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