MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / IsBareIdentifier

Function IsBareIdentifier

pkg/sql/lexbase/predicates.go:73–94  ·  view source on GitHub ↗

IsBareIdentifier returns true if the input string is a permissible bare SQL identifier.

(s string)

Source from the content-addressed store, hash-verified

71// IsBareIdentifier returns true if the input string is a permissible bare SQL
72// identifier.
73func IsBareIdentifier(s string) bool {
74 if len(s) == 0 || !IsIdentStart(int(s[0])) || (s[0] >= 'A' && s[0] <= 'Z') {
75 return false
76 }
77 // Keep track of whether the input string is all ASCII. If it is, we don't
78 // have to bother running the full Normalize() function at the end, which is
79 // quite expensive.
80 isASCII := s[0] < utf8.RuneSelf
81 for i := 1; i < len(s); i++ {
82 if !IsIdentMiddle(int(s[i])) {
83 return false
84 }
85 if s[i] >= 'A' && s[i] <= 'Z' {
86 // Non-lowercase identifiers aren't permissible.
87 return false
88 }
89 if s[i] >= utf8.RuneSelf {
90 isASCII = false
91 }
92 }
93 return isASCII || NormalizeName(s) == s
94}
95
96// IsIdentStart returns true if the character is valid at the start of an identifier.
97func IsIdentStart(ch int) bool {

Callers 2

EncodeRestrictedSQLIdentFunction · 0.85

Calls 3

IsIdentStartFunction · 0.85
IsIdentMiddleFunction · 0.85
NormalizeNameFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…