()
| 25 | ) |
| 26 | |
| 27 | func (i item) String() string { |
| 28 | switch i.typ { |
| 29 | case itemString: |
| 30 | return i.val |
| 31 | case itemSingleEscape: |
| 32 | escapes := map[string]string{ |
| 33 | "b": "\b", |
| 34 | "f": "\f", |
| 35 | "n": "\n", |
| 36 | "r": "\r", |
| 37 | "t": "\t", |
| 38 | "v": "\v", |
| 39 | } |
| 40 | |
| 41 | if out, exists := escapes[i.val]; exists { |
| 42 | return out |
| 43 | } |
| 44 | return i.val |
| 45 | case itemHexEscape, itemUnicodeEscape, itemCodepointEscape: |
| 46 | num, err := strconv.ParseInt(i.val, 16, 0) |
| 47 | if err != nil { |
| 48 | return i.val |
| 49 | } |
| 50 | return string(rune(num)) |
| 51 | case itemOctalEscape: |
| 52 | num, err := strconv.ParseInt(i.val, 8, 0) |
| 53 | if err != nil { |
| 54 | return i.val |
| 55 | } |
| 56 | return string(rune(num)) |
| 57 | default: |
| 58 | return i.val |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | // a stringLexer maintains the state needed to lex a string |
| 63 | type stringLexer struct { |
no outgoing calls
no test coverage detected