Debian Codegraph @

bytes/case.go

raw symbols SCIP
1 package bytesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/bytes`/
2
3 import (
4 "github.com/gofiber/utils/v2/internal/caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/"
5 )
6
7 // swarMinLen is the smallest input length worth routing through the
8 // word-at-a-time (SWAR) helpers; shorter inputs are cheaper byte-by-byte.
9 const swarMinLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/bytes`/swarMinLen. = caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/.WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/WordLen.
10
11 // ToLower converts an ASCII byte slice to lower-case without modifying the input.
12 func ToLowerscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/bytes`/ToLower().(b []byte) []byte {
13 n := len(b)
14 if n < swarMinLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/bytes`/swarMinLen. {
15 table := caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/.ToLowerTablescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/ToLowerTable.
16 for i := 0; i < n; i++ {
17 c := b[i]
18 low := table[c]
19 if low != c {
20 dst := make([]byte, n)
21 copy(dst, b[:i])
22 dst[i] = low
23 for i++; i < n; i++ {
24 dst[i] = table[b[i]]
25 }
26 return dst
27 }
28 }
29 return b
30 }
31
32 i := caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/.FirstUpperIndexscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/FirstUpperIndex().(b)
33 if i < 0 {
34 return b
35 }
36
37 dst := make([]byte, n)
38 // Copy the unchanged prefix up to the word containing the first
39 // uppercase byte, then convert the rest word-at-a-time.
40 from := i &^ (caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/.WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/WordLen. - 1)
41 copy(dst, b[:from])
42 caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/.ToLowerCopyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/ToLowerCopy().(dst, b, from)
43 return dst
44 }
45
46 // ToUpper converts an ASCII byte slice to upper-case without modifying the input.
47 func ToUpperscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/bytes`/ToUpper().(b []byte) []byte {
48 n := len(b)
49 if n < swarMinLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/bytes`/swarMinLen. {
50 table := caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/.ToUpperTablescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/ToUpperTable.
51 for i := 0; i < n; i++ {
52 c := b[i]
53 up := table[c]
54 if up != c {
55 dst := make([]byte, n)
56 copy(dst, b[:i])
57 dst[i] = up
58 for i++; i < n; i++ {
59 dst[i] = table[b[i]]
60 }
61 return dst
62 }
63 }
64 return b
65 }
66
67 i := caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/.FirstLowerIndexscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/FirstLowerIndex().(b)
68 if i < 0 {
69 return b
70 }
71
72 dst := make([]byte, n)
73 from := i &^ (caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/.WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/WordLen. - 1)
74 copy(dst, b[:from])
75 caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/.ToUpperCopyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/ToUpperCopy().(dst, b, from)
76 return dst
77 }
78
79 // UnsafeToLower converts an ASCII byte slice to lower-case in-place.
80 // The passed slice content is modified and the same slice is returned.
81 func UnsafeToLowerscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/bytes`/UnsafeToLower().(b []byte) []byte {
82 if len(b) < swarMinLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/bytes`/swarMinLen. {
83 table := caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/.ToLowerTablescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/ToLowerTable.
84 for i := range b {
85 b[i] = table[b[i]]
86 }
87 return b
88 }
89 caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/.ToLowerInPlacescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/ToLowerInPlace().(b)
90 return b
91 }
92
93 // UnsafeToUpper converts an ASCII byte slice to upper-case in-place.
94 // The passed slice content is modified and the same slice is returned.
95 func UnsafeToUpperscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/bytes`/UnsafeToUpper().(b []byte) []byte {
96 if len(b) < swarMinLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/bytes`/swarMinLen. {
97 table := caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/.ToUpperTablescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/ToUpperTable.
98 for i := range b {
99 b[i] = table[b[i]]
100 }
101 return b
102 }
103 caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/.ToUpperInPlacescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/ToUpperInPlace().(b)
104 return b
105 }