@@ -61,119 +61,7 @@ export class EjsonDecoder extends JsonDecoder {
6161 }
6262 }
6363
64- public skipWhitespace ( ) : void {
65- const reader = this . reader ;
66- const uint8 = reader . uint8 ;
67- let x = reader . x ;
68- let char : number = 0 ;
69- while ( true ) {
70- char = uint8 [ x ] ;
71- switch ( char ) {
72- case 32 /* <space> */ :
73- case 9 /* <tab> */ :
74- case 10 /* <line feed> */ :
75- case 13 /* <carriage return> */ :
76- x ++ ;
77- continue ;
78- default :
79- reader . x = x ;
80- return ;
81- }
82- }
83- }
84-
85- public readNull ( ) : null {
86- if ( this . reader . u32 ( ) !== 0x6e756c6c /* null */ ) throw new Error ( 'Invalid JSON' ) ;
87- return null ;
88- }
89-
90- public readTrue ( ) : true {
91- if ( this . reader . u32 ( ) !== 0x74727565 /* true */ ) throw new Error ( 'Invalid JSON' ) ;
92- return true ;
93- }
94-
95- public readFalse ( ) : false {
96- const reader = this . reader ;
97- if ( reader . u8 ( ) !== 0x66 /* f */ || reader . u32 ( ) !== 0x616c7365 /* alse */ ) throw new Error ( 'Invalid JSON' ) ;
98- return false ;
99- }
100-
101- public readNum ( ) : number {
102- const reader = this . reader ;
103- const uint8 = reader . uint8 ;
104- let x = reader . x ;
105- let c = uint8 [ x ++ ] ;
106- const c1 = c ;
107- c = uint8 [ x ++ ] ;
108- if ( ! c || ( ( c < 45 || c > 57 ) && c !== 43 && c !== 69 && c !== 101 ) ) {
109- reader . x = x - 1 ;
110- const num = + String . fromCharCode ( c1 ) ;
111- if ( num !== num ) throw new Error ( 'Invalid JSON' ) ;
112- return num ;
113- }
114- const c2 = c ;
115- c = uint8 [ x ++ ] ;
116- if ( ! c || ( ( c < 45 || c > 57 ) && c !== 43 && c !== 69 && c !== 101 ) ) {
117- reader . x = x - 1 ;
118- const num = + String . fromCharCode ( c1 , c2 ) ;
119- if ( num !== num ) throw new Error ( 'Invalid JSON' ) ;
120- return num ;
121- }
122- // Continue reading for longer numbers (simplified from JsonDecoder)
123- const points : number [ ] = [ c1 , c2 ] ;
124- while ( c && ( ( c >= 45 && c <= 57 ) || c === 43 || c === 69 || c === 101 ) ) {
125- points . push ( c ) ;
126- c = uint8 [ x ++ ] ;
127- }
128- reader . x = x - 1 ;
129- const num = + String . fromCharCode . apply ( String , points ) ;
130- if ( num !== num ) throw new Error ( 'Invalid JSON' ) ;
131- return num ;
132- }
13364
134- public readStr ( ) : string {
135- const reader = this . reader ;
136- const uint8 = reader . uint8 ;
137- const char = uint8 [ reader . x ++ ] ;
138- if ( char !== 0x22 ) throw new Error ( 'Invalid JSON' ) ;
139- const x0 = reader . x ;
140- let x1 = x0 ;
141-
142- // Find ending quote (simplified version)
143- while ( x1 < uint8 . length ) {
144- const c = uint8 [ x1 ] ;
145- if ( c === 0x22 /* " */ && uint8 [ x1 - 1 ] !== 0x5c /* \ */ ) {
146- break ;
147- }
148- x1 ++ ;
149- }
150-
151- if ( x1 >= uint8 . length ) throw new Error ( 'Invalid JSON' ) ;
152-
153- // Decode UTF-8 string
154- let str = '' ;
155- for ( let i = x0 ; i < x1 ; i ++ ) {
156- str += String . fromCharCode ( uint8 [ i ] ) ;
157- }
158-
159- // Handle escaped characters (simplified)
160- str = str . replace ( / \\ ( b | f | n | r | t | " | \/ | \\ ) / g, ( match , char ) => {
161- switch ( char ) {
162- case 'b' : return '\b' ;
163- case 'f' : return '\f' ;
164- case 'n' : return '\n' ;
165- case 'r' : return '\r' ;
166- case 't' : return '\t' ;
167- case '"' : return '"' ;
168- case '/' : return '/' ;
169- case '\\' : return '\\' ;
170- default : return match ;
171- }
172- } ) ;
173-
174- reader . x = x1 + 1 ;
175- return str ;
176- }
17765
17866 public readArr ( ) : unknown [ ] {
17967 const reader = this . reader ;
0 commit comments