Debian Codegraph @

pkg/internal/third_party/go-json-experiment/json/fold.go

raw symbols SCIP
1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package jsonscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/
6
7 import (
8 "unicodescip-go gomod github.com/golang/go/src go1.21 unicode/"
9 "unicode/utf8scip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/"
10 )
11
12 // foldName returns a folded string such that foldName(x) == foldName(y)
13 // is similar to strings.EqualFold(x, y), but ignores underscore and dashes.
14 // This allows foldName to match common naming conventions.
15 func foldNamescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/foldName().(in []byte) []byte {
16 // This is inlinable to take advantage of "function outlining".
17 // See https://blog.filippo.io/efficient-go-apis-with-the-inliner/
18 var arr [32]byte // large enough for most JSON names
19 return appendFoldedNamescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/appendFoldedName().(arr[:0], in)
20 }
21 func appendFoldedNamescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/appendFoldedName().(out, in []byte) []byte {
22 for i := 0; i < len(in); {
23 // Handle single-byte ASCII.
24 if c := in[i]; c < utf8scip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/.RuneSelfscip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/RuneSelf. {
25 if c != '_' && c != '-' {
26 if 'a' <= c && c <= 'z' {
27 c -= 'a' - 'A'
28 }
29 out = append(out, c)
30 }
31 i++
32 continue
33 }
34 // Handle multi-byte Unicode.
35 r, n := utf8scip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/.DecodeRunescip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/DecodeRune().(in[i:])
36 out = utf8scip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/.AppendRunescip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/AppendRune().(out, foldRunescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/foldRune().(r))
37 i += n
38 }
39 return out
40 }
41
42 // foldRune is a variation on unicode.SimpleFold that returns the same rune
43 // for all runes in the same fold set.
44 //
45 // Invariant:
46 //
47 // foldRune(x) == foldRune(y) ⇔ strings.EqualFold(string(x), string(y))
48 func foldRunescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/foldRune().(r rune) rune {
49 for {
50 r2 := unicodescip-go gomod github.com/golang/go/src go1.21 unicode/.SimpleFoldscip-go gomod github.com/golang/go/src go1.21 unicode/SimpleFold().(r)
51 if r2 <= r {
52 return r2 // smallest character in the fold set
53 }
54 r = r2
55 }
56 }