readQuotedIdentifier reads something like "MyColumn" with support for Unicode quotes
()
| 864 | |
| 865 | // readQuotedIdentifier reads something like "MyColumn" with support for Unicode quotes |
| 866 | func (t *Tokenizer) readQuotedIdentifier() (models.Token, error) { |
| 867 | // Get and normalize opening quote |
| 868 | r, size := utf8.DecodeRune(t.input[t.pos.Index:]) |
| 869 | quote := normalizeQuote(r) |
| 870 | startPos := t.pos.Clone() |
| 871 | |
| 872 | // Skip opening quote |
| 873 | t.pos.AdvanceRune(r, size) |
| 874 | |
| 875 | var buf bytes.Buffer |
| 876 | for t.pos.Index < len(t.input) { |
| 877 | r, size := utf8.DecodeRune(t.input[t.pos.Index:]) |
| 878 | r = normalizeQuote(r) |
| 879 | |
| 880 | if r == quote { |
| 881 | // Check for escaped quote |
| 882 | if t.pos.Index+size < len(t.input) { |
| 883 | nextR, nextSize := utf8.DecodeRune(t.input[t.pos.Index+size:]) |
| 884 | nextR = normalizeQuote(nextR) |
| 885 | if nextR == quote { |
| 886 | // Include one quote and skip the other |
| 887 | buf.WriteRune(r) |
| 888 | t.pos.Index += size + nextSize |
| 889 | t.pos.Column += 2 |
| 890 | continue |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | // End of quoted identifier |
| 895 | t.pos.Index += size |
| 896 | t.pos.Column++ |
| 897 | |
| 898 | word := &models.Word{ |
| 899 | Value: buf.String(), |
| 900 | QuoteStyle: quote, |
| 901 | } |
| 902 | |
| 903 | // Double-quoted strings are identifiers in SQL |
| 904 | return models.Token{ |
| 905 | Type: models.TokenTypeDoubleQuotedString, |
| 906 | Word: word, |
| 907 | Value: buf.String(), |
| 908 | Quote: quote, |
| 909 | }, nil |
| 910 | } |
| 911 | |
| 912 | if r == '\n' { |
| 913 | return models.Token{}, errors.UnterminatedStringError( |
| 914 | models.Location{Line: startPos.Line, Column: startPos.Column}, |
| 915 | string(t.input), |
| 916 | ) |
| 917 | } |
| 918 | |
| 919 | // Handle regular characters |
| 920 | buf.WriteRune(r) |
| 921 | t.pos.Index += size |
| 922 | t.pos.Column++ |
| 923 | } |
no test coverage detected