yajl-ruby 0.7.4 → 0.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of yajl-ruby might be problematic. Click here for more details.

data/ext/yajl_lex.c CHANGED
@@ -1,22 +1,22 @@
1
1
  /*
2
- * Copyright 2007-2009, Lloyd Hilaiel.
3
- *
2
+ * Copyright 2010, Lloyd Hilaiel.
3
+ *
4
4
  * Redistribution and use in source and binary forms, with or without
5
5
  * modification, are permitted provided that the following conditions are
6
6
  * met:
7
- *
7
+ *
8
8
  * 1. Redistributions of source code must retain the above copyright
9
9
  * notice, this list of conditions and the following disclaimer.
10
- *
10
+ *
11
11
  * 2. Redistributions in binary form must reproduce the above copyright
12
12
  * notice, this list of conditions and the following disclaimer in
13
13
  * the documentation and/or other materials provided with the
14
14
  * distribution.
15
- *
15
+ *
16
16
  * 3. Neither the name of Lloyd Hilaiel nor the names of its
17
17
  * contributors may be used to endorse or promote products derived
18
18
  * from this software without specific prior written permission.
19
- *
19
+ *
20
20
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21
21
  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
22
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -28,7 +28,7 @@
28
28
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29
29
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
30
  * POSSIBILITY OF SUCH DAMAGE.
31
- */
31
+ */
32
32
 
33
33
  #include "yajl_lex.h"
34
34
  #include "yajl_buf.h"
@@ -40,7 +40,7 @@
40
40
 
41
41
  #ifdef YAJL_LEXER_DEBUG
42
42
  static const char *
43
- tokToStr(yajl_tok tok)
43
+ tokToStr(yajl_tok tok)
44
44
  {
45
45
  switch (tok) {
46
46
  case yajl_tok_bool: return "bool";
@@ -69,13 +69,13 @@ tokToStr(yajl_tok tok)
69
69
  * the network or disk). This makes the lexer more complex. The
70
70
  * responsibility of the lexer is to handle transparently the case where
71
71
  * a chunk boundary falls in the middle of a token. This is
72
- * accomplished is via a buffer and a character reading abstraction.
72
+ * accomplished is via a buffer and a character reading abstraction.
73
73
  *
74
74
  * Overview of implementation
75
75
  *
76
76
  * When we lex to end of input string before end of token is hit, we
77
77
  * copy all of the input text composing the token into our lexBuf.
78
- *
78
+ *
79
79
  * Every time we read a character, we do so through the readChar function.
80
80
  * readChar's responsibility is to handle pulling all chars from the buffer
81
81
  * before pulling chars from input text
@@ -90,7 +90,7 @@ struct yajl_lexer_t {
90
90
  yajl_lex_error error;
91
91
 
92
92
  /* a input buffer to handle the case where a token is spread over
93
- * multiple chunks */
93
+ * multiple chunks */
94
94
  yajl_buf buf;
95
95
 
96
96
  /* in the case where we have data in the lexBuf, bufOff holds
@@ -180,24 +180,24 @@ static const char charLookupTable[256] =
180
180
  /*78*/ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
181
181
 
182
182
  /* include these so we don't have to always check the range of the char */
183
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
184
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
185
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
186
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
187
-
188
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
189
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
190
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
191
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
192
-
193
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
194
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
195
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
196
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
197
-
198
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
199
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
200
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
183
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
184
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
185
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
186
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
187
+
188
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
189
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
190
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
191
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
192
+
193
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
194
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
195
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
196
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
197
+
198
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
199
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
200
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
201
201
  0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
202
202
  };
203
203
 
@@ -209,7 +209,7 @@ static const char charLookupTable[256] =
209
209
  * yajl_tok_eof - if end of input was hit before validation could
210
210
  * complete
211
211
  * yajl_tok_error - if invalid utf8 was encountered
212
- *
212
+ *
213
213
  * NOTE: on error the offset will point to the first char of the
214
214
  * invalid utf8 */
215
215
  #define UTF8_CHECK_EOF if (*offset >= jsonTextLen) { return yajl_tok_eof; }
@@ -223,7 +223,7 @@ yajl_lex_utf8_char(yajl_lexer lexer, const unsigned char * jsonText,
223
223
  /* single byte */
224
224
  return yajl_tok_string;
225
225
  } else if ((curChar >> 5) == 0x6) {
226
- /* two byte */
226
+ /* two byte */
227
227
  UTF8_CHECK_EOF;
228
228
  curChar = readChar(lexer, jsonText, offset);
229
229
  if ((curChar >> 6) == 0x2) return yajl_tok_string;
@@ -249,7 +249,7 @@ yajl_lex_utf8_char(yajl_lexer lexer, const unsigned char * jsonText,
249
249
  if ((curChar >> 6) == 0x2) return yajl_tok_string;
250
250
  }
251
251
  }
252
- }
252
+ }
253
253
 
254
254
  return yajl_tok_error;
255
255
  }
@@ -300,8 +300,8 @@ yajl_lex_string(yajl_lexer lexer, const unsigned char * jsonText,
300
300
  unsigned int i = 0;
301
301
 
302
302
  for (i=0;i<4;i++) {
303
- STR_CHECK_EOF;
304
- curChar = readChar(lexer, jsonText, offset);
303
+ STR_CHECK_EOF;
304
+ curChar = readChar(lexer, jsonText, offset);
305
305
  if (!(charLookupTable[curChar] & VHC)) {
306
306
  /* back up to offending char */
307
307
  unreadChar(lexer, offset);
@@ -313,8 +313,8 @@ yajl_lex_string(yajl_lexer lexer, const unsigned char * jsonText,
313
313
  /* back up to offending char */
314
314
  unreadChar(lexer, offset);
315
315
  lexer->error = yajl_lex_string_invalid_escaped_char;
316
- goto finish_string_lex;
317
- }
316
+ goto finish_string_lex;
317
+ }
318
318
  }
319
319
  /* when not validating UTF8 it's a simple table lookup to determine
320
320
  * if the present character is invalid */
@@ -322,29 +322,29 @@ yajl_lex_string(yajl_lexer lexer, const unsigned char * jsonText,
322
322
  /* back up to offending char */
323
323
  unreadChar(lexer, offset);
324
324
  lexer->error = yajl_lex_string_invalid_json_char;
325
- goto finish_string_lex;
325
+ goto finish_string_lex;
326
326
  }
327
327
  /* when in validate UTF8 mode we need to do some extra work */
328
328
  else if (lexer->validateUTF8) {
329
329
  yajl_tok t = yajl_lex_utf8_char(lexer, jsonText, jsonTextLen,
330
330
  offset, curChar);
331
-
331
+
332
332
  if (t == yajl_tok_eof) {
333
333
  tok = yajl_tok_eof;
334
334
  goto finish_string_lex;
335
335
  } else if (t == yajl_tok_error) {
336
336
  lexer->error = yajl_lex_string_invalid_utf8;
337
337
  goto finish_string_lex;
338
- }
338
+ }
339
339
  }
340
- /* accept it, and move on */
340
+ /* accept it, and move on */
341
341
  }
342
342
  finish_string_lex:
343
343
  /* tell our buddy, the parser, wether he needs to process this string
344
344
  * again */
345
345
  if (hasEscapes && tok == yajl_tok_string) {
346
346
  tok = yajl_tok_string_with_escapes;
347
- }
347
+ }
348
348
 
349
349
  return tok;
350
350
  }
@@ -363,23 +363,23 @@ yajl_lex_number(yajl_lexer lexer, const unsigned char * jsonText,
363
363
 
364
364
  yajl_tok tok = yajl_tok_integer;
365
365
 
366
- RETURN_IF_EOF;
366
+ RETURN_IF_EOF;
367
367
  c = readChar(lexer, jsonText, offset);
368
368
 
369
369
  /* optional leading minus */
370
370
  if (c == '-') {
371
- RETURN_IF_EOF;
372
- c = readChar(lexer, jsonText, offset);
371
+ RETURN_IF_EOF;
372
+ c = readChar(lexer, jsonText, offset);
373
373
  }
374
374
 
375
375
  /* a single zero, or a series of integers */
376
376
  if (c == '0') {
377
- RETURN_IF_EOF;
378
- c = readChar(lexer, jsonText, offset);
377
+ RETURN_IF_EOF;
378
+ c = readChar(lexer, jsonText, offset);
379
379
  } else if (c >= '1' && c <= '9') {
380
380
  do {
381
- RETURN_IF_EOF;
382
- c = readChar(lexer, jsonText, offset);
381
+ RETURN_IF_EOF;
382
+ c = readChar(lexer, jsonText, offset);
383
383
  } while (c >= '0' && c <= '9');
384
384
  } else {
385
385
  unreadChar(lexer, offset);
@@ -390,15 +390,15 @@ yajl_lex_number(yajl_lexer lexer, const unsigned char * jsonText,
390
390
  /* optional fraction (indicates this is floating point) */
391
391
  if (c == '.') {
392
392
  int numRd = 0;
393
-
393
+
394
394
  RETURN_IF_EOF;
395
- c = readChar(lexer, jsonText, offset);
395
+ c = readChar(lexer, jsonText, offset);
396
396
 
397
397
  while (c >= '0' && c <= '9') {
398
398
  numRd++;
399
399
  RETURN_IF_EOF;
400
- c = readChar(lexer, jsonText, offset);
401
- }
400
+ c = readChar(lexer, jsonText, offset);
401
+ }
402
402
 
403
403
  if (!numRd) {
404
404
  unreadChar(lexer, offset);
@@ -411,18 +411,18 @@ yajl_lex_number(yajl_lexer lexer, const unsigned char * jsonText,
411
411
  /* optional exponent (indicates this is floating point) */
412
412
  if (c == 'e' || c == 'E') {
413
413
  RETURN_IF_EOF;
414
- c = readChar(lexer, jsonText, offset);
414
+ c = readChar(lexer, jsonText, offset);
415
415
 
416
416
  /* optional sign */
417
417
  if (c == '+' || c == '-') {
418
418
  RETURN_IF_EOF;
419
- c = readChar(lexer, jsonText, offset);
419
+ c = readChar(lexer, jsonText, offset);
420
420
  }
421
421
 
422
422
  if (c >= '0' && c <= '9') {
423
423
  do {
424
424
  RETURN_IF_EOF;
425
- c = readChar(lexer, jsonText, offset);
425
+ c = readChar(lexer, jsonText, offset);
426
426
  } while (c >= '0' && c <= '9');
427
427
  } else {
428
428
  unreadChar(lexer, offset);
@@ -431,10 +431,10 @@ yajl_lex_number(yajl_lexer lexer, const unsigned char * jsonText,
431
431
  }
432
432
  tok = yajl_tok_double;
433
433
  }
434
-
434
+
435
435
  /* we always go "one too far" */
436
436
  unreadChar(lexer, offset);
437
-
437
+
438
438
  return tok;
439
439
  }
440
440
 
@@ -446,24 +446,24 @@ yajl_lex_comment(yajl_lexer lexer, const unsigned char * jsonText,
446
446
 
447
447
  yajl_tok tok = yajl_tok_comment;
448
448
 
449
- RETURN_IF_EOF;
449
+ RETURN_IF_EOF;
450
450
  c = readChar(lexer, jsonText, offset);
451
451
 
452
452
  /* either slash or star expected */
453
453
  if (c == '/') {
454
454
  /* now we throw away until end of line */
455
455
  do {
456
- RETURN_IF_EOF;
457
- c = readChar(lexer, jsonText, offset);
456
+ RETURN_IF_EOF;
457
+ c = readChar(lexer, jsonText, offset);
458
458
  } while (c != '\n');
459
459
  } else if (c == '*') {
460
- /* now we throw away until end of comment */
460
+ /* now we throw away until end of comment */
461
461
  for (;;) {
462
- RETURN_IF_EOF;
463
- c = readChar(lexer, jsonText, offset);
462
+ RETURN_IF_EOF;
463
+ c = readChar(lexer, jsonText, offset);
464
464
  if (c == '*') {
465
- RETURN_IF_EOF;
466
- c = readChar(lexer, jsonText, offset);
465
+ RETURN_IF_EOF;
466
+ c = readChar(lexer, jsonText, offset);
467
467
  if (c == '/') {
468
468
  break;
469
469
  } else {
@@ -475,7 +475,7 @@ yajl_lex_comment(yajl_lexer lexer, const unsigned char * jsonText,
475
475
  lexer->error = yajl_lex_invalid_char;
476
476
  tok = yajl_tok_error;
477
477
  }
478
-
478
+
479
479
  return tok;
480
480
  }
481
481
 
@@ -583,7 +583,7 @@ yajl_lex_lex(yajl_lexer lexer, const unsigned char * jsonText,
583
583
  goto lexed;
584
584
  }
585
585
  case '-':
586
- case '0': case '1': case '2': case '3': case '4':
586
+ case '0': case '1': case '2': case '3': case '4':
587
587
  case '5': case '6': case '7': case '8': case '9': {
588
588
  /* integer parsing wants to start from the beginning */
589
589
  unreadChar(lexer, offset);
@@ -610,11 +610,11 @@ yajl_lex_lex(yajl_lexer lexer, const unsigned char * jsonText,
610
610
  jsonTextLen, offset);
611
611
  if (tok == yajl_tok_comment) {
612
612
  /* "error" is silly, but that's the initial
613
- * state of tok. guilty until proven innocent. */
613
+ * state of tok. guilty until proven innocent. */
614
614
  tok = yajl_tok_error;
615
615
  yajl_buf_clear(lexer->buf);
616
616
  lexer->bufInUse = 0;
617
- startOffset = *offset;
617
+ startOffset = *offset;
618
618
  break;
619
619
  }
620
620
  /* hit error or eof, bail */
@@ -635,7 +635,7 @@ yajl_lex_lex(yajl_lexer lexer, const unsigned char * jsonText,
635
635
  lexer->bufInUse = 1;
636
636
  yajl_buf_append(lexer->buf, jsonText + startOffset, *offset - startOffset);
637
637
  lexer->bufOff = 0;
638
-
638
+
639
639
  if (tok != yajl_tok_eof) {
640
640
  *outBuf = yajl_buf_data(lexer->buf);
641
641
  *outLen = yajl_buf_len(lexer->buf);
@@ -651,7 +651,7 @@ yajl_lex_lex(yajl_lexer lexer, const unsigned char * jsonText,
651
651
  {
652
652
  assert(*outLen >= 2);
653
653
  (*outBuf)++;
654
- *outLen -= 2;
654
+ *outLen -= 2;
655
655
  }
656
656
 
657
657
 
@@ -682,7 +682,7 @@ yajl_lex_error_to_string(yajl_lex_error error)
682
682
  case yajl_lex_string_invalid_escaped_char:
683
683
  return "inside a string, '\\' occurs before a character "
684
684
  "which it may not.";
685
- case yajl_lex_string_invalid_json_char:
685
+ case yajl_lex_string_invalid_json_char:
686
686
  return "invalid character inside string.";
687
687
  case yajl_lex_string_invalid_hex_char:
688
688
  return "invalid (non-hex) character occurs after '\\u' inside "
@@ -735,13 +735,13 @@ yajl_tok yajl_lex_peek(yajl_lexer lexer, const unsigned char * jsonText,
735
735
  unsigned int bufOff = lexer->bufOff;
736
736
  unsigned int bufInUse = lexer->bufInUse;
737
737
  yajl_tok tok;
738
-
738
+
739
739
  tok = yajl_lex_lex(lexer, jsonText, jsonTextLen, &offset,
740
740
  &outBuf, &outLen);
741
741
 
742
742
  lexer->bufOff = bufOff;
743
743
  lexer->bufInUse = bufInUse;
744
744
  yajl_buf_truncate(lexer->buf, bufLen);
745
-
745
+
746
746
  return tok;
747
747
  }
data/ext/yajl_lex.h CHANGED
@@ -1,22 +1,22 @@
1
1
  /*
2
- * Copyright 2007-2009, Lloyd Hilaiel.
3
- *
2
+ * Copyright 2010, Lloyd Hilaiel.
3
+ *
4
4
  * Redistribution and use in source and binary forms, with or without
5
5
  * modification, are permitted provided that the following conditions are
6
6
  * met:
7
- *
7
+ *
8
8
  * 1. Redistributions of source code must retain the above copyright
9
9
  * notice, this list of conditions and the following disclaimer.
10
- *
10
+ *
11
11
  * 2. Redistributions in binary form must reproduce the above copyright
12
12
  * notice, this list of conditions and the following disclaimer in
13
13
  * the documentation and/or other materials provided with the
14
14
  * distribution.
15
- *
15
+ *
16
16
  * 3. Neither the name of Lloyd Hilaiel nor the names of its
17
17
  * contributors may be used to endorse or promote products derived
18
18
  * from this software without specific prior written permission.
19
- *
19
+ *
20
20
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21
21
  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
22
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -28,7 +28,7 @@
28
28
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29
29
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
30
  * POSSIBILITY OF SUCH DAMAGE.
31
- */
31
+ */
32
32
 
33
33
  #ifndef __YAJL_LEX_H__
34
34
  #define __YAJL_LEX_H__
@@ -36,21 +36,21 @@
36
36
  #include "api/yajl_common.h"
37
37
 
38
38
  typedef enum {
39
- yajl_tok_bool,
39
+ yajl_tok_bool,
40
40
  yajl_tok_colon,
41
- yajl_tok_comma,
41
+ yajl_tok_comma,
42
42
  yajl_tok_eof,
43
43
  yajl_tok_error,
44
- yajl_tok_left_brace,
44
+ yajl_tok_left_brace,
45
45
  yajl_tok_left_bracket,
46
- yajl_tok_null,
47
- yajl_tok_right_brace,
46
+ yajl_tok_null,
47
+ yajl_tok_right_brace,
48
48
  yajl_tok_right_bracket,
49
49
 
50
50
  /* we differentiate between integers and doubles to allow the
51
51
  * parser to interpret the number without re-scanning */
52
- yajl_tok_integer,
53
- yajl_tok_double,
52
+ yajl_tok_integer,
53
+ yajl_tok_double,
54
54
 
55
55
  /* we differentiate between strings which require further processing,
56
56
  * and strings that do not */
@@ -83,7 +83,7 @@ n * error messages.
83
83
  *
84
84
  * When you pass the next chunk of data, context should be reinitialized
85
85
  * to zero.
86
- *
86
+ *
87
87
  * Finally, the output buffer is usually just a pointer into the jsonText,
88
88
  * however in cases where the entity being lexed spans multiple chunks,
89
89
  * the lexer will buffer the entity and the data returned will be