-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring.go
29 lines (24 loc) · 939 Bytes
/
string.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package lexy
// stringCodec is the Codec for strings.
//
// A string is encoded as its bytes.
// Get will fully consume its argument buffer, and will never fail.
//
// The order of strings, and this encoding, may be surprising.
// A string in Go is essentially an immutable []byte without text semantics.
// For an encoded UTF-8 string, the order is the same as the lexicographical order of the Unicode code points.
// However, even this is not intuitive. For example, 'Z' < 'a'.
// Collation is locale-dependent. Any ordering could be incorrect in another locale.
type stringCodec struct{}
func (stringCodec) Append(buf []byte, value string) []byte {
return append(buf, value...)
}
func (stringCodec) Put(buf []byte, value string) []byte {
return copyAll(buf, []byte(value))
}
func (stringCodec) Get(buf []byte) (string, []byte) {
return string(buf), buf[len(buf):]
}
func (stringCodec) RequiresTerminator() bool {
return true
}