IdentityMaybeQuoteStrict Quote an identity if need be (has illegal characters or spaces) First character MUST be alpha (not numeric or any other character)
(buf *bytes.Buffer, quote byte, ident string)
| 88 | // IdentityMaybeQuoteStrict Quote an identity if need be (has illegal characters or spaces) |
| 89 | // First character MUST be alpha (not numeric or any other character) |
| 90 | func IdentityMaybeQuoteStrictBuf(buf *bytes.Buffer, quote byte, ident string) { |
| 91 | |
| 92 | if len(ident) == 0 { |
| 93 | return |
| 94 | } |
| 95 | needsQuote := false |
| 96 | quoter := rune(quote) |
| 97 | |
| 98 | firstRune, _ := utf8.DecodeRuneInString(ident) |
| 99 | lastRune, _ := utf8.DecodeLastRuneInString(ident) |
| 100 | |
| 101 | if quoter == firstRune && quoter == lastRune { |
| 102 | // Already escaped?? |
| 103 | io.WriteString(buf, ident) |
| 104 | return |
| 105 | } |
| 106 | if firstRune == '@' || (firstRune == '[' && lastRune == ']') { |
| 107 | needsQuote = false |
| 108 | } else if !unicode.IsLetter(firstRune) { |
| 109 | needsQuote = true |
| 110 | } else { |
| 111 | for _, r := range ident { |
| 112 | if !lex.IsIdentifierRune(r) { |
| 113 | needsQuote = true |
| 114 | break |
| 115 | } else if r == quoter { |
| 116 | needsQuote = true |
| 117 | break |
| 118 | } else if r == '.' { |
| 119 | needsQuote = true |
| 120 | break |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | if needsQuote { |
| 126 | buf.WriteByte(quote) |
| 127 | escapeQuote(buf, quoter, ident) |
| 128 | if quote == '[' { |
| 129 | buf.WriteByte(']') |
| 130 | } else { |
| 131 | buf.WriteByte(quote) |
| 132 | } |
| 133 | } else { |
| 134 | io.WriteString(buf, ident) |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | // IdentityMaybeQuoteStrict Quote an identity if need be (has illegal characters or spaces) |
| 139 | // First character MUST be alpha (not numeric or any other character) |
no test coverage detected