// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package tag contains functionality handling tags and related data.
package tag // import "golang.org/x/text/internal/tag" import // An Index converts tags to a compact numeric value. // // All elements are of size 4. Tags may be up to 4 bytes long. Excess bytes can // be used to store additional information about the tag. type Index string // Elem returns the element data at the given index. func ( Index) ( int) string { return string([*4 : *4+4]) } // Index reports the index of the given key or -1 if it could not be found. // Only the first len(key) bytes from the start of the 4-byte entries will be // considered for the search and the first match in Index will be returned. func ( Index) ( []byte) int { := len() // search the index of the first entry with an equal or higher value than // key in s. := sort.Search(len()/4, func( int) bool { return cmp([*4:*4+], ) != -1 }) := * 4 if cmp([:+len()], ) != 0 { return -1 } return } // Next finds the next occurrence of key after index x, which must have been // obtained from a call to Index using the same key. It returns x+1 or -1. func ( Index) ( []byte, int) int { if ++; *4 < len() && cmp([*4:*4+len()], ) == 0 { return } return -1 } // cmp returns an integer comparing a and b lexicographically. func cmp( Index, []byte) int { := len() if len() < { = len() } for , := range [:] { switch { case [] > : return 1 case [] < : return -1 } } switch { case len() < len(): return -1 case len() > len(): return 1 } return 0 } // Compare returns an integer comparing a and b lexicographically. func ( string, []byte) int { return cmp(Index(), ) } // FixCase reformats b to the same pattern of cases as form. // If returns false if string b is malformed. func ( string, []byte) bool { if len() != len() { return false } for , := range { if [] <= 'Z' { if >= 'a' { -= 'z' - 'Z' } if < 'A' || 'Z' < { return false } } else { if <= 'Z' { += 'z' - 'Z' } if < 'a' || 'z' < { return false } } [] = } return true }