summaryrefslogtreecommitdiff
path: root/src/mongo/gotools/common/json/single_quoted.go
blob: ca465ee04f23cdf6e3567b324c04e556fab6d2b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package json

// Transition functions for recognizing single-quoted strings.
// Adapted from encoding/json/scanner.go.

// stateInSingleQuotedString is the state after reading `'`.
func stateInSingleQuotedString(s *scanner, c int) int {
	if c == '\'' {
		s.step = stateEndValue
		return scanContinue
	}
	if c == '\\' {
		s.step = stateInSingleQuotedStringEsc
		return scanContinue
	}
	if c < 0x20 {
		return s.error(c, "in string literal")
	}
	return scanContinue
}

// stateInSingleQuotedStringEsc is the state after reading `'\` during a quoted string.
func stateInSingleQuotedStringEsc(s *scanner, c int) int {
	switch c {
	case 'b', 'f', 'n', 'r', 't', '\\', '/', '\'':
		s.step = stateInSingleQuotedString
		return scanContinue
	}
	if c == 'u' {
		s.step = stateInSingleQuotedStringEscU
		return scanContinue
	}
	return s.error(c, "in string escape code")
}

// stateInSingleQuotedStringEscU is the state after reading `'\u` during a quoted string.
func stateInSingleQuotedStringEscU(s *scanner, c int) int {
	if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' {
		s.step = stateInSingleQuotedStringEscU1
		return scanContinue
	}
	// numbers
	return s.error(c, "in \\u hexadecimal character escape")
}

// stateInSingleQuotedStringEscU1 is the state after reading `'\u1` during a quoted string.
func stateInSingleQuotedStringEscU1(s *scanner, c int) int {
	if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' {
		s.step = stateInSingleQuotedStringEscU12
		return scanContinue
	}
	// numbers
	return s.error(c, "in \\u hexadecimal character escape")
}

// stateInSingleQuotedStringEscU12 is the state after reading `'\u12` during a quoted string.
func stateInSingleQuotedStringEscU12(s *scanner, c int) int {
	if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' {
		s.step = stateInSingleQuotedStringEscU123
		return scanContinue
	}
	// numbers
	return s.error(c, "in \\u hexadecimal character escape")
}

// stateInSingleQuotedStringEscU123 is the state after reading `'\u123` during a quoted string.
func stateInSingleQuotedStringEscU123(s *scanner, c int) int {
	if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' {
		s.step = stateInSingleQuotedString
		return scanContinue
	}
	// numbers
	return s.error(c, "in \\u hexadecimal character escape")
}