File tree 1 file changed +38
-21
lines changed 1 file changed +38
-21
lines changed Original file line number Diff line number Diff line change @@ -75,36 +75,53 @@ function perf_parse_json(strng::AbstractString)
75
75
if strng[pos] != ' "'
76
76
error (" AbstractString starting with quotation expected at position $pos " )
77
77
else
78
- pos = pos + 1
78
+ pos += 1
79
79
end
80
- str = " "
80
+ str = IOBuffer ()
81
81
while pos <= len
82
82
nc = strng[pos]
83
83
if nc == ' "'
84
+ pos += 1
85
+ return String (take! (str))
86
+ elseif nc == ' \\ '
84
87
pos = pos + 1
85
- return string (str)
86
- elseif nc == ' \\ '
87
- if pos+ 1 > len
88
- error_pos (" End of file reached right after escape character" )
89
- end
90
- pos = pos + 1
88
+ pos > len && break # goto error handling
91
89
anc = strng[pos]
92
- if anc == ' "' || anc == ' \\ ' || anc == ' /'
93
- str = string (str, strng[pos])
94
- pos = pos + 1
95
- elseif anc == ' b' || anc == ' f' || anc == ' n' || anc == ' r' || anc == ' t'
96
- str = string (str, ' \\ ' , string[pos])
97
- pos = pos + 1
90
+ if anc == ' "'
91
+ write (str, " \" " )
92
+ pos += 1
93
+ elseif anc == ' \\ '
94
+ write (str, " \\ " )
95
+ pos += 1
96
+ elseif anc == ' /'
97
+ write (str, " /" )
98
+ pos += 1
99
+ elseif anc == ' b'
100
+ write (str, " \b " )
101
+ pos += 1
102
+ elseif anc == ' f'
103
+ write (str, " \f " )
104
+ pos += 1
105
+ elseif anc == ' n'
106
+ write (str, " \n " )
107
+ pos += 1
108
+ elseif anc == ' r'
109
+ write (str, " \r " )
110
+ pos += 1
111
+ elseif anc == ' t'
112
+ write (str, " \t " )
113
+ pos += 1
98
114
elseif anc == ' u'
99
- if pos+ 4 > len
100
- error_pos (" End of file reached in escaped unicode character" )
101
- end
102
- str = string (str, strng[pos- 1 : pos+ 4 ])
115
+ pos + 4 > len && break # goto error handling
116
+ write (str, Char (parse (Int, strng[pos: pos+ 4 ], base= 16 )))
103
117
pos = pos + 5
118
+ else # should rarely happen
119
+ write (str, anc)
120
+ pos = pos + 1
104
121
end
105
- else # should never happen
106
- str = string (str,strng[pos] )
107
- pos = pos + 1
122
+ else # common case
123
+ write (str, nc )
124
+ pos = nextind (strng, pos)
108
125
end
109
126
end
110
127
error (" End of file while expecting end of string" )
You can’t perform that action at this time.
0 commit comments