IsBareIdentifier returns true if the input string is a permissible bare SQL identifier.
(s string)
| 71 | // IsBareIdentifier returns true if the input string is a permissible bare SQL |
| 72 | // identifier. |
| 73 | func 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. |
| 97 | func IsIdentStart(ch int) bool { |
no test coverage detected
searching dependent graphs…