MCPcopy Index your code
hub / github.com/tidwall/gjson / Less

Method Less

gjson.go:2317–2334  ·  view source on GitHub ↗

Less return true if a token is less than another token. The caseSensitive parameter is used when the tokens are Strings. The order when comparing two different type is: Null < False < Number < String < True < JSON

(token Result, caseSensitive bool)

Source from the content-addressed store, hash-verified

2315//
2316// Null < False < Number < String < True < JSON
2317func (t Result) Less(token Result, caseSensitive bool) bool {
2318 if t.Type < token.Type {
2319 return true
2320 }
2321 if t.Type > token.Type {
2322 return false
2323 }
2324 if t.Type == String {
2325 if caseSensitive {
2326 return t.Str < token.Str
2327 }
2328 return stringLessInsensitive(t.Str, token.Str)
2329 }
2330 if t.Type == Number {
2331 return t.Num < token.Num
2332 }
2333 return t.Raw < token.Raw
2334}
2335
2336func stringLessInsensitive(a, b string) bool {
2337 for i := 0; i < len(a) && i < len(b); i++ {

Callers 1

TestLessFunction · 0.80

Calls 1

stringLessInsensitiveFunction · 0.85

Tested by 1

TestLessFunction · 0.64