parseEscape parses a backslash escape.
()
| 22 | |
| 23 | // parseEscape parses a backslash escape. |
| 24 | func (p *parser) parseEscape() (result string, err error) { |
| 25 | if len(p.s) < p.i+2 || p.s[p.i] != '\\' { |
| 26 | return "", errors.New("invalid escape sequence") |
| 27 | } |
| 28 | |
| 29 | start := p.i + 1 |
| 30 | c := p.s[start] |
| 31 | switch { |
| 32 | case c == '\r' || c == '\n' || c == '\f': |
| 33 | return "", errors.New("escaped line ending outside string") |
| 34 | case hexDigit(c): |
| 35 | // unicode escape (hex) |
| 36 | var i int |
| 37 | for i = start; i < start+6 && i < len(p.s) && hexDigit(p.s[i]); i++ { |
| 38 | // empty |
| 39 | } |
| 40 | v, _ := strconv.ParseUint(p.s[start:i], 16, 64) |
| 41 | if len(p.s) > i { |
| 42 | switch p.s[i] { |
| 43 | case '\r': |
| 44 | i++ |
| 45 | if len(p.s) > i && p.s[i] == '\n' { |
| 46 | i++ |
| 47 | } |
| 48 | case ' ', '\t', '\n', '\f': |
| 49 | i++ |
| 50 | } |
| 51 | } |
| 52 | p.i = i |
| 53 | return string(rune(v)), nil |
| 54 | } |
| 55 | |
| 56 | // Return the literal character after the backslash. |
| 57 | result = p.s[start : start+1] |
| 58 | p.i += 2 |
| 59 | return result, nil |
| 60 | } |
| 61 | |
| 62 | // toLowerASCII returns s with all ASCII capital letters lowercased. |
| 63 | func toLowerASCII(s string) string { |
no test coverage detected