@@ -684,14 +684,19 @@ static int parser_buffer_bytes(parser_t *self, size_t nbytes) {
684
684
685
685
#define IS_WHITESPACE (c ) ((c == ' ' || c == '\t'))
686
686
687
- #define IS_TERMINATOR (c ) ((self->lineterminator == '\0' && \
688
- c == '\n') || c == self->lineterminator)
687
+ #define IS_TERMINATOR (c ) ((self->lineterminator == '\0' && c == '\n') || \
688
+ (self->lineterminator != '\0' && \
689
+ c == self->lineterminator))
689
690
690
691
#define IS_QUOTE (c ) ((c == self->quotechar && self->quoting != QUOTE_NONE))
691
692
692
693
// don't parse '\r' with a custom line terminator
693
694
#define IS_CARRIAGE (c ) ((self->lineterminator == '\0' && c == '\r'))
694
695
696
+ #define IS_COMMENT_CHAR (c ) ((self->commentchar != '\0' && c == self->commentchar))
697
+
698
+ #define IS_ESCAPE_CHAR (c ) ((self->escapechar != '\0' && c == self->escapechar))
699
+
695
700
#define IS_SKIPPABLE_SPACE (c ) ((!self->delim_whitespace && c == ' ' && \
696
701
self->skipinitialspace))
697
702
@@ -866,7 +871,7 @@ int tokenize_bytes(parser_t *self, size_t line_limit)
866
871
self -> state = EAT_CRNL ;
867
872
}
868
873
break ;
869
- } else if (c == self -> commentchar ) {
874
+ } else if (IS_COMMENT_CHAR ( c ) ) {
870
875
self -> state = EAT_LINE_COMMENT ;
871
876
break ;
872
877
} else if (IS_WHITESPACE (c )) {
@@ -899,7 +904,7 @@ int tokenize_bytes(parser_t *self, size_t line_limit)
899
904
} else if (IS_QUOTE (c )) {
900
905
// start quoted field
901
906
self -> state = IN_QUOTED_FIELD ;
902
- } else if (c == self -> escapechar ) {
907
+ } else if (IS_ESCAPE_CHAR ( c ) ) {
903
908
// possible escaped character
904
909
self -> state = ESCAPED_CHAR ;
905
910
} else if (IS_SKIPPABLE_SPACE (c )) {
@@ -912,7 +917,7 @@ int tokenize_bytes(parser_t *self, size_t line_limit)
912
917
// save empty field
913
918
END_FIELD ();
914
919
}
915
- } else if (c == self -> commentchar ) {
920
+ } else if (IS_COMMENT_CHAR ( c ) ) {
916
921
END_FIELD ();
917
922
self -> state = EAT_COMMENT ;
918
923
} else {
@@ -950,7 +955,7 @@ int tokenize_bytes(parser_t *self, size_t line_limit)
950
955
} else if (IS_CARRIAGE (c )) {
951
956
END_FIELD ();
952
957
self -> state = EAT_CRNL ;
953
- } else if (c == self -> escapechar ) {
958
+ } else if (IS_ESCAPE_CHAR ( c ) ) {
954
959
// possible escaped character
955
960
self -> state = ESCAPED_CHAR ;
956
961
} else if (IS_DELIMITER (c )) {
@@ -962,7 +967,7 @@ int tokenize_bytes(parser_t *self, size_t line_limit)
962
967
} else {
963
968
self -> state = START_FIELD ;
964
969
}
965
- } else if (c == self -> commentchar ) {
970
+ } else if (IS_COMMENT_CHAR ( c ) ) {
966
971
END_FIELD ();
967
972
self -> state = EAT_COMMENT ;
968
973
} else {
@@ -973,7 +978,7 @@ int tokenize_bytes(parser_t *self, size_t line_limit)
973
978
974
979
case IN_QUOTED_FIELD :
975
980
// in quoted field
976
- if (c == self -> escapechar ) {
981
+ if (IS_ESCAPE_CHAR ( c ) ) {
977
982
// possible escape character
978
983
self -> state = ESCAPE_IN_QUOTED_FIELD ;
979
984
} else if (IS_QUOTE (c )) {
0 commit comments