fastcsv 0.0.5 → 0.0.7

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.
@@ -38,19 +38,19 @@ typedef struct {
38
38
  } Data;
39
39
 
40
40
 
41
- #line 169 "ext/fastcsv/fastcsv.rl"
41
+ #line 172 "ext/fastcsv/fastcsv.rl"
42
42
 
43
43
 
44
44
 
45
45
  #line 46 "ext/fastcsv/fastcsv.c"
46
- static const int raw_parse_start = 5;
47
- static const int raw_parse_first_final = 5;
46
+ static const int raw_parse_start = 4;
47
+ static const int raw_parse_first_final = 4;
48
48
  static const int raw_parse_error = 0;
49
49
 
50
- static const int raw_parse_en_main = 5;
50
+ static const int raw_parse_en_main = 4;
51
51
 
52
52
 
53
- #line 172 "ext/fastcsv/fastcsv.rl"
53
+ #line 175 "ext/fastcsv/fastcsv.rl"
54
54
 
55
55
  // 16 kB
56
56
  #define BUFSIZE 16384
@@ -132,7 +132,7 @@ static VALUE raw_parse(int argc, VALUE *argv, VALUE self) {
132
132
  rb_raise(rb_eArgError, ":col_sep has to be a single character String");
133
133
  }
134
134
 
135
- // @see rb_io_extract_modeenc
135
+ // @see rb_io_extract_modeenc parse_mode_enc
136
136
  /* Set to defaults */
137
137
  rb_io_ext_int_to_encs(NULL, NULL, &enc, &enc2, 0);
138
138
 
@@ -270,7 +270,7 @@ static VALUE raw_parse(int argc, VALUE *argv, VALUE self) {
270
270
  act = 0;
271
271
  }
272
272
 
273
- #line 383 "ext/fastcsv/fastcsv.rl"
273
+ #line 386 "ext/fastcsv/fastcsv.rl"
274
274
 
275
275
  while (!done) {
276
276
  VALUE str;
@@ -350,7 +350,7 @@ tr0:
350
350
  break;
351
351
  }
352
352
  }
353
- goto st5;
353
+ goto st4;
354
354
  tr5:
355
355
  #line 49 "ext/fastcsv/fastcsv.rl"
356
356
  {
@@ -363,7 +363,7 @@ tr5:
363
363
  ENCODE;
364
364
  }
365
365
  }
366
- #line 137 "ext/fastcsv/fastcsv.rl"
366
+ #line 138 "ext/fastcsv/fastcsv.rl"
367
367
  {
368
368
  if (d->start == 0 || p == d->start) { // same as new_row
369
369
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -380,9 +380,9 @@ tr5:
380
380
  rb_yield(row);
381
381
  }
382
382
  }
383
- #line 167 "ext/fastcsv/fastcsv.rl"
383
+ #line 170 "ext/fastcsv/fastcsv.rl"
384
384
  {te = p+1;}
385
- goto st5;
385
+ goto st4;
386
386
  tr6:
387
387
  #line 49 "ext/fastcsv/fastcsv.rl"
388
388
  {
@@ -400,9 +400,9 @@ tr6:
400
400
  rb_ary_push(row, field);
401
401
  field = Qnil;
402
402
  }
403
- #line 165 "ext/fastcsv/fastcsv.rl"
403
+ #line 168 "ext/fastcsv/fastcsv.rl"
404
404
  {te = p+1;}
405
- goto st5;
405
+ goto st4;
406
406
  tr7:
407
407
  #line 49 "ext/fastcsv/fastcsv.rl"
408
408
  {
@@ -420,9 +420,9 @@ tr7:
420
420
  rb_ary_push(row, field);
421
421
  field = Qnil;
422
422
  }
423
- #line 165 "ext/fastcsv/fastcsv.rl"
423
+ #line 168 "ext/fastcsv/fastcsv.rl"
424
424
  {te = p+1;}
425
- #line 137 "ext/fastcsv/fastcsv.rl"
425
+ #line 138 "ext/fastcsv/fastcsv.rl"
426
426
  {
427
427
  if (d->start == 0 || p == d->start) { // same as new_row
428
428
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -439,9 +439,9 @@ tr7:
439
439
  rb_yield(row);
440
440
  }
441
441
  }
442
- goto st5;
443
- tr13:
444
- #line 137 "ext/fastcsv/fastcsv.rl"
442
+ goto st4;
443
+ tr12:
444
+ #line 138 "ext/fastcsv/fastcsv.rl"
445
445
  {
446
446
  if (d->start == 0 || p == d->start) { // same as new_row
447
447
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -458,27 +458,27 @@ tr13:
458
458
  rb_yield(row);
459
459
  }
460
460
  }
461
- #line 167 "ext/fastcsv/fastcsv.rl"
461
+ #line 170 "ext/fastcsv/fastcsv.rl"
462
462
  {te = p+1;}
463
- goto st5;
464
- tr19:
463
+ goto st4;
464
+ tr18:
465
465
  #line 95 "ext/fastcsv/fastcsv.rl"
466
466
  {
467
467
  rb_ary_push(row, field);
468
468
  field = Qnil;
469
469
  }
470
- #line 165 "ext/fastcsv/fastcsv.rl"
470
+ #line 168 "ext/fastcsv/fastcsv.rl"
471
471
  {te = p+1;}
472
- goto st5;
473
- tr20:
472
+ goto st4;
473
+ tr19:
474
474
  #line 95 "ext/fastcsv/fastcsv.rl"
475
475
  {
476
476
  rb_ary_push(row, field);
477
477
  field = Qnil;
478
478
  }
479
- #line 165 "ext/fastcsv/fastcsv.rl"
479
+ #line 168 "ext/fastcsv/fastcsv.rl"
480
480
  {te = p+1;}
481
- #line 137 "ext/fastcsv/fastcsv.rl"
481
+ #line 138 "ext/fastcsv/fastcsv.rl"
482
482
  {
483
483
  if (d->start == 0 || p == d->start) { // same as new_row
484
484
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -495,12 +495,12 @@ tr20:
495
495
  rb_yield(row);
496
496
  }
497
497
  }
498
- goto st5;
499
- tr42:
500
- #line 167 "ext/fastcsv/fastcsv.rl"
498
+ goto st4;
499
+ tr36:
500
+ #line 170 "ext/fastcsv/fastcsv.rl"
501
501
  {te = p;p--;}
502
- goto st5;
503
- tr43:
502
+ goto st4;
503
+ tr37:
504
504
  #line 100 "ext/fastcsv/fastcsv.rl"
505
505
  {
506
506
  d->start = p;
@@ -509,7 +509,7 @@ tr43:
509
509
  if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
510
510
  FREE;
511
511
 
512
- rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline - 1);
512
+ rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline);
513
513
  }
514
514
  }
515
515
  else {
@@ -517,6 +517,8 @@ tr43:
517
517
  row_sep = ALLOC_N(char, len_row_sep);
518
518
  memcpy(row_sep, mark_row_sep, len_row_sep);
519
519
  }
520
+
521
+ curline++;
520
522
  }
521
523
  #line 1 "NONE"
522
524
  { switch( act ) {
@@ -528,8 +530,35 @@ tr43:
528
530
  break;
529
531
  }
530
532
  }
531
- goto st5;
532
- tr50:
533
+ goto st4;
534
+ tr43:
535
+ #line 100 "ext/fastcsv/fastcsv.rl"
536
+ {
537
+ d->start = p;
538
+
539
+ if (len_row_sep) {
540
+ if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
541
+ FREE;
542
+
543
+ rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline);
544
+ }
545
+ }
546
+ else {
547
+ len_row_sep = p - mark_row_sep;
548
+ row_sep = ALLOC_N(char, len_row_sep);
549
+ memcpy(row_sep, mark_row_sep, len_row_sep);
550
+ }
551
+
552
+ curline++;
553
+ }
554
+ #line 169 "ext/fastcsv/fastcsv.rl"
555
+ {te = p;p--;}
556
+ goto st4;
557
+ tr44:
558
+ #line 169 "ext/fastcsv/fastcsv.rl"
559
+ {te = p;p--;}
560
+ goto st4;
561
+ tr45:
533
562
  #line 100 "ext/fastcsv/fastcsv.rl"
534
563
  {
535
564
  d->start = p;
@@ -538,7 +567,7 @@ tr50:
538
567
  if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
539
568
  FREE;
540
569
 
541
- rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline - 1);
570
+ rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline);
542
571
  }
543
572
  }
544
573
  else {
@@ -546,8 +575,10 @@ tr50:
546
575
  row_sep = ALLOC_N(char, len_row_sep);
547
576
  memcpy(row_sep, mark_row_sep, len_row_sep);
548
577
  }
578
+
579
+ curline++;
549
580
  }
550
- #line 137 "ext/fastcsv/fastcsv.rl"
581
+ #line 138 "ext/fastcsv/fastcsv.rl"
551
582
  {
552
583
  if (d->start == 0 || p == d->start) { // same as new_row
553
584
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -564,16 +595,44 @@ tr50:
564
595
  rb_yield(row);
565
596
  }
566
597
  }
567
- #line 167 "ext/fastcsv/fastcsv.rl"
598
+ #line 170 "ext/fastcsv/fastcsv.rl"
568
599
  {te = p+1;}
569
- goto st5;
570
- tr56:
600
+ goto st4;
601
+ tr51:
602
+ #line 95 "ext/fastcsv/fastcsv.rl"
603
+ {
604
+ rb_ary_push(row, field);
605
+ field = Qnil;
606
+ }
607
+ #line 168 "ext/fastcsv/fastcsv.rl"
608
+ {te = p+1;}
609
+ #line 100 "ext/fastcsv/fastcsv.rl"
610
+ {
611
+ d->start = p;
612
+
613
+ if (len_row_sep) {
614
+ if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
615
+ FREE;
616
+
617
+ rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline);
618
+ }
619
+ }
620
+ else {
621
+ len_row_sep = p - mark_row_sep;
622
+ row_sep = ALLOC_N(char, len_row_sep);
623
+ memcpy(row_sep, mark_row_sep, len_row_sep);
624
+ }
625
+
626
+ curline++;
627
+ }
628
+ goto st4;
629
+ tr52:
571
630
  #line 95 "ext/fastcsv/fastcsv.rl"
572
631
  {
573
632
  rb_ary_push(row, field);
574
633
  field = Qnil;
575
634
  }
576
- #line 165 "ext/fastcsv/fastcsv.rl"
635
+ #line 168 "ext/fastcsv/fastcsv.rl"
577
636
  {te = p+1;}
578
637
  #line 100 "ext/fastcsv/fastcsv.rl"
579
638
  {
@@ -583,7 +642,7 @@ tr56:
583
642
  if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
584
643
  FREE;
585
644
 
586
- rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline - 1);
645
+ rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline);
587
646
  }
588
647
  }
589
648
  else {
@@ -591,8 +650,10 @@ tr56:
591
650
  row_sep = ALLOC_N(char, len_row_sep);
592
651
  memcpy(row_sep, mark_row_sep, len_row_sep);
593
652
  }
653
+
654
+ curline++;
594
655
  }
595
- #line 137 "ext/fastcsv/fastcsv.rl"
656
+ #line 138 "ext/fastcsv/fastcsv.rl"
596
657
  {
597
658
  if (d->start == 0 || p == d->start) { // same as new_row
598
659
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -609,39 +670,39 @@ tr56:
609
670
  rb_yield(row);
610
671
  }
611
672
  }
612
- goto st5;
613
- st5:
673
+ goto st4;
674
+ st4:
614
675
  #line 1 "NONE"
615
676
  {ts = 0;}
616
677
  #line 1 "NONE"
617
678
  {act = 0;}
618
679
  if ( ++p == pe )
619
- goto _test_eof5;
620
- case 5:
680
+ goto _test_eof4;
681
+ case 4:
621
682
  #line 1 "NONE"
622
683
  {ts = p;}
623
- #line 624 "ext/fastcsv/fastcsv.c"
684
+ #line 685 "ext/fastcsv/fastcsv.c"
624
685
  _widec = (*p);
625
686
  _widec = (short)(1152 + ((*p) - -128));
626
687
  if (
627
- #line 155 "ext/fastcsv/fastcsv.rl"
688
+ #line 156 "ext/fastcsv/fastcsv.rl"
628
689
  (*p) == quote_char ) _widec += 256;
629
690
  if (
630
- #line 156 "ext/fastcsv/fastcsv.rl"
691
+ #line 157 "ext/fastcsv/fastcsv.rl"
631
692
  (*p) == col_sep ) _widec += 512;
632
693
  switch( _widec ) {
633
- case 1280: goto tr33;
694
+ case 1280: goto tr27;
634
695
  case 1290: goto tr3;
635
696
  case 1293: goto tr4;
636
- case 1536: goto tr35;
637
- case 1546: goto tr36;
638
- case 1549: goto tr37;
697
+ case 1536: goto tr29;
698
+ case 1546: goto tr30;
699
+ case 1549: goto tr31;
639
700
  case 1792: goto tr7;
640
701
  case 1802: goto tr8;
641
702
  case 1805: goto tr9;
642
- case 2048: goto tr39;
643
- case 2058: goto tr40;
644
- case 2061: goto tr41;
703
+ case 2048: goto tr33;
704
+ case 2058: goto tr34;
705
+ case 2061: goto tr35;
645
706
  }
646
707
  if ( _widec < 1408 ) {
647
708
  if ( 1152 <= _widec && _widec <= 1407 )
@@ -649,11 +710,11 @@ case 5:
649
710
  } else if ( _widec > 1663 ) {
650
711
  if ( _widec > 1919 ) {
651
712
  if ( 1920 <= _widec && _widec <= 2175 )
652
- goto tr38;
713
+ goto tr32;
653
714
  } else if ( _widec >= 1664 )
654
715
  goto tr6;
655
716
  } else
656
- goto tr34;
717
+ goto tr28;
657
718
  goto st0;
658
719
  st0:
659
720
  cs = 0;
@@ -665,10 +726,10 @@ case 1:
665
726
  _widec = (*p);
666
727
  _widec = (short)(1152 + ((*p) - -128));
667
728
  if (
668
- #line 155 "ext/fastcsv/fastcsv.rl"
729
+ #line 156 "ext/fastcsv/fastcsv.rl"
669
730
  (*p) == quote_char ) _widec += 256;
670
731
  if (
671
- #line 156 "ext/fastcsv/fastcsv.rl"
732
+ #line 157 "ext/fastcsv/fastcsv.rl"
672
733
  (*p) == col_sep ) _widec += 512;
673
734
  switch( _widec ) {
674
735
  case 1280: goto tr2;
@@ -704,7 +765,7 @@ tr2:
704
765
  ENCODE;
705
766
  }
706
767
  }
707
- #line 137 "ext/fastcsv/fastcsv.rl"
768
+ #line 138 "ext/fastcsv/fastcsv.rl"
708
769
  {
709
770
  if (d->start == 0 || p == d->start) { // same as new_row
710
771
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -721,21 +782,21 @@ tr2:
721
782
  rb_yield(row);
722
783
  }
723
784
  }
724
- #line 167 "ext/fastcsv/fastcsv.rl"
785
+ #line 170 "ext/fastcsv/fastcsv.rl"
725
786
  {act = 3;}
726
- goto st6;
727
- st6:
787
+ goto st5;
788
+ st5:
728
789
  if ( ++p == pe )
729
- goto _test_eof6;
730
- case 6:
731
- #line 732 "ext/fastcsv/fastcsv.c"
790
+ goto _test_eof5;
791
+ case 5:
792
+ #line 793 "ext/fastcsv/fastcsv.c"
732
793
  _widec = (*p);
733
794
  _widec = (short)(1152 + ((*p) - -128));
734
795
  if (
735
- #line 155 "ext/fastcsv/fastcsv.rl"
796
+ #line 156 "ext/fastcsv/fastcsv.rl"
736
797
  (*p) == quote_char ) _widec += 256;
737
798
  if (
738
- #line 156 "ext/fastcsv/fastcsv.rl"
799
+ #line 157 "ext/fastcsv/fastcsv.rl"
739
800
  (*p) == col_sep ) _widec += 512;
740
801
  switch( _widec ) {
741
802
  case 1280: goto tr2;
@@ -756,7 +817,7 @@ case 6:
756
817
  goto tr6;
757
818
  } else if ( _widec >= 1152 )
758
819
  goto st1;
759
- goto tr42;
820
+ goto tr36;
760
821
  tr3:
761
822
  #line 1 "NONE"
762
823
  {te = p+1;}
@@ -771,10 +832,9 @@ tr3:
771
832
  ENCODE;
772
833
  }
773
834
  }
774
- #line 117 "ext/fastcsv/fastcsv.rl"
835
+ #line 119 "ext/fastcsv/fastcsv.rl"
775
836
  {
776
837
  mark_row_sep = p;
777
- curline++;
778
838
 
779
839
  if (d->start == 0 || p == d->start) {
780
840
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -791,9 +851,9 @@ tr3:
791
851
  rb_yield(row);
792
852
  row = rb_ary_new();
793
853
  }
794
- #line 166 "ext/fastcsv/fastcsv.rl"
854
+ #line 169 "ext/fastcsv/fastcsv.rl"
795
855
  {act = 2;}
796
- goto st7;
856
+ goto st6;
797
857
  tr8:
798
858
  #line 1 "NONE"
799
859
  {te = p+1;}
@@ -813,12 +873,11 @@ tr8:
813
873
  rb_ary_push(row, field);
814
874
  field = Qnil;
815
875
  }
816
- #line 165 "ext/fastcsv/fastcsv.rl"
876
+ #line 168 "ext/fastcsv/fastcsv.rl"
817
877
  {act = 1;}
818
- #line 117 "ext/fastcsv/fastcsv.rl"
878
+ #line 119 "ext/fastcsv/fastcsv.rl"
819
879
  {
820
880
  mark_row_sep = p;
821
- curline++;
822
881
 
823
882
  if (d->start == 0 || p == d->start) {
824
883
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -835,14 +894,13 @@ tr8:
835
894
  rb_yield(row);
836
895
  row = rb_ary_new();
837
896
  }
838
- goto st7;
839
- tr14:
897
+ goto st6;
898
+ tr13:
840
899
  #line 1 "NONE"
841
900
  {te = p+1;}
842
- #line 117 "ext/fastcsv/fastcsv.rl"
901
+ #line 119 "ext/fastcsv/fastcsv.rl"
843
902
  {
844
903
  mark_row_sep = p;
845
- curline++;
846
904
 
847
905
  if (d->start == 0 || p == d->start) {
848
906
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -859,10 +917,10 @@ tr14:
859
917
  rb_yield(row);
860
918
  row = rb_ary_new();
861
919
  }
862
- #line 166 "ext/fastcsv/fastcsv.rl"
920
+ #line 169 "ext/fastcsv/fastcsv.rl"
863
921
  {act = 2;}
864
- goto st7;
865
- tr21:
922
+ goto st6;
923
+ tr20:
866
924
  #line 1 "NONE"
867
925
  {te = p+1;}
868
926
  #line 95 "ext/fastcsv/fastcsv.rl"
@@ -870,12 +928,11 @@ tr21:
870
928
  rb_ary_push(row, field);
871
929
  field = Qnil;
872
930
  }
873
- #line 165 "ext/fastcsv/fastcsv.rl"
931
+ #line 168 "ext/fastcsv/fastcsv.rl"
874
932
  {act = 1;}
875
- #line 117 "ext/fastcsv/fastcsv.rl"
933
+ #line 119 "ext/fastcsv/fastcsv.rl"
876
934
  {
877
935
  mark_row_sep = p;
878
- curline++;
879
936
 
880
937
  if (d->start == 0 || p == d->start) {
881
938
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -892,19 +949,112 @@ tr21:
892
949
  rb_yield(row);
893
950
  row = rb_ary_new();
894
951
  }
895
- goto st7;
896
- tr44:
952
+ goto st6;
953
+ tr38:
897
954
  #line 1 "NONE"
898
955
  {te = p+1;}
899
- #line 166 "ext/fastcsv/fastcsv.rl"
956
+ #line 169 "ext/fastcsv/fastcsv.rl"
900
957
  {act = 2;}
901
- goto st7;
902
- st7:
958
+ goto st6;
959
+ tr46:
960
+ #line 1 "NONE"
961
+ {te = p+1;}
962
+ #line 119 "ext/fastcsv/fastcsv.rl"
963
+ {
964
+ mark_row_sep = p;
965
+
966
+ if (d->start == 0 || p == d->start) {
967
+ rb_ivar_set(self, s_row, rb_str_new2(""));
968
+ }
969
+ else if (p > d->start) {
970
+ rb_ivar_set(self, s_row, rb_str_new(d->start, p - d->start));
971
+ }
972
+
973
+ if (!NIL_P(field) || RARRAY_LEN(row)) { // same as new_field
974
+ rb_ary_push(row, field);
975
+ field = Qnil;
976
+ }
977
+
978
+ rb_yield(row);
979
+ row = rb_ary_new();
980
+ }
981
+ #line 100 "ext/fastcsv/fastcsv.rl"
982
+ {
983
+ d->start = p;
984
+
985
+ if (len_row_sep) {
986
+ if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
987
+ FREE;
988
+
989
+ rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline);
990
+ }
991
+ }
992
+ else {
993
+ len_row_sep = p - mark_row_sep;
994
+ row_sep = ALLOC_N(char, len_row_sep);
995
+ memcpy(row_sep, mark_row_sep, len_row_sep);
996
+ }
997
+
998
+ curline++;
999
+ }
1000
+ #line 169 "ext/fastcsv/fastcsv.rl"
1001
+ {act = 2;}
1002
+ goto st6;
1003
+ tr53:
1004
+ #line 1 "NONE"
1005
+ {te = p+1;}
1006
+ #line 95 "ext/fastcsv/fastcsv.rl"
1007
+ {
1008
+ rb_ary_push(row, field);
1009
+ field = Qnil;
1010
+ }
1011
+ #line 168 "ext/fastcsv/fastcsv.rl"
1012
+ {act = 1;}
1013
+ #line 119 "ext/fastcsv/fastcsv.rl"
1014
+ {
1015
+ mark_row_sep = p;
1016
+
1017
+ if (d->start == 0 || p == d->start) {
1018
+ rb_ivar_set(self, s_row, rb_str_new2(""));
1019
+ }
1020
+ else if (p > d->start) {
1021
+ rb_ivar_set(self, s_row, rb_str_new(d->start, p - d->start));
1022
+ }
1023
+
1024
+ if (!NIL_P(field) || RARRAY_LEN(row)) { // same as new_field
1025
+ rb_ary_push(row, field);
1026
+ field = Qnil;
1027
+ }
1028
+
1029
+ rb_yield(row);
1030
+ row = rb_ary_new();
1031
+ }
1032
+ #line 100 "ext/fastcsv/fastcsv.rl"
1033
+ {
1034
+ d->start = p;
1035
+
1036
+ if (len_row_sep) {
1037
+ if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
1038
+ FREE;
1039
+
1040
+ rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline);
1041
+ }
1042
+ }
1043
+ else {
1044
+ len_row_sep = p - mark_row_sep;
1045
+ row_sep = ALLOC_N(char, len_row_sep);
1046
+ memcpy(row_sep, mark_row_sep, len_row_sep);
1047
+ }
1048
+
1049
+ curline++;
1050
+ }
1051
+ goto st6;
1052
+ st6:
903
1053
  if ( ++p == pe )
904
- goto _test_eof7;
905
- case 7:
906
- #line 907 "ext/fastcsv/fastcsv.c"
907
- goto tr43;
1054
+ goto _test_eof6;
1055
+ case 6:
1056
+ #line 1057 "ext/fastcsv/fastcsv.c"
1057
+ goto tr37;
908
1058
  tr4:
909
1059
  #line 1 "NONE"
910
1060
  {te = p+1;}
@@ -919,10 +1069,9 @@ tr4:
919
1069
  ENCODE;
920
1070
  }
921
1071
  }
922
- #line 117 "ext/fastcsv/fastcsv.rl"
1072
+ #line 119 "ext/fastcsv/fastcsv.rl"
923
1073
  {
924
1074
  mark_row_sep = p;
925
- curline++;
926
1075
 
927
1076
  if (d->start == 0 || p == d->start) {
928
1077
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -939,9 +1088,9 @@ tr4:
939
1088
  rb_yield(row);
940
1089
  row = rb_ary_new();
941
1090
  }
942
- #line 166 "ext/fastcsv/fastcsv.rl"
1091
+ #line 169 "ext/fastcsv/fastcsv.rl"
943
1092
  {act = 2;}
944
- goto st8;
1093
+ goto st7;
945
1094
  tr9:
946
1095
  #line 1 "NONE"
947
1096
  {te = p+1;}
@@ -961,12 +1110,11 @@ tr9:
961
1110
  rb_ary_push(row, field);
962
1111
  field = Qnil;
963
1112
  }
964
- #line 165 "ext/fastcsv/fastcsv.rl"
1113
+ #line 168 "ext/fastcsv/fastcsv.rl"
965
1114
  {act = 1;}
966
- #line 117 "ext/fastcsv/fastcsv.rl"
1115
+ #line 119 "ext/fastcsv/fastcsv.rl"
967
1116
  {
968
1117
  mark_row_sep = p;
969
- curline++;
970
1118
 
971
1119
  if (d->start == 0 || p == d->start) {
972
1120
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -983,14 +1131,13 @@ tr9:
983
1131
  rb_yield(row);
984
1132
  row = rb_ary_new();
985
1133
  }
986
- goto st8;
987
- tr15:
1134
+ goto st7;
1135
+ tr14:
988
1136
  #line 1 "NONE"
989
1137
  {te = p+1;}
990
- #line 117 "ext/fastcsv/fastcsv.rl"
1138
+ #line 119 "ext/fastcsv/fastcsv.rl"
991
1139
  {
992
1140
  mark_row_sep = p;
993
- curline++;
994
1141
 
995
1142
  if (d->start == 0 || p == d->start) {
996
1143
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -1007,10 +1154,10 @@ tr15:
1007
1154
  rb_yield(row);
1008
1155
  row = rb_ary_new();
1009
1156
  }
1010
- #line 166 "ext/fastcsv/fastcsv.rl"
1157
+ #line 169 "ext/fastcsv/fastcsv.rl"
1011
1158
  {act = 2;}
1012
- goto st8;
1013
- tr22:
1159
+ goto st7;
1160
+ tr21:
1014
1161
  #line 1 "NONE"
1015
1162
  {te = p+1;}
1016
1163
  #line 95 "ext/fastcsv/fastcsv.rl"
@@ -1018,12 +1165,11 @@ tr22:
1018
1165
  rb_ary_push(row, field);
1019
1166
  field = Qnil;
1020
1167
  }
1021
- #line 165 "ext/fastcsv/fastcsv.rl"
1168
+ #line 168 "ext/fastcsv/fastcsv.rl"
1022
1169
  {act = 1;}
1023
- #line 117 "ext/fastcsv/fastcsv.rl"
1170
+ #line 119 "ext/fastcsv/fastcsv.rl"
1024
1171
  {
1025
1172
  mark_row_sep = p;
1026
- curline++;
1027
1173
 
1028
1174
  if (d->start == 0 || p == d->start) {
1029
1175
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -1040,16 +1186,109 @@ tr22:
1040
1186
  rb_yield(row);
1041
1187
  row = rb_ary_new();
1042
1188
  }
1043
- goto st8;
1044
- st8:
1045
- if ( ++p == pe )
1046
- goto _test_eof8;
1047
- case 8:
1048
- #line 1049 "ext/fastcsv/fastcsv.c"
1049
- if ( (*p) == 10 )
1050
- goto tr44;
1051
- goto tr43;
1052
- tr33:
1189
+ goto st7;
1190
+ tr47:
1191
+ #line 1 "NONE"
1192
+ {te = p+1;}
1193
+ #line 119 "ext/fastcsv/fastcsv.rl"
1194
+ {
1195
+ mark_row_sep = p;
1196
+
1197
+ if (d->start == 0 || p == d->start) {
1198
+ rb_ivar_set(self, s_row, rb_str_new2(""));
1199
+ }
1200
+ else if (p > d->start) {
1201
+ rb_ivar_set(self, s_row, rb_str_new(d->start, p - d->start));
1202
+ }
1203
+
1204
+ if (!NIL_P(field) || RARRAY_LEN(row)) { // same as new_field
1205
+ rb_ary_push(row, field);
1206
+ field = Qnil;
1207
+ }
1208
+
1209
+ rb_yield(row);
1210
+ row = rb_ary_new();
1211
+ }
1212
+ #line 100 "ext/fastcsv/fastcsv.rl"
1213
+ {
1214
+ d->start = p;
1215
+
1216
+ if (len_row_sep) {
1217
+ if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
1218
+ FREE;
1219
+
1220
+ rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline);
1221
+ }
1222
+ }
1223
+ else {
1224
+ len_row_sep = p - mark_row_sep;
1225
+ row_sep = ALLOC_N(char, len_row_sep);
1226
+ memcpy(row_sep, mark_row_sep, len_row_sep);
1227
+ }
1228
+
1229
+ curline++;
1230
+ }
1231
+ #line 169 "ext/fastcsv/fastcsv.rl"
1232
+ {act = 2;}
1233
+ goto st7;
1234
+ tr54:
1235
+ #line 1 "NONE"
1236
+ {te = p+1;}
1237
+ #line 95 "ext/fastcsv/fastcsv.rl"
1238
+ {
1239
+ rb_ary_push(row, field);
1240
+ field = Qnil;
1241
+ }
1242
+ #line 168 "ext/fastcsv/fastcsv.rl"
1243
+ {act = 1;}
1244
+ #line 119 "ext/fastcsv/fastcsv.rl"
1245
+ {
1246
+ mark_row_sep = p;
1247
+
1248
+ if (d->start == 0 || p == d->start) {
1249
+ rb_ivar_set(self, s_row, rb_str_new2(""));
1250
+ }
1251
+ else if (p > d->start) {
1252
+ rb_ivar_set(self, s_row, rb_str_new(d->start, p - d->start));
1253
+ }
1254
+
1255
+ if (!NIL_P(field) || RARRAY_LEN(row)) { // same as new_field
1256
+ rb_ary_push(row, field);
1257
+ field = Qnil;
1258
+ }
1259
+
1260
+ rb_yield(row);
1261
+ row = rb_ary_new();
1262
+ }
1263
+ #line 100 "ext/fastcsv/fastcsv.rl"
1264
+ {
1265
+ d->start = p;
1266
+
1267
+ if (len_row_sep) {
1268
+ if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
1269
+ FREE;
1270
+
1271
+ rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline);
1272
+ }
1273
+ }
1274
+ else {
1275
+ len_row_sep = p - mark_row_sep;
1276
+ row_sep = ALLOC_N(char, len_row_sep);
1277
+ memcpy(row_sep, mark_row_sep, len_row_sep);
1278
+ }
1279
+
1280
+ curline++;
1281
+ }
1282
+ goto st7;
1283
+ st7:
1284
+ if ( ++p == pe )
1285
+ goto _test_eof7;
1286
+ case 7:
1287
+ #line 1288 "ext/fastcsv/fastcsv.c"
1288
+ if ( (*p) == 10 )
1289
+ goto tr38;
1290
+ goto tr37;
1291
+ tr27:
1053
1292
  #line 1 "NONE"
1054
1293
  {te = p+1;}
1055
1294
  #line 49 "ext/fastcsv/fastcsv.rl"
@@ -1063,7 +1302,7 @@ tr33:
1063
1302
  ENCODE;
1064
1303
  }
1065
1304
  }
1066
- #line 137 "ext/fastcsv/fastcsv.rl"
1305
+ #line 138 "ext/fastcsv/fastcsv.rl"
1067
1306
  {
1068
1307
  if (d->start == 0 || p == d->start) { // same as new_row
1069
1308
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -1080,21 +1319,21 @@ tr33:
1080
1319
  rb_yield(row);
1081
1320
  }
1082
1321
  }
1083
- #line 167 "ext/fastcsv/fastcsv.rl"
1322
+ #line 170 "ext/fastcsv/fastcsv.rl"
1084
1323
  {act = 3;}
1085
- goto st9;
1086
- st9:
1324
+ goto st8;
1325
+ st8:
1087
1326
  if ( ++p == pe )
1088
- goto _test_eof9;
1089
- case 9:
1090
- #line 1091 "ext/fastcsv/fastcsv.c"
1327
+ goto _test_eof8;
1328
+ case 8:
1329
+ #line 1330 "ext/fastcsv/fastcsv.c"
1091
1330
  _widec = (*p);
1092
1331
  _widec = (short)(1152 + ((*p) - -128));
1093
1332
  if (
1094
- #line 155 "ext/fastcsv/fastcsv.rl"
1333
+ #line 156 "ext/fastcsv/fastcsv.rl"
1095
1334
  (*p) == quote_char ) _widec += 256;
1096
1335
  if (
1097
- #line 156 "ext/fastcsv/fastcsv.rl"
1336
+ #line 157 "ext/fastcsv/fastcsv.rl"
1098
1337
  (*p) == col_sep ) _widec += 512;
1099
1338
  if ( _widec < 1291 ) {
1100
1339
  if ( 1152 <= _widec && _widec <= 1289 )
@@ -1104,14 +1343,14 @@ case 9:
1104
1343
  goto st1;
1105
1344
  } else
1106
1345
  goto st1;
1107
- goto tr42;
1108
- tr34:
1346
+ goto tr36;
1347
+ tr28:
1109
1348
  #line 41 "ext/fastcsv/fastcsv.rl"
1110
1349
  {
1111
1350
  unclosed_line = curline;
1112
1351
  }
1113
1352
  goto st2;
1114
- tr45:
1353
+ tr39:
1115
1354
  #line 100 "ext/fastcsv/fastcsv.rl"
1116
1355
  {
1117
1356
  d->start = p;
@@ -1120,7 +1359,7 @@ tr45:
1120
1359
  if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
1121
1360
  FREE;
1122
1361
 
1123
- rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline - 1);
1362
+ rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline);
1124
1363
  }
1125
1364
  }
1126
1365
  else {
@@ -1128,22 +1367,20 @@ tr45:
1128
1367
  row_sep = ALLOC_N(char, len_row_sep);
1129
1368
  memcpy(row_sep, mark_row_sep, len_row_sep);
1130
1369
  }
1370
+
1371
+ curline++;
1131
1372
  }
1132
1373
  goto st2;
1133
1374
  st2:
1134
1375
  if ( ++p == pe )
1135
1376
  goto _test_eof2;
1136
1377
  case 2:
1137
- #line 1138 "ext/fastcsv/fastcsv.c"
1378
+ #line 1379 "ext/fastcsv/fastcsv.c"
1138
1379
  _widec = (*p);
1139
1380
  _widec = (short)(128 + ((*p) - -128));
1140
1381
  if (
1141
- #line 155 "ext/fastcsv/fastcsv.rl"
1382
+ #line 156 "ext/fastcsv/fastcsv.rl"
1142
1383
  (*p) == quote_char ) _widec += 256;
1143
- switch( _widec ) {
1144
- case 522: goto tr12;
1145
- case 525: goto tr12;
1146
- }
1147
1384
  if ( _widec < 257 ) {
1148
1385
  if ( 128 <= _widec && _widec <= 255 )
1149
1386
  goto st2;
@@ -1194,7 +1431,7 @@ tr11:
1194
1431
  unclosed_line = 0;
1195
1432
  }
1196
1433
  goto st3;
1197
- tr46:
1434
+ tr40:
1198
1435
  #line 60 "ext/fastcsv/fastcsv.rl"
1199
1436
  {
1200
1437
  if (p == ts) {
@@ -1242,7 +1479,7 @@ tr46:
1242
1479
  if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
1243
1480
  FREE;
1244
1481
 
1245
- rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline - 1);
1482
+ rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline);
1246
1483
  }
1247
1484
  }
1248
1485
  else {
@@ -1250,48 +1487,50 @@ tr46:
1250
1487
  row_sep = ALLOC_N(char, len_row_sep);
1251
1488
  memcpy(row_sep, mark_row_sep, len_row_sep);
1252
1489
  }
1490
+
1491
+ curline++;
1253
1492
  }
1254
1493
  goto st3;
1255
1494
  st3:
1256
1495
  if ( ++p == pe )
1257
1496
  goto _test_eof3;
1258
1497
  case 3:
1259
- #line 1260 "ext/fastcsv/fastcsv.c"
1498
+ #line 1499 "ext/fastcsv/fastcsv.c"
1260
1499
  _widec = (*p);
1261
1500
  _widec = (short)(1152 + ((*p) - -128));
1262
1501
  if (
1263
- #line 155 "ext/fastcsv/fastcsv.rl"
1502
+ #line 156 "ext/fastcsv/fastcsv.rl"
1264
1503
  (*p) == quote_char ) _widec += 256;
1265
1504
  if (
1266
- #line 156 "ext/fastcsv/fastcsv.rl"
1505
+ #line 157 "ext/fastcsv/fastcsv.rl"
1267
1506
  (*p) == col_sep ) _widec += 512;
1268
1507
  switch( _widec ) {
1269
- case 1280: goto tr13;
1270
- case 1290: goto tr14;
1271
- case 1293: goto tr15;
1272
- case 1536: goto tr16;
1273
- case 1546: goto tr17;
1274
- case 1549: goto tr18;
1275
- case 1792: goto tr20;
1276
- case 1802: goto tr21;
1277
- case 1805: goto tr22;
1278
- case 2048: goto tr24;
1279
- case 2058: goto tr25;
1280
- case 2061: goto tr26;
1508
+ case 1280: goto tr12;
1509
+ case 1290: goto tr13;
1510
+ case 1293: goto tr14;
1511
+ case 1536: goto tr15;
1512
+ case 1546: goto tr16;
1513
+ case 1549: goto tr17;
1514
+ case 1792: goto tr19;
1515
+ case 1802: goto tr20;
1516
+ case 1805: goto tr21;
1517
+ case 2048: goto tr23;
1518
+ case 2058: goto tr24;
1519
+ case 2061: goto tr25;
1281
1520
  }
1282
1521
  if ( _widec < 1664 ) {
1283
1522
  if ( 1408 <= _widec && _widec <= 1663 )
1284
1523
  goto st2;
1285
1524
  } else if ( _widec > 1919 ) {
1286
1525
  if ( 1920 <= _widec && _widec <= 2175 )
1287
- goto tr23;
1526
+ goto tr22;
1288
1527
  } else
1289
- goto tr19;
1528
+ goto tr18;
1290
1529
  goto tr0;
1291
- tr16:
1530
+ tr15:
1292
1531
  #line 1 "NONE"
1293
1532
  {te = p+1;}
1294
- #line 137 "ext/fastcsv/fastcsv.rl"
1533
+ #line 138 "ext/fastcsv/fastcsv.rl"
1295
1534
  {
1296
1535
  if (d->start == 0 || p == d->start) { // same as new_row
1297
1536
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -1308,10 +1547,10 @@ tr16:
1308
1547
  rb_yield(row);
1309
1548
  }
1310
1549
  }
1311
- #line 167 "ext/fastcsv/fastcsv.rl"
1550
+ #line 170 "ext/fastcsv/fastcsv.rl"
1312
1551
  {act = 3;}
1313
- goto st10;
1314
- tr23:
1552
+ goto st9;
1553
+ tr22:
1315
1554
  #line 1 "NONE"
1316
1555
  {te = p+1;}
1317
1556
  #line 95 "ext/fastcsv/fastcsv.rl"
@@ -1319,10 +1558,10 @@ tr23:
1319
1558
  rb_ary_push(row, field);
1320
1559
  field = Qnil;
1321
1560
  }
1322
- #line 165 "ext/fastcsv/fastcsv.rl"
1561
+ #line 168 "ext/fastcsv/fastcsv.rl"
1323
1562
  {act = 1;}
1324
- goto st10;
1325
- tr24:
1563
+ goto st9;
1564
+ tr23:
1326
1565
  #line 1 "NONE"
1327
1566
  {te = p+1;}
1328
1567
  #line 95 "ext/fastcsv/fastcsv.rl"
@@ -1330,9 +1569,9 @@ tr24:
1330
1569
  rb_ary_push(row, field);
1331
1570
  field = Qnil;
1332
1571
  }
1333
- #line 165 "ext/fastcsv/fastcsv.rl"
1572
+ #line 168 "ext/fastcsv/fastcsv.rl"
1334
1573
  {act = 1;}
1335
- #line 137 "ext/fastcsv/fastcsv.rl"
1574
+ #line 138 "ext/fastcsv/fastcsv.rl"
1336
1575
  {
1337
1576
  if (d->start == 0 || p == d->start) { // same as new_row
1338
1577
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -1349,8 +1588,8 @@ tr24:
1349
1588
  rb_yield(row);
1350
1589
  }
1351
1590
  }
1352
- goto st10;
1353
- tr35:
1591
+ goto st9;
1592
+ tr29:
1354
1593
  #line 1 "NONE"
1355
1594
  {te = p+1;}
1356
1595
  #line 41 "ext/fastcsv/fastcsv.rl"
@@ -1368,7 +1607,7 @@ tr35:
1368
1607
  ENCODE;
1369
1608
  }
1370
1609
  }
1371
- #line 137 "ext/fastcsv/fastcsv.rl"
1610
+ #line 138 "ext/fastcsv/fastcsv.rl"
1372
1611
  {
1373
1612
  if (d->start == 0 || p == d->start) { // same as new_row
1374
1613
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -1385,10 +1624,10 @@ tr35:
1385
1624
  rb_yield(row);
1386
1625
  }
1387
1626
  }
1388
- #line 167 "ext/fastcsv/fastcsv.rl"
1627
+ #line 170 "ext/fastcsv/fastcsv.rl"
1389
1628
  {act = 3;}
1390
- goto st10;
1391
- tr38:
1629
+ goto st9;
1630
+ tr32:
1392
1631
  #line 1 "NONE"
1393
1632
  {te = p+1;}
1394
1633
  #line 49 "ext/fastcsv/fastcsv.rl"
@@ -1411,10 +1650,10 @@ tr38:
1411
1650
  rb_ary_push(row, field);
1412
1651
  field = Qnil;
1413
1652
  }
1414
- #line 165 "ext/fastcsv/fastcsv.rl"
1653
+ #line 168 "ext/fastcsv/fastcsv.rl"
1415
1654
  {act = 1;}
1416
- goto st10;
1417
- tr39:
1655
+ goto st9;
1656
+ tr33:
1418
1657
  #line 1 "NONE"
1419
1658
  {te = p+1;}
1420
1659
  #line 49 "ext/fastcsv/fastcsv.rl"
@@ -1437,9 +1676,9 @@ tr39:
1437
1676
  rb_ary_push(row, field);
1438
1677
  field = Qnil;
1439
1678
  }
1440
- #line 165 "ext/fastcsv/fastcsv.rl"
1679
+ #line 168 "ext/fastcsv/fastcsv.rl"
1441
1680
  {act = 1;}
1442
- #line 137 "ext/fastcsv/fastcsv.rl"
1681
+ #line 138 "ext/fastcsv/fastcsv.rl"
1443
1682
  {
1444
1683
  if (d->start == 0 || p == d->start) { // same as new_row
1445
1684
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -1456,7 +1695,49 @@ tr39:
1456
1695
  rb_yield(row);
1457
1696
  }
1458
1697
  }
1459
- goto st10;
1698
+ goto st9;
1699
+ tr48:
1700
+ #line 1 "NONE"
1701
+ {te = p+1;}
1702
+ #line 100 "ext/fastcsv/fastcsv.rl"
1703
+ {
1704
+ d->start = p;
1705
+
1706
+ if (len_row_sep) {
1707
+ if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
1708
+ FREE;
1709
+
1710
+ rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline);
1711
+ }
1712
+ }
1713
+ else {
1714
+ len_row_sep = p - mark_row_sep;
1715
+ row_sep = ALLOC_N(char, len_row_sep);
1716
+ memcpy(row_sep, mark_row_sep, len_row_sep);
1717
+ }
1718
+
1719
+ curline++;
1720
+ }
1721
+ #line 138 "ext/fastcsv/fastcsv.rl"
1722
+ {
1723
+ if (d->start == 0 || p == d->start) { // same as new_row
1724
+ rb_ivar_set(self, s_row, rb_str_new2(""));
1725
+ }
1726
+ else if (p > d->start) {
1727
+ rb_ivar_set(self, s_row, rb_str_new(d->start, p - d->start));
1728
+ }
1729
+
1730
+ if (!NIL_P(field) || RARRAY_LEN(row)) {
1731
+ rb_ary_push(row, field);
1732
+ }
1733
+
1734
+ if (RARRAY_LEN(row)) {
1735
+ rb_yield(row);
1736
+ }
1737
+ }
1738
+ #line 170 "ext/fastcsv/fastcsv.rl"
1739
+ {act = 3;}
1740
+ goto st9;
1460
1741
  tr55:
1461
1742
  #line 1 "NONE"
1462
1743
  {te = p+1;}
@@ -1465,7 +1746,7 @@ tr55:
1465
1746
  rb_ary_push(row, field);
1466
1747
  field = Qnil;
1467
1748
  }
1468
- #line 165 "ext/fastcsv/fastcsv.rl"
1749
+ #line 168 "ext/fastcsv/fastcsv.rl"
1469
1750
  {act = 1;}
1470
1751
  #line 100 "ext/fastcsv/fastcsv.rl"
1471
1752
  {
@@ -1475,7 +1756,7 @@ tr55:
1475
1756
  if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
1476
1757
  FREE;
1477
1758
 
1478
- rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline - 1);
1759
+ rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline);
1479
1760
  }
1480
1761
  }
1481
1762
  else {
@@ -1483,22 +1764,67 @@ tr55:
1483
1764
  row_sep = ALLOC_N(char, len_row_sep);
1484
1765
  memcpy(row_sep, mark_row_sep, len_row_sep);
1485
1766
  }
1767
+
1768
+ curline++;
1486
1769
  }
1487
- goto st10;
1488
- st10:
1770
+ goto st9;
1771
+ tr56:
1772
+ #line 1 "NONE"
1773
+ {te = p+1;}
1774
+ #line 95 "ext/fastcsv/fastcsv.rl"
1775
+ {
1776
+ rb_ary_push(row, field);
1777
+ field = Qnil;
1778
+ }
1779
+ #line 168 "ext/fastcsv/fastcsv.rl"
1780
+ {act = 1;}
1781
+ #line 100 "ext/fastcsv/fastcsv.rl"
1782
+ {
1783
+ d->start = p;
1784
+
1785
+ if (len_row_sep) {
1786
+ if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
1787
+ FREE;
1788
+
1789
+ rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline);
1790
+ }
1791
+ }
1792
+ else {
1793
+ len_row_sep = p - mark_row_sep;
1794
+ row_sep = ALLOC_N(char, len_row_sep);
1795
+ memcpy(row_sep, mark_row_sep, len_row_sep);
1796
+ }
1797
+
1798
+ curline++;
1799
+ }
1800
+ #line 138 "ext/fastcsv/fastcsv.rl"
1801
+ {
1802
+ if (d->start == 0 || p == d->start) { // same as new_row
1803
+ rb_ivar_set(self, s_row, rb_str_new2(""));
1804
+ }
1805
+ else if (p > d->start) {
1806
+ rb_ivar_set(self, s_row, rb_str_new(d->start, p - d->start));
1807
+ }
1808
+
1809
+ if (!NIL_P(field) || RARRAY_LEN(row)) {
1810
+ rb_ary_push(row, field);
1811
+ }
1812
+
1813
+ if (RARRAY_LEN(row)) {
1814
+ rb_yield(row);
1815
+ }
1816
+ }
1817
+ goto st9;
1818
+ st9:
1489
1819
  if ( ++p == pe )
1490
- goto _test_eof10;
1491
- case 10:
1492
- #line 1493 "ext/fastcsv/fastcsv.c"
1820
+ goto _test_eof9;
1821
+ case 9:
1822
+ #line 1823 "ext/fastcsv/fastcsv.c"
1493
1823
  _widec = (*p);
1494
1824
  _widec = (short)(128 + ((*p) - -128));
1495
1825
  if (
1496
- #line 155 "ext/fastcsv/fastcsv.rl"
1826
+ #line 156 "ext/fastcsv/fastcsv.rl"
1497
1827
  (*p) == quote_char ) _widec += 256;
1498
- switch( _widec ) {
1499
- case 522: goto tr12;
1500
- case 525: goto tr12;
1501
- }
1502
1828
  if ( _widec < 257 ) {
1503
1829
  if ( 128 <= _widec && _widec <= 255 )
1504
1830
  goto st2;
@@ -1508,151 +1834,12 @@ case 10:
1508
1834
  } else
1509
1835
  goto st2;
1510
1836
  goto tr0;
1511
- tr12:
1512
- #line 60 "ext/fastcsv/fastcsv.rl"
1837
+ tr16:
1838
+ #line 1 "NONE"
1839
+ {te = p+1;}
1840
+ #line 119 "ext/fastcsv/fastcsv.rl"
1513
1841
  {
1514
- if (p == ts) {
1515
- field = rb_enc_str_new("", 0, encoding);
1516
- ENCODE;
1517
- }
1518
- // @note If we add an action on '""', we can skip some steps if no '""' is found.
1519
- else if (p > ts) {
1520
- // Operating on ts in-place produces odd behavior, FYI.
1521
- char *copy = ALLOC_N(char, p - ts);
1522
- memcpy(copy, ts, p - ts);
1523
-
1524
- char *reader = ts, *writer = copy;
1525
- int escaped = 0;
1526
-
1527
- while (p > reader) {
1528
- if (*reader == quote_char && !escaped) {
1529
- // Skip the escaping character.
1530
- escaped = 1;
1531
- }
1532
- else {
1533
- escaped = 0;
1534
- *writer++ = *reader;
1535
- }
1536
- reader++;
1537
- }
1538
-
1539
- field = rb_enc_str_new(copy, writer - copy, encoding);
1540
- ENCODE;
1541
-
1542
- if (copy != NULL) {
1543
- free(copy);
1544
- }
1545
- }
1546
- }
1547
- #line 45 "ext/fastcsv/fastcsv.rl"
1548
- {
1549
- unclosed_line = 0;
1550
- }
1551
- goto st4;
1552
- tr47:
1553
- #line 60 "ext/fastcsv/fastcsv.rl"
1554
- {
1555
- if (p == ts) {
1556
- field = rb_enc_str_new("", 0, encoding);
1557
- ENCODE;
1558
- }
1559
- // @note If we add an action on '""', we can skip some steps if no '""' is found.
1560
- else if (p > ts) {
1561
- // Operating on ts in-place produces odd behavior, FYI.
1562
- char *copy = ALLOC_N(char, p - ts);
1563
- memcpy(copy, ts, p - ts);
1564
-
1565
- char *reader = ts, *writer = copy;
1566
- int escaped = 0;
1567
-
1568
- while (p > reader) {
1569
- if (*reader == quote_char && !escaped) {
1570
- // Skip the escaping character.
1571
- escaped = 1;
1572
- }
1573
- else {
1574
- escaped = 0;
1575
- *writer++ = *reader;
1576
- }
1577
- reader++;
1578
- }
1579
-
1580
- field = rb_enc_str_new(copy, writer - copy, encoding);
1581
- ENCODE;
1582
-
1583
- if (copy != NULL) {
1584
- free(copy);
1585
- }
1586
- }
1587
- }
1588
- #line 45 "ext/fastcsv/fastcsv.rl"
1589
- {
1590
- unclosed_line = 0;
1591
- }
1592
- #line 100 "ext/fastcsv/fastcsv.rl"
1593
- {
1594
- d->start = p;
1595
-
1596
- if (len_row_sep) {
1597
- if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
1598
- FREE;
1599
-
1600
- rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline - 1);
1601
- }
1602
- }
1603
- else {
1604
- len_row_sep = p - mark_row_sep;
1605
- row_sep = ALLOC_N(char, len_row_sep);
1606
- memcpy(row_sep, mark_row_sep, len_row_sep);
1607
- }
1608
- }
1609
- goto st4;
1610
- st4:
1611
- if ( ++p == pe )
1612
- goto _test_eof4;
1613
- case 4:
1614
- #line 1615 "ext/fastcsv/fastcsv.c"
1615
- _widec = (*p);
1616
- _widec = (short)(1152 + ((*p) - -128));
1617
- if (
1618
- #line 155 "ext/fastcsv/fastcsv.rl"
1619
- (*p) == quote_char ) _widec += 256;
1620
- if (
1621
- #line 156 "ext/fastcsv/fastcsv.rl"
1622
- (*p) == col_sep ) _widec += 512;
1623
- switch( _widec ) {
1624
- case 1280: goto tr13;
1625
- case 1290: goto tr17;
1626
- case 1293: goto tr18;
1627
- case 1536: goto tr27;
1628
- case 1546: goto tr28;
1629
- case 1549: goto tr28;
1630
- case 1792: goto tr20;
1631
- case 1802: goto tr25;
1632
- case 1805: goto tr26;
1633
- case 2048: goto tr30;
1634
- case 2058: goto tr31;
1635
- case 2061: goto tr31;
1636
- }
1637
- if ( _widec < 1408 ) {
1638
- if ( 1152 <= _widec && _widec <= 1407 )
1639
- goto st2;
1640
- } else if ( _widec > 1663 ) {
1641
- if ( _widec > 1919 ) {
1642
- if ( 1920 <= _widec && _widec <= 2175 )
1643
- goto tr29;
1644
- } else if ( _widec >= 1664 )
1645
- goto tr23;
1646
- } else
1647
- goto tr12;
1648
- goto tr0;
1649
- tr17:
1650
- #line 1 "NONE"
1651
- {te = p+1;}
1652
- #line 117 "ext/fastcsv/fastcsv.rl"
1653
- {
1654
- mark_row_sep = p;
1655
- curline++;
1842
+ mark_row_sep = p;
1656
1843
 
1657
1844
  if (d->start == 0 || p == d->start) {
1658
1845
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -1669,10 +1856,10 @@ tr17:
1669
1856
  rb_yield(row);
1670
1857
  row = rb_ary_new();
1671
1858
  }
1672
- #line 166 "ext/fastcsv/fastcsv.rl"
1859
+ #line 169 "ext/fastcsv/fastcsv.rl"
1673
1860
  {act = 2;}
1674
- goto st11;
1675
- tr25:
1861
+ goto st10;
1862
+ tr24:
1676
1863
  #line 1 "NONE"
1677
1864
  {te = p+1;}
1678
1865
  #line 95 "ext/fastcsv/fastcsv.rl"
@@ -1680,12 +1867,11 @@ tr25:
1680
1867
  rb_ary_push(row, field);
1681
1868
  field = Qnil;
1682
1869
  }
1683
- #line 165 "ext/fastcsv/fastcsv.rl"
1870
+ #line 168 "ext/fastcsv/fastcsv.rl"
1684
1871
  {act = 1;}
1685
- #line 117 "ext/fastcsv/fastcsv.rl"
1872
+ #line 119 "ext/fastcsv/fastcsv.rl"
1686
1873
  {
1687
1874
  mark_row_sep = p;
1688
- curline++;
1689
1875
 
1690
1876
  if (d->start == 0 || p == d->start) {
1691
1877
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -1702,8 +1888,8 @@ tr25:
1702
1888
  rb_yield(row);
1703
1889
  row = rb_ary_new();
1704
1890
  }
1705
- goto st11;
1706
- tr36:
1891
+ goto st10;
1892
+ tr30:
1707
1893
  #line 1 "NONE"
1708
1894
  {te = p+1;}
1709
1895
  #line 41 "ext/fastcsv/fastcsv.rl"
@@ -1721,10 +1907,9 @@ tr36:
1721
1907
  ENCODE;
1722
1908
  }
1723
1909
  }
1724
- #line 117 "ext/fastcsv/fastcsv.rl"
1910
+ #line 119 "ext/fastcsv/fastcsv.rl"
1725
1911
  {
1726
1912
  mark_row_sep = p;
1727
- curline++;
1728
1913
 
1729
1914
  if (d->start == 0 || p == d->start) {
1730
1915
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -1741,10 +1926,10 @@ tr36:
1741
1926
  rb_yield(row);
1742
1927
  row = rb_ary_new();
1743
1928
  }
1744
- #line 166 "ext/fastcsv/fastcsv.rl"
1929
+ #line 169 "ext/fastcsv/fastcsv.rl"
1745
1930
  {act = 2;}
1746
- goto st11;
1747
- tr40:
1931
+ goto st10;
1932
+ tr34:
1748
1933
  #line 1 "NONE"
1749
1934
  {te = p+1;}
1750
1935
  #line 49 "ext/fastcsv/fastcsv.rl"
@@ -1767,12 +1952,11 @@ tr40:
1767
1952
  rb_ary_push(row, field);
1768
1953
  field = Qnil;
1769
1954
  }
1770
- #line 165 "ext/fastcsv/fastcsv.rl"
1955
+ #line 168 "ext/fastcsv/fastcsv.rl"
1771
1956
  {act = 1;}
1772
- #line 117 "ext/fastcsv/fastcsv.rl"
1957
+ #line 119 "ext/fastcsv/fastcsv.rl"
1773
1958
  {
1774
1959
  mark_row_sep = p;
1775
- curline++;
1776
1960
 
1777
1961
  if (d->start == 0 || p == d->start) {
1778
1962
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -1789,8 +1973,8 @@ tr40:
1789
1973
  rb_yield(row);
1790
1974
  row = rb_ary_new();
1791
1975
  }
1792
- goto st11;
1793
- tr48:
1976
+ goto st10;
1977
+ tr41:
1794
1978
  #line 1 "NONE"
1795
1979
  {te = p+1;}
1796
1980
  #line 100 "ext/fastcsv/fastcsv.rl"
@@ -1801,7 +1985,7 @@ tr48:
1801
1985
  if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
1802
1986
  FREE;
1803
1987
 
1804
- rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline - 1);
1988
+ rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline);
1805
1989
  }
1806
1990
  }
1807
1991
  else {
@@ -1809,17 +1993,18 @@ tr48:
1809
1993
  row_sep = ALLOC_N(char, len_row_sep);
1810
1994
  memcpy(row_sep, mark_row_sep, len_row_sep);
1811
1995
  }
1996
+
1997
+ curline++;
1812
1998
  }
1813
- #line 166 "ext/fastcsv/fastcsv.rl"
1999
+ #line 169 "ext/fastcsv/fastcsv.rl"
1814
2000
  {act = 2;}
1815
- goto st11;
1816
- tr51:
2001
+ goto st10;
2002
+ tr49:
1817
2003
  #line 1 "NONE"
1818
2004
  {te = p+1;}
1819
- #line 117 "ext/fastcsv/fastcsv.rl"
2005
+ #line 119 "ext/fastcsv/fastcsv.rl"
1820
2006
  {
1821
2007
  mark_row_sep = p;
1822
- curline++;
1823
2008
 
1824
2009
  if (d->start == 0 || p == d->start) {
1825
2010
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -1844,7 +2029,7 @@ tr51:
1844
2029
  if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
1845
2030
  FREE;
1846
2031
 
1847
- rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline - 1);
2032
+ rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline);
1848
2033
  }
1849
2034
  }
1850
2035
  else {
@@ -1852,10 +2037,12 @@ tr51:
1852
2037
  row_sep = ALLOC_N(char, len_row_sep);
1853
2038
  memcpy(row_sep, mark_row_sep, len_row_sep);
1854
2039
  }
2040
+
2041
+ curline++;
1855
2042
  }
1856
- #line 166 "ext/fastcsv/fastcsv.rl"
2043
+ #line 169 "ext/fastcsv/fastcsv.rl"
1857
2044
  {act = 2;}
1858
- goto st11;
2045
+ goto st10;
1859
2046
  tr57:
1860
2047
  #line 1 "NONE"
1861
2048
  {te = p+1;}
@@ -1864,12 +2051,11 @@ tr57:
1864
2051
  rb_ary_push(row, field);
1865
2052
  field = Qnil;
1866
2053
  }
1867
- #line 165 "ext/fastcsv/fastcsv.rl"
2054
+ #line 168 "ext/fastcsv/fastcsv.rl"
1868
2055
  {act = 1;}
1869
- #line 117 "ext/fastcsv/fastcsv.rl"
2056
+ #line 119 "ext/fastcsv/fastcsv.rl"
1870
2057
  {
1871
2058
  mark_row_sep = p;
1872
- curline++;
1873
2059
 
1874
2060
  if (d->start == 0 || p == d->start) {
1875
2061
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -1894,7 +2080,7 @@ tr57:
1894
2080
  if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
1895
2081
  FREE;
1896
2082
 
1897
- rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline - 1);
2083
+ rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline);
1898
2084
  }
1899
2085
  }
1900
2086
  else {
@@ -1902,36 +2088,34 @@ tr57:
1902
2088
  row_sep = ALLOC_N(char, len_row_sep);
1903
2089
  memcpy(row_sep, mark_row_sep, len_row_sep);
1904
2090
  }
2091
+
2092
+ curline++;
1905
2093
  }
1906
- goto st11;
1907
- st11:
2094
+ goto st10;
2095
+ st10:
1908
2096
  if ( ++p == pe )
1909
- goto _test_eof11;
1910
- case 11:
1911
- #line 1912 "ext/fastcsv/fastcsv.c"
2097
+ goto _test_eof10;
2098
+ case 10:
2099
+ #line 2100 "ext/fastcsv/fastcsv.c"
1912
2100
  _widec = (*p);
1913
2101
  _widec = (short)(128 + ((*p) - -128));
1914
2102
  if (
1915
- #line 155 "ext/fastcsv/fastcsv.rl"
2103
+ #line 156 "ext/fastcsv/fastcsv.rl"
1916
2104
  (*p) == quote_char ) _widec += 256;
1917
- switch( _widec ) {
1918
- case 256: goto tr43;
1919
- case 522: goto tr47;
1920
- case 525: goto tr47;
1921
- }
2105
+ if ( _widec == 256 )
2106
+ goto tr37;
1922
2107
  if ( _widec > 383 ) {
1923
2108
  if ( 384 <= _widec && _widec <= 639 )
1924
- goto tr46;
2109
+ goto tr40;
1925
2110
  } else if ( _widec >= 128 )
1926
- goto tr45;
2111
+ goto tr39;
1927
2112
  goto tr0;
1928
- tr18:
2113
+ tr17:
1929
2114
  #line 1 "NONE"
1930
2115
  {te = p+1;}
1931
- #line 117 "ext/fastcsv/fastcsv.rl"
2116
+ #line 119 "ext/fastcsv/fastcsv.rl"
1932
2117
  {
1933
2118
  mark_row_sep = p;
1934
- curline++;
1935
2119
 
1936
2120
  if (d->start == 0 || p == d->start) {
1937
2121
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -1948,10 +2132,10 @@ tr18:
1948
2132
  rb_yield(row);
1949
2133
  row = rb_ary_new();
1950
2134
  }
1951
- #line 166 "ext/fastcsv/fastcsv.rl"
2135
+ #line 169 "ext/fastcsv/fastcsv.rl"
1952
2136
  {act = 2;}
1953
- goto st12;
1954
- tr26:
2137
+ goto st11;
2138
+ tr25:
1955
2139
  #line 1 "NONE"
1956
2140
  {te = p+1;}
1957
2141
  #line 95 "ext/fastcsv/fastcsv.rl"
@@ -1959,12 +2143,11 @@ tr26:
1959
2143
  rb_ary_push(row, field);
1960
2144
  field = Qnil;
1961
2145
  }
1962
- #line 165 "ext/fastcsv/fastcsv.rl"
2146
+ #line 168 "ext/fastcsv/fastcsv.rl"
1963
2147
  {act = 1;}
1964
- #line 117 "ext/fastcsv/fastcsv.rl"
2148
+ #line 119 "ext/fastcsv/fastcsv.rl"
1965
2149
  {
1966
2150
  mark_row_sep = p;
1967
- curline++;
1968
2151
 
1969
2152
  if (d->start == 0 || p == d->start) {
1970
2153
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -1981,8 +2164,8 @@ tr26:
1981
2164
  rb_yield(row);
1982
2165
  row = rb_ary_new();
1983
2166
  }
1984
- goto st12;
1985
- tr37:
2167
+ goto st11;
2168
+ tr31:
1986
2169
  #line 1 "NONE"
1987
2170
  {te = p+1;}
1988
2171
  #line 41 "ext/fastcsv/fastcsv.rl"
@@ -2000,10 +2183,9 @@ tr37:
2000
2183
  ENCODE;
2001
2184
  }
2002
2185
  }
2003
- #line 117 "ext/fastcsv/fastcsv.rl"
2186
+ #line 119 "ext/fastcsv/fastcsv.rl"
2004
2187
  {
2005
2188
  mark_row_sep = p;
2006
- curline++;
2007
2189
 
2008
2190
  if (d->start == 0 || p == d->start) {
2009
2191
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -2020,10 +2202,10 @@ tr37:
2020
2202
  rb_yield(row);
2021
2203
  row = rb_ary_new();
2022
2204
  }
2023
- #line 166 "ext/fastcsv/fastcsv.rl"
2205
+ #line 169 "ext/fastcsv/fastcsv.rl"
2024
2206
  {act = 2;}
2025
- goto st12;
2026
- tr41:
2207
+ goto st11;
2208
+ tr35:
2027
2209
  #line 1 "NONE"
2028
2210
  {te = p+1;}
2029
2211
  #line 49 "ext/fastcsv/fastcsv.rl"
@@ -2046,12 +2228,11 @@ tr41:
2046
2228
  rb_ary_push(row, field);
2047
2229
  field = Qnil;
2048
2230
  }
2049
- #line 165 "ext/fastcsv/fastcsv.rl"
2231
+ #line 168 "ext/fastcsv/fastcsv.rl"
2050
2232
  {act = 1;}
2051
- #line 117 "ext/fastcsv/fastcsv.rl"
2233
+ #line 119 "ext/fastcsv/fastcsv.rl"
2052
2234
  {
2053
2235
  mark_row_sep = p;
2054
- curline++;
2055
2236
 
2056
2237
  if (d->start == 0 || p == d->start) {
2057
2238
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -2068,14 +2249,13 @@ tr41:
2068
2249
  rb_yield(row);
2069
2250
  row = rb_ary_new();
2070
2251
  }
2071
- goto st12;
2072
- tr52:
2252
+ goto st11;
2253
+ tr50:
2073
2254
  #line 1 "NONE"
2074
2255
  {te = p+1;}
2075
- #line 117 "ext/fastcsv/fastcsv.rl"
2256
+ #line 119 "ext/fastcsv/fastcsv.rl"
2076
2257
  {
2077
2258
  mark_row_sep = p;
2078
- curline++;
2079
2259
 
2080
2260
  if (d->start == 0 || p == d->start) {
2081
2261
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -2100,7 +2280,7 @@ tr52:
2100
2280
  if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
2101
2281
  FREE;
2102
2282
 
2103
- rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline - 1);
2283
+ rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline);
2104
2284
  }
2105
2285
  }
2106
2286
  else {
@@ -2108,10 +2288,12 @@ tr52:
2108
2288
  row_sep = ALLOC_N(char, len_row_sep);
2109
2289
  memcpy(row_sep, mark_row_sep, len_row_sep);
2110
2290
  }
2291
+
2292
+ curline++;
2111
2293
  }
2112
- #line 166 "ext/fastcsv/fastcsv.rl"
2294
+ #line 169 "ext/fastcsv/fastcsv.rl"
2113
2295
  {act = 2;}
2114
- goto st12;
2296
+ goto st11;
2115
2297
  tr58:
2116
2298
  #line 1 "NONE"
2117
2299
  {te = p+1;}
@@ -2120,12 +2302,11 @@ tr58:
2120
2302
  rb_ary_push(row, field);
2121
2303
  field = Qnil;
2122
2304
  }
2123
- #line 165 "ext/fastcsv/fastcsv.rl"
2305
+ #line 168 "ext/fastcsv/fastcsv.rl"
2124
2306
  {act = 1;}
2125
- #line 117 "ext/fastcsv/fastcsv.rl"
2307
+ #line 119 "ext/fastcsv/fastcsv.rl"
2126
2308
  {
2127
2309
  mark_row_sep = p;
2128
- curline++;
2129
2310
 
2130
2311
  if (d->start == 0 || p == d->start) {
2131
2312
  rb_ivar_set(self, s_row, rb_str_new2(""));
@@ -2150,7 +2331,7 @@ tr58:
2150
2331
  if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
2151
2332
  FREE;
2152
2333
 
2153
- rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline - 1);
2334
+ rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline);
2154
2335
  }
2155
2336
  }
2156
2337
  else {
@@ -2158,31 +2339,32 @@ tr58:
2158
2339
  row_sep = ALLOC_N(char, len_row_sep);
2159
2340
  memcpy(row_sep, mark_row_sep, len_row_sep);
2160
2341
  }
2342
+
2343
+ curline++;
2161
2344
  }
2162
- goto st12;
2163
- st12:
2345
+ goto st11;
2346
+ st11:
2164
2347
  if ( ++p == pe )
2165
- goto _test_eof12;
2166
- case 12:
2167
- #line 2168 "ext/fastcsv/fastcsv.c"
2348
+ goto _test_eof11;
2349
+ case 11:
2350
+ #line 2351 "ext/fastcsv/fastcsv.c"
2168
2351
  _widec = (*p);
2169
2352
  _widec = (short)(128 + ((*p) - -128));
2170
2353
  if (
2171
- #line 155 "ext/fastcsv/fastcsv.rl"
2354
+ #line 156 "ext/fastcsv/fastcsv.rl"
2172
2355
  (*p) == quote_char ) _widec += 256;
2173
2356
  switch( _widec ) {
2174
- case 256: goto tr43;
2175
- case 266: goto tr48;
2176
- case 522: goto tr49;
2177
- case 525: goto tr47;
2357
+ case 256: goto tr37;
2358
+ case 266: goto tr41;
2359
+ case 522: goto tr42;
2178
2360
  }
2179
2361
  if ( _widec > 383 ) {
2180
2362
  if ( 384 <= _widec && _widec <= 639 )
2181
- goto tr46;
2363
+ goto tr40;
2182
2364
  } else if ( _widec >= 128 )
2183
- goto tr45;
2365
+ goto tr39;
2184
2366
  goto tr0;
2185
- tr28:
2367
+ tr42:
2186
2368
  #line 1 "NONE"
2187
2369
  {te = p+1;}
2188
2370
  #line 60 "ext/fastcsv/fastcsv.rl"
@@ -2224,857 +2406,103 @@ tr28:
2224
2406
  {
2225
2407
  unclosed_line = 0;
2226
2408
  }
2227
- #line 117 "ext/fastcsv/fastcsv.rl"
2409
+ #line 100 "ext/fastcsv/fastcsv.rl"
2228
2410
  {
2229
- mark_row_sep = p;
2230
- curline++;
2411
+ d->start = p;
2231
2412
 
2232
- if (d->start == 0 || p == d->start) {
2233
- rb_ivar_set(self, s_row, rb_str_new2(""));
2234
- }
2235
- else if (p > d->start) {
2236
- rb_ivar_set(self, s_row, rb_str_new(d->start, p - d->start));
2237
- }
2413
+ if (len_row_sep) {
2414
+ if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
2415
+ FREE;
2238
2416
 
2239
- if (!NIL_P(field) || RARRAY_LEN(row)) { // same as new_field
2240
- rb_ary_push(row, field);
2241
- field = Qnil;
2417
+ rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline);
2418
+ }
2419
+ }
2420
+ else {
2421
+ len_row_sep = p - mark_row_sep;
2422
+ row_sep = ALLOC_N(char, len_row_sep);
2423
+ memcpy(row_sep, mark_row_sep, len_row_sep);
2242
2424
  }
2243
2425
 
2244
- rb_yield(row);
2245
- row = rb_ary_new();
2426
+ curline++;
2246
2427
  }
2247
- #line 166 "ext/fastcsv/fastcsv.rl"
2428
+ #line 169 "ext/fastcsv/fastcsv.rl"
2248
2429
  {act = 2;}
2249
- goto st13;
2250
- tr31:
2251
- #line 1 "NONE"
2252
- {te = p+1;}
2253
- #line 60 "ext/fastcsv/fastcsv.rl"
2254
- {
2255
- if (p == ts) {
2256
- field = rb_enc_str_new("", 0, encoding);
2257
- ENCODE;
2258
- }
2259
- // @note If we add an action on '""', we can skip some steps if no '""' is found.
2260
- else if (p > ts) {
2261
- // Operating on ts in-place produces odd behavior, FYI.
2262
- char *copy = ALLOC_N(char, p - ts);
2263
- memcpy(copy, ts, p - ts);
2264
-
2265
- char *reader = ts, *writer = copy;
2266
- int escaped = 0;
2267
-
2268
- while (p > reader) {
2269
- if (*reader == quote_char && !escaped) {
2270
- // Skip the escaping character.
2271
- escaped = 1;
2272
- }
2273
- else {
2274
- escaped = 0;
2275
- *writer++ = *reader;
2276
- }
2277
- reader++;
2278
- }
2279
-
2280
- field = rb_enc_str_new(copy, writer - copy, encoding);
2281
- ENCODE;
2282
-
2283
- if (copy != NULL) {
2284
- free(copy);
2285
- }
2286
- }
2287
- }
2288
- #line 45 "ext/fastcsv/fastcsv.rl"
2289
- {
2290
- unclosed_line = 0;
2291
- }
2292
- #line 95 "ext/fastcsv/fastcsv.rl"
2293
- {
2294
- rb_ary_push(row, field);
2295
- field = Qnil;
2296
- }
2297
- #line 165 "ext/fastcsv/fastcsv.rl"
2298
- {act = 1;}
2299
- #line 117 "ext/fastcsv/fastcsv.rl"
2300
- {
2301
- mark_row_sep = p;
2302
- curline++;
2303
-
2304
- if (d->start == 0 || p == d->start) {
2305
- rb_ivar_set(self, s_row, rb_str_new2(""));
2306
- }
2307
- else if (p > d->start) {
2308
- rb_ivar_set(self, s_row, rb_str_new(d->start, p - d->start));
2309
- }
2310
-
2311
- if (!NIL_P(field) || RARRAY_LEN(row)) { // same as new_field
2312
- rb_ary_push(row, field);
2313
- field = Qnil;
2314
- }
2315
-
2316
- rb_yield(row);
2317
- row = rb_ary_new();
2318
- }
2319
- goto st13;
2320
- tr49:
2321
- #line 1 "NONE"
2322
- {te = p+1;}
2323
- #line 60 "ext/fastcsv/fastcsv.rl"
2324
- {
2325
- if (p == ts) {
2326
- field = rb_enc_str_new("", 0, encoding);
2327
- ENCODE;
2328
- }
2329
- // @note If we add an action on '""', we can skip some steps if no '""' is found.
2330
- else if (p > ts) {
2331
- // Operating on ts in-place produces odd behavior, FYI.
2332
- char *copy = ALLOC_N(char, p - ts);
2333
- memcpy(copy, ts, p - ts);
2334
-
2335
- char *reader = ts, *writer = copy;
2336
- int escaped = 0;
2337
-
2338
- while (p > reader) {
2339
- if (*reader == quote_char && !escaped) {
2340
- // Skip the escaping character.
2341
- escaped = 1;
2342
- }
2343
- else {
2344
- escaped = 0;
2345
- *writer++ = *reader;
2346
- }
2347
- reader++;
2348
- }
2349
-
2350
- field = rb_enc_str_new(copy, writer - copy, encoding);
2351
- ENCODE;
2352
-
2353
- if (copy != NULL) {
2354
- free(copy);
2355
- }
2356
- }
2357
- }
2358
- #line 45 "ext/fastcsv/fastcsv.rl"
2359
- {
2360
- unclosed_line = 0;
2361
- }
2362
- #line 100 "ext/fastcsv/fastcsv.rl"
2363
- {
2364
- d->start = p;
2365
-
2366
- if (len_row_sep) {
2367
- if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
2368
- FREE;
2369
-
2370
- rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline - 1);
2371
- }
2372
- }
2373
- else {
2374
- len_row_sep = p - mark_row_sep;
2375
- row_sep = ALLOC_N(char, len_row_sep);
2376
- memcpy(row_sep, mark_row_sep, len_row_sep);
2377
- }
2378
- }
2379
- #line 166 "ext/fastcsv/fastcsv.rl"
2380
- {act = 2;}
2381
- goto st13;
2382
- tr54:
2383
- #line 1 "NONE"
2384
- {te = p+1;}
2385
- #line 60 "ext/fastcsv/fastcsv.rl"
2386
- {
2387
- if (p == ts) {
2388
- field = rb_enc_str_new("", 0, encoding);
2389
- ENCODE;
2390
- }
2391
- // @note If we add an action on '""', we can skip some steps if no '""' is found.
2392
- else if (p > ts) {
2393
- // Operating on ts in-place produces odd behavior, FYI.
2394
- char *copy = ALLOC_N(char, p - ts);
2395
- memcpy(copy, ts, p - ts);
2396
-
2397
- char *reader = ts, *writer = copy;
2398
- int escaped = 0;
2399
-
2400
- while (p > reader) {
2401
- if (*reader == quote_char && !escaped) {
2402
- // Skip the escaping character.
2403
- escaped = 1;
2404
- }
2405
- else {
2406
- escaped = 0;
2407
- *writer++ = *reader;
2408
- }
2409
- reader++;
2410
- }
2411
-
2412
- field = rb_enc_str_new(copy, writer - copy, encoding);
2413
- ENCODE;
2414
-
2415
- if (copy != NULL) {
2416
- free(copy);
2417
- }
2418
- }
2419
- }
2420
- #line 45 "ext/fastcsv/fastcsv.rl"
2421
- {
2422
- unclosed_line = 0;
2423
- }
2424
- #line 117 "ext/fastcsv/fastcsv.rl"
2425
- {
2426
- mark_row_sep = p;
2427
- curline++;
2428
-
2429
- if (d->start == 0 || p == d->start) {
2430
- rb_ivar_set(self, s_row, rb_str_new2(""));
2431
- }
2432
- else if (p > d->start) {
2433
- rb_ivar_set(self, s_row, rb_str_new(d->start, p - d->start));
2434
- }
2435
-
2436
- if (!NIL_P(field) || RARRAY_LEN(row)) { // same as new_field
2437
- rb_ary_push(row, field);
2438
- field = Qnil;
2439
- }
2440
-
2441
- rb_yield(row);
2442
- row = rb_ary_new();
2443
- }
2444
- #line 100 "ext/fastcsv/fastcsv.rl"
2445
- {
2446
- d->start = p;
2447
-
2448
- if (len_row_sep) {
2449
- if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
2450
- FREE;
2451
-
2452
- rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline - 1);
2453
- }
2454
- }
2455
- else {
2456
- len_row_sep = p - mark_row_sep;
2457
- row_sep = ALLOC_N(char, len_row_sep);
2458
- memcpy(row_sep, mark_row_sep, len_row_sep);
2459
- }
2460
- }
2461
- #line 166 "ext/fastcsv/fastcsv.rl"
2462
- {act = 2;}
2463
- goto st13;
2464
- tr61:
2465
- #line 1 "NONE"
2466
- {te = p+1;}
2467
- #line 60 "ext/fastcsv/fastcsv.rl"
2468
- {
2469
- if (p == ts) {
2470
- field = rb_enc_str_new("", 0, encoding);
2471
- ENCODE;
2472
- }
2473
- // @note If we add an action on '""', we can skip some steps if no '""' is found.
2474
- else if (p > ts) {
2475
- // Operating on ts in-place produces odd behavior, FYI.
2476
- char *copy = ALLOC_N(char, p - ts);
2477
- memcpy(copy, ts, p - ts);
2478
-
2479
- char *reader = ts, *writer = copy;
2480
- int escaped = 0;
2481
-
2482
- while (p > reader) {
2483
- if (*reader == quote_char && !escaped) {
2484
- // Skip the escaping character.
2485
- escaped = 1;
2486
- }
2487
- else {
2488
- escaped = 0;
2489
- *writer++ = *reader;
2490
- }
2491
- reader++;
2492
- }
2493
-
2494
- field = rb_enc_str_new(copy, writer - copy, encoding);
2495
- ENCODE;
2496
-
2497
- if (copy != NULL) {
2498
- free(copy);
2499
- }
2500
- }
2501
- }
2502
- #line 45 "ext/fastcsv/fastcsv.rl"
2503
- {
2504
- unclosed_line = 0;
2505
- }
2506
- #line 95 "ext/fastcsv/fastcsv.rl"
2507
- {
2508
- rb_ary_push(row, field);
2509
- field = Qnil;
2510
- }
2511
- #line 165 "ext/fastcsv/fastcsv.rl"
2512
- {act = 1;}
2513
- #line 117 "ext/fastcsv/fastcsv.rl"
2514
- {
2515
- mark_row_sep = p;
2516
- curline++;
2517
-
2518
- if (d->start == 0 || p == d->start) {
2519
- rb_ivar_set(self, s_row, rb_str_new2(""));
2520
- }
2521
- else if (p > d->start) {
2522
- rb_ivar_set(self, s_row, rb_str_new(d->start, p - d->start));
2523
- }
2524
-
2525
- if (!NIL_P(field) || RARRAY_LEN(row)) { // same as new_field
2526
- rb_ary_push(row, field);
2527
- field = Qnil;
2528
- }
2529
-
2530
- rb_yield(row);
2531
- row = rb_ary_new();
2532
- }
2533
- #line 100 "ext/fastcsv/fastcsv.rl"
2534
- {
2535
- d->start = p;
2536
-
2537
- if (len_row_sep) {
2538
- if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
2539
- FREE;
2540
-
2541
- rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline - 1);
2542
- }
2543
- }
2544
- else {
2545
- len_row_sep = p - mark_row_sep;
2546
- row_sep = ALLOC_N(char, len_row_sep);
2547
- memcpy(row_sep, mark_row_sep, len_row_sep);
2548
- }
2549
- }
2550
- goto st13;
2551
- st13:
2552
- if ( ++p == pe )
2553
- goto _test_eof13;
2554
- case 13:
2555
- #line 2556 "ext/fastcsv/fastcsv.c"
2556
- _widec = (*p);
2557
- _widec = (short)(1152 + ((*p) - -128));
2558
- if (
2559
- #line 155 "ext/fastcsv/fastcsv.rl"
2560
- (*p) == quote_char ) _widec += 256;
2561
- if (
2562
- #line 156 "ext/fastcsv/fastcsv.rl"
2563
- (*p) == col_sep ) _widec += 512;
2564
- switch( _widec ) {
2565
- case 1280: goto tr50;
2566
- case 1290: goto tr51;
2567
- case 1293: goto tr52;
2568
- case 1536: goto tr53;
2569
- case 1546: goto tr54;
2570
- case 1549: goto tr54;
2571
- case 1792: goto tr56;
2572
- case 1802: goto tr57;
2573
- case 1805: goto tr58;
2574
- case 2048: goto tr60;
2575
- case 2058: goto tr61;
2576
- case 2061: goto tr61;
2577
- }
2578
- if ( _widec < 1408 ) {
2579
- if ( 1152 <= _widec && _widec <= 1407 )
2580
- goto tr45;
2581
- } else if ( _widec > 1663 ) {
2582
- if ( _widec > 1919 ) {
2583
- if ( 1920 <= _widec && _widec <= 2175 )
2584
- goto tr59;
2585
- } else if ( _widec >= 1664 )
2586
- goto tr55;
2587
- } else
2588
- goto tr47;
2589
- goto tr0;
2590
- tr27:
2591
- #line 1 "NONE"
2592
- {te = p+1;}
2593
- #line 60 "ext/fastcsv/fastcsv.rl"
2594
- {
2595
- if (p == ts) {
2596
- field = rb_enc_str_new("", 0, encoding);
2597
- ENCODE;
2598
- }
2599
- // @note If we add an action on '""', we can skip some steps if no '""' is found.
2600
- else if (p > ts) {
2601
- // Operating on ts in-place produces odd behavior, FYI.
2602
- char *copy = ALLOC_N(char, p - ts);
2603
- memcpy(copy, ts, p - ts);
2604
-
2605
- char *reader = ts, *writer = copy;
2606
- int escaped = 0;
2607
-
2608
- while (p > reader) {
2609
- if (*reader == quote_char && !escaped) {
2610
- // Skip the escaping character.
2611
- escaped = 1;
2612
- }
2613
- else {
2614
- escaped = 0;
2615
- *writer++ = *reader;
2616
- }
2617
- reader++;
2618
- }
2619
-
2620
- field = rb_enc_str_new(copy, writer - copy, encoding);
2621
- ENCODE;
2622
-
2623
- if (copy != NULL) {
2624
- free(copy);
2625
- }
2626
- }
2627
- }
2628
- #line 45 "ext/fastcsv/fastcsv.rl"
2629
- {
2630
- unclosed_line = 0;
2631
- }
2632
- #line 137 "ext/fastcsv/fastcsv.rl"
2633
- {
2634
- if (d->start == 0 || p == d->start) { // same as new_row
2635
- rb_ivar_set(self, s_row, rb_str_new2(""));
2636
- }
2637
- else if (p > d->start) {
2638
- rb_ivar_set(self, s_row, rb_str_new(d->start, p - d->start));
2639
- }
2640
-
2641
- if (!NIL_P(field) || RARRAY_LEN(row)) {
2642
- rb_ary_push(row, field);
2643
- }
2644
-
2645
- if (RARRAY_LEN(row)) {
2646
- rb_yield(row);
2647
- }
2648
- }
2649
- #line 167 "ext/fastcsv/fastcsv.rl"
2650
- {act = 3;}
2651
- goto st14;
2652
- tr29:
2653
- #line 1 "NONE"
2654
- {te = p+1;}
2655
- #line 60 "ext/fastcsv/fastcsv.rl"
2656
- {
2657
- if (p == ts) {
2658
- field = rb_enc_str_new("", 0, encoding);
2659
- ENCODE;
2660
- }
2661
- // @note If we add an action on '""', we can skip some steps if no '""' is found.
2662
- else if (p > ts) {
2663
- // Operating on ts in-place produces odd behavior, FYI.
2664
- char *copy = ALLOC_N(char, p - ts);
2665
- memcpy(copy, ts, p - ts);
2666
-
2667
- char *reader = ts, *writer = copy;
2668
- int escaped = 0;
2669
-
2670
- while (p > reader) {
2671
- if (*reader == quote_char && !escaped) {
2672
- // Skip the escaping character.
2673
- escaped = 1;
2674
- }
2675
- else {
2676
- escaped = 0;
2677
- *writer++ = *reader;
2678
- }
2679
- reader++;
2680
- }
2681
-
2682
- field = rb_enc_str_new(copy, writer - copy, encoding);
2683
- ENCODE;
2684
-
2685
- if (copy != NULL) {
2686
- free(copy);
2687
- }
2688
- }
2689
- }
2690
- #line 45 "ext/fastcsv/fastcsv.rl"
2691
- {
2692
- unclosed_line = 0;
2693
- }
2694
- #line 95 "ext/fastcsv/fastcsv.rl"
2695
- {
2696
- rb_ary_push(row, field);
2697
- field = Qnil;
2698
- }
2699
- #line 165 "ext/fastcsv/fastcsv.rl"
2700
- {act = 1;}
2701
- goto st14;
2702
- tr30:
2703
- #line 1 "NONE"
2704
- {te = p+1;}
2705
- #line 60 "ext/fastcsv/fastcsv.rl"
2706
- {
2707
- if (p == ts) {
2708
- field = rb_enc_str_new("", 0, encoding);
2709
- ENCODE;
2710
- }
2711
- // @note If we add an action on '""', we can skip some steps if no '""' is found.
2712
- else if (p > ts) {
2713
- // Operating on ts in-place produces odd behavior, FYI.
2714
- char *copy = ALLOC_N(char, p - ts);
2715
- memcpy(copy, ts, p - ts);
2716
-
2717
- char *reader = ts, *writer = copy;
2718
- int escaped = 0;
2719
-
2720
- while (p > reader) {
2721
- if (*reader == quote_char && !escaped) {
2722
- // Skip the escaping character.
2723
- escaped = 1;
2724
- }
2725
- else {
2726
- escaped = 0;
2727
- *writer++ = *reader;
2728
- }
2729
- reader++;
2730
- }
2731
-
2732
- field = rb_enc_str_new(copy, writer - copy, encoding);
2733
- ENCODE;
2734
-
2735
- if (copy != NULL) {
2736
- free(copy);
2737
- }
2738
- }
2739
- }
2740
- #line 45 "ext/fastcsv/fastcsv.rl"
2741
- {
2742
- unclosed_line = 0;
2743
- }
2744
- #line 95 "ext/fastcsv/fastcsv.rl"
2745
- {
2746
- rb_ary_push(row, field);
2747
- field = Qnil;
2748
- }
2749
- #line 165 "ext/fastcsv/fastcsv.rl"
2750
- {act = 1;}
2751
- #line 137 "ext/fastcsv/fastcsv.rl"
2752
- {
2753
- if (d->start == 0 || p == d->start) { // same as new_row
2754
- rb_ivar_set(self, s_row, rb_str_new2(""));
2755
- }
2756
- else if (p > d->start) {
2757
- rb_ivar_set(self, s_row, rb_str_new(d->start, p - d->start));
2758
- }
2759
-
2760
- if (!NIL_P(field) || RARRAY_LEN(row)) {
2761
- rb_ary_push(row, field);
2762
- }
2763
-
2764
- if (RARRAY_LEN(row)) {
2765
- rb_yield(row);
2766
- }
2767
- }
2768
- goto st14;
2769
- tr53:
2770
- #line 1 "NONE"
2771
- {te = p+1;}
2772
- #line 60 "ext/fastcsv/fastcsv.rl"
2773
- {
2774
- if (p == ts) {
2775
- field = rb_enc_str_new("", 0, encoding);
2776
- ENCODE;
2777
- }
2778
- // @note If we add an action on '""', we can skip some steps if no '""' is found.
2779
- else if (p > ts) {
2780
- // Operating on ts in-place produces odd behavior, FYI.
2781
- char *copy = ALLOC_N(char, p - ts);
2782
- memcpy(copy, ts, p - ts);
2783
-
2784
- char *reader = ts, *writer = copy;
2785
- int escaped = 0;
2786
-
2787
- while (p > reader) {
2788
- if (*reader == quote_char && !escaped) {
2789
- // Skip the escaping character.
2790
- escaped = 1;
2791
- }
2792
- else {
2793
- escaped = 0;
2794
- *writer++ = *reader;
2795
- }
2796
- reader++;
2797
- }
2798
-
2799
- field = rb_enc_str_new(copy, writer - copy, encoding);
2800
- ENCODE;
2801
-
2802
- if (copy != NULL) {
2803
- free(copy);
2804
- }
2805
- }
2806
- }
2807
- #line 45 "ext/fastcsv/fastcsv.rl"
2808
- {
2809
- unclosed_line = 0;
2810
- }
2811
- #line 100 "ext/fastcsv/fastcsv.rl"
2812
- {
2813
- d->start = p;
2814
-
2815
- if (len_row_sep) {
2816
- if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
2817
- FREE;
2818
-
2819
- rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline - 1);
2820
- }
2821
- }
2822
- else {
2823
- len_row_sep = p - mark_row_sep;
2824
- row_sep = ALLOC_N(char, len_row_sep);
2825
- memcpy(row_sep, mark_row_sep, len_row_sep);
2826
- }
2827
- }
2828
- #line 137 "ext/fastcsv/fastcsv.rl"
2829
- {
2830
- if (d->start == 0 || p == d->start) { // same as new_row
2831
- rb_ivar_set(self, s_row, rb_str_new2(""));
2832
- }
2833
- else if (p > d->start) {
2834
- rb_ivar_set(self, s_row, rb_str_new(d->start, p - d->start));
2835
- }
2836
-
2837
- if (!NIL_P(field) || RARRAY_LEN(row)) {
2838
- rb_ary_push(row, field);
2839
- }
2840
-
2841
- if (RARRAY_LEN(row)) {
2842
- rb_yield(row);
2843
- }
2844
- }
2845
- #line 167 "ext/fastcsv/fastcsv.rl"
2846
- {act = 3;}
2847
- goto st14;
2848
- tr59:
2849
- #line 1 "NONE"
2850
- {te = p+1;}
2851
- #line 60 "ext/fastcsv/fastcsv.rl"
2852
- {
2853
- if (p == ts) {
2854
- field = rb_enc_str_new("", 0, encoding);
2855
- ENCODE;
2856
- }
2857
- // @note If we add an action on '""', we can skip some steps if no '""' is found.
2858
- else if (p > ts) {
2859
- // Operating on ts in-place produces odd behavior, FYI.
2860
- char *copy = ALLOC_N(char, p - ts);
2861
- memcpy(copy, ts, p - ts);
2862
-
2863
- char *reader = ts, *writer = copy;
2864
- int escaped = 0;
2865
-
2866
- while (p > reader) {
2867
- if (*reader == quote_char && !escaped) {
2868
- // Skip the escaping character.
2869
- escaped = 1;
2870
- }
2871
- else {
2872
- escaped = 0;
2873
- *writer++ = *reader;
2874
- }
2875
- reader++;
2876
- }
2877
-
2878
- field = rb_enc_str_new(copy, writer - copy, encoding);
2879
- ENCODE;
2880
-
2881
- if (copy != NULL) {
2882
- free(copy);
2883
- }
2884
- }
2885
- }
2886
- #line 45 "ext/fastcsv/fastcsv.rl"
2887
- {
2888
- unclosed_line = 0;
2889
- }
2890
- #line 95 "ext/fastcsv/fastcsv.rl"
2891
- {
2892
- rb_ary_push(row, field);
2893
- field = Qnil;
2894
- }
2895
- #line 165 "ext/fastcsv/fastcsv.rl"
2896
- {act = 1;}
2897
- #line 100 "ext/fastcsv/fastcsv.rl"
2898
- {
2899
- d->start = p;
2900
-
2901
- if (len_row_sep) {
2902
- if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
2903
- FREE;
2904
-
2905
- rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline - 1);
2906
- }
2907
- }
2908
- else {
2909
- len_row_sep = p - mark_row_sep;
2910
- row_sep = ALLOC_N(char, len_row_sep);
2911
- memcpy(row_sep, mark_row_sep, len_row_sep);
2912
- }
2913
- }
2914
- goto st14;
2915
- tr60:
2916
- #line 1 "NONE"
2917
- {te = p+1;}
2918
- #line 60 "ext/fastcsv/fastcsv.rl"
2919
- {
2920
- if (p == ts) {
2921
- field = rb_enc_str_new("", 0, encoding);
2922
- ENCODE;
2923
- }
2924
- // @note If we add an action on '""', we can skip some steps if no '""' is found.
2925
- else if (p > ts) {
2926
- // Operating on ts in-place produces odd behavior, FYI.
2927
- char *copy = ALLOC_N(char, p - ts);
2928
- memcpy(copy, ts, p - ts);
2929
-
2930
- char *reader = ts, *writer = copy;
2931
- int escaped = 0;
2932
-
2933
- while (p > reader) {
2934
- if (*reader == quote_char && !escaped) {
2935
- // Skip the escaping character.
2936
- escaped = 1;
2937
- }
2938
- else {
2939
- escaped = 0;
2940
- *writer++ = *reader;
2941
- }
2942
- reader++;
2943
- }
2944
-
2945
- field = rb_enc_str_new(copy, writer - copy, encoding);
2946
- ENCODE;
2947
-
2948
- if (copy != NULL) {
2949
- free(copy);
2950
- }
2951
- }
2952
- }
2953
- #line 45 "ext/fastcsv/fastcsv.rl"
2954
- {
2955
- unclosed_line = 0;
2956
- }
2957
- #line 95 "ext/fastcsv/fastcsv.rl"
2958
- {
2959
- rb_ary_push(row, field);
2960
- field = Qnil;
2961
- }
2962
- #line 165 "ext/fastcsv/fastcsv.rl"
2963
- {act = 1;}
2964
- #line 100 "ext/fastcsv/fastcsv.rl"
2965
- {
2966
- d->start = p;
2967
-
2968
- if (len_row_sep) {
2969
- if (p - mark_row_sep != len_row_sep || row_sep[0] != *mark_row_sep || (len_row_sep == 2 && row_sep[1] != *(mark_row_sep + 1))) {
2970
- FREE;
2971
-
2972
- rb_raise(eError, "Unquoted fields do not allow \\r or \\n (line %d).", curline - 1);
2973
- }
2974
- }
2975
- else {
2976
- len_row_sep = p - mark_row_sep;
2977
- row_sep = ALLOC_N(char, len_row_sep);
2978
- memcpy(row_sep, mark_row_sep, len_row_sep);
2979
- }
2980
- }
2981
- #line 137 "ext/fastcsv/fastcsv.rl"
2982
- {
2983
- if (d->start == 0 || p == d->start) { // same as new_row
2984
- rb_ivar_set(self, s_row, rb_str_new2(""));
2985
- }
2986
- else if (p > d->start) {
2987
- rb_ivar_set(self, s_row, rb_str_new(d->start, p - d->start));
2988
- }
2989
-
2990
- if (!NIL_P(field) || RARRAY_LEN(row)) {
2991
- rb_ary_push(row, field);
2992
- }
2993
-
2994
- if (RARRAY_LEN(row)) {
2995
- rb_yield(row);
2996
- }
2997
- }
2998
- goto st14;
2999
- st14:
2430
+ goto st12;
2431
+ st12:
3000
2432
  if ( ++p == pe )
3001
- goto _test_eof14;
3002
- case 14:
3003
- #line 3004 "ext/fastcsv/fastcsv.c"
2433
+ goto _test_eof12;
2434
+ case 12:
2435
+ #line 2436 "ext/fastcsv/fastcsv.c"
3004
2436
  _widec = (*p);
3005
2437
  _widec = (short)(1152 + ((*p) - -128));
3006
2438
  if (
3007
- #line 155 "ext/fastcsv/fastcsv.rl"
2439
+ #line 156 "ext/fastcsv/fastcsv.rl"
3008
2440
  (*p) == quote_char ) _widec += 256;
3009
2441
  if (
3010
- #line 156 "ext/fastcsv/fastcsv.rl"
2442
+ #line 157 "ext/fastcsv/fastcsv.rl"
3011
2443
  (*p) == col_sep ) _widec += 512;
3012
2444
  switch( _widec ) {
3013
- case 1280: goto tr13;
3014
- case 1290: goto tr17;
3015
- case 1293: goto tr18;
3016
- case 1536: goto tr27;
3017
- case 1546: goto tr28;
3018
- case 1549: goto tr28;
3019
- case 1792: goto tr20;
3020
- case 1802: goto tr25;
3021
- case 1805: goto tr26;
3022
- case 2048: goto tr30;
3023
- case 2058: goto tr31;
3024
- case 2061: goto tr31;
2445
+ case 1280: goto tr45;
2446
+ case 1290: goto tr46;
2447
+ case 1293: goto tr47;
2448
+ case 1536: goto tr48;
2449
+ case 1546: goto tr49;
2450
+ case 1549: goto tr50;
2451
+ case 1792: goto tr52;
2452
+ case 1802: goto tr53;
2453
+ case 1805: goto tr54;
2454
+ case 2048: goto tr56;
2455
+ case 2058: goto tr57;
2456
+ case 2061: goto tr58;
3025
2457
  }
3026
2458
  if ( _widec < 1408 ) {
3027
2459
  if ( 1152 <= _widec && _widec <= 1407 )
3028
- goto st2;
2460
+ goto tr43;
3029
2461
  } else if ( _widec > 1663 ) {
3030
2462
  if ( _widec > 1919 ) {
3031
2463
  if ( 1920 <= _widec && _widec <= 2175 )
3032
- goto tr29;
2464
+ goto tr55;
3033
2465
  } else if ( _widec >= 1664 )
3034
- goto tr23;
2466
+ goto tr51;
3035
2467
  } else
3036
- goto tr12;
3037
- goto tr0;
2468
+ goto tr39;
2469
+ goto tr44;
3038
2470
  }
3039
- _test_eof5: cs = 5; goto _test_eof;
2471
+ _test_eof4: cs = 4; goto _test_eof;
3040
2472
  _test_eof1: cs = 1; goto _test_eof;
2473
+ _test_eof5: cs = 5; goto _test_eof;
3041
2474
  _test_eof6: cs = 6; goto _test_eof;
3042
2475
  _test_eof7: cs = 7; goto _test_eof;
3043
2476
  _test_eof8: cs = 8; goto _test_eof;
3044
- _test_eof9: cs = 9; goto _test_eof;
3045
2477
  _test_eof2: cs = 2; goto _test_eof;
3046
2478
  _test_eof3: cs = 3; goto _test_eof;
2479
+ _test_eof9: cs = 9; goto _test_eof;
3047
2480
  _test_eof10: cs = 10; goto _test_eof;
3048
- _test_eof4: cs = 4; goto _test_eof;
3049
2481
  _test_eof11: cs = 11; goto _test_eof;
3050
2482
  _test_eof12: cs = 12; goto _test_eof;
3051
- _test_eof13: cs = 13; goto _test_eof;
3052
- _test_eof14: cs = 14; goto _test_eof;
3053
2483
 
3054
2484
  _test_eof: {}
3055
2485
  if ( p == eof )
3056
2486
  {
3057
2487
  switch ( cs ) {
3058
2488
  case 1: goto tr0;
3059
- case 6: goto tr42;
3060
- case 7: goto tr43;
3061
- case 8: goto tr43;
3062
- case 9: goto tr42;
2489
+ case 5: goto tr36;
2490
+ case 6: goto tr37;
2491
+ case 7: goto tr37;
2492
+ case 8: goto tr36;
3063
2493
  case 2: goto tr0;
3064
2494
  case 3: goto tr0;
3065
- case 10: goto tr0;
3066
- case 4: goto tr0;
3067
- case 11: goto tr43;
2495
+ case 9: goto tr0;
2496
+ case 10: goto tr37;
2497
+ case 11: goto tr37;
3068
2498
  case 12: goto tr43;
3069
- case 13: goto tr43;
3070
- case 14: goto tr0;
3071
2499
  }
3072
2500
  }
3073
2501
 
3074
2502
  _out: {}
3075
2503
  }
3076
2504
 
3077
- #line 444 "ext/fastcsv/fastcsv.rl"
2505
+ #line 447 "ext/fastcsv/fastcsv.rl"
3078
2506
 
3079
2507
  if (done && cs < raw_parse_first_final) {
3080
2508
  if (d->start == 0 || p == d->start) { // same as new_row
@@ -3100,6 +2528,13 @@ case 14:
3100
2528
  else if (io) {
3101
2529
  have = pe - ts;
3102
2530
  memmove(buf, ts, have);
2531
+ // @see https://github.com/hpricot/hpricot/blob/master/ext/hpricot_scan/hpricot_scan.rl#L92
2532
+ if (d->start > ts) {
2533
+ d->start = buf + (d->start - ts);
2534
+ }
2535
+ if (mark_row_sep >= ts) {
2536
+ mark_row_sep = buf + (mark_row_sep - ts);
2537
+ }
3103
2538
  te = buf + (te - ts);
3104
2539
  ts = buf;
3105
2540
  }