Home Download Docs Code Community
     1	/*
     2	Copyright 2011 The Perkeep Authors
     3	
     4	Licensed under the Apache License, Version 2.0 (the "License");
     5	you may not use this file except in compliance with the License.
     6	You may obtain a copy of the License at
     7	
     8	     http://www.apache.org/licenses/LICENSE-2.0
     9	
    10	Unless required by applicable law or agreed to in writing, software
    11	distributed under the License is distributed on an "AS IS" BASIS,
    12	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13	See the License for the specific language governing permissions and
    14	limitations under the License.
    15	*/
    16	
    17	package index
    18	
    19	import (
    20		"fmt"
    21		"strings"
    22	)
    23	
    24	func unreverseTimeString(s string) string {
    25		if !strings.HasPrefix(s, "rt") {
    26			panic(fmt.Sprintf("can't unreverse time string: %q", s))
    27		}
    28		b := make([]byte, 0, len(s)-2)
    29		b = appendReverseString(b, s[2:])
    30		return string(b)
    31	}
    32	
    33	func reverseTimeString(s string) string {
    34		b := make([]byte, 0, len(s)+2)
    35		b = append(b, 'r')
    36		b = append(b, 't')
    37		b = appendReverseString(b, s)
    38		return string(b)
    39	}
    40	
    41	func appendReverseString(b []byte, s string) []byte {
    42		for i := 0; i < len(s); i++ {
    43			c := s[i]
    44			if c >= '0' && c <= '9' {
    45				b = append(b, '0'+('9'-c))
    46			} else {
    47				b = append(b, c)
    48			}
    49		}
    50		return b
    51	}
Website layout inspired by memcached.
Content by the authors.