@@ -1646,7 +1646,7 @@ PARSER_Parse(OpQuotedString)
1646
1646
1647
1647
1648
1648
struct data_QuotedString {
1649
- int dashIsNull ;
1649
+ int dashIsEmpty ;
1650
1650
int quotesOptional ;
1651
1651
int supportEscape ;
1652
1652
};
@@ -1661,35 +1661,51 @@ PARSER_Parse(QuotedString)
1661
1661
const char * c ;
1662
1662
struct data_QuotedString * const data = (struct data_QuotedString * ) pdata ;
1663
1663
size_t i ;
1664
+ int hadQuote = 0 ;
1664
1665
1665
1666
assert (npb -> str != NULL );
1666
1667
assert (offs != NULL );
1667
1668
assert (parsed != NULL );
1668
1669
c = npb -> str ;
1669
1670
i = * offs ;
1670
- if (i + 2 > npb -> strLen )
1671
- goto done ; /* needs at least 2 characters */
1671
+ if (i + 1 > npb -> strLen )
1672
+ goto done ; /* needs at least 1 characters (with quotesQptional...) */
1672
1673
1673
- if (c [i ] != '"' )
1674
- goto done ;
1675
- ++ i ;
1674
+ if (c [i ] == '"' ) {
1675
+ hadQuote = 1 ;
1676
+ ++ i ;
1677
+ } else {
1678
+ if (!data -> quotesOptional ) {
1679
+ goto done ;
1680
+ }
1681
+ }
1676
1682
1683
+ fprintf (stderr , "start loop %zd, char %c\n" , i , c [i ]);
1677
1684
/* search end of string */
1678
- while (i < npb -> strLen && c [i ] != '"' ) {
1685
+ while (i < npb -> strLen &&
1686
+ ( (hadQuote && c [i ] != '"' ) || (!hadQuote && c [i ] != ' ' ) )
1687
+ ) {
1688
+ fprintf (stderr , "in loop %zd, char %c\n" , i , c [i ]);
1679
1689
if (data -> supportEscape && c [i ] == '\\' && (i < npb -> strLen )) {
1680
1690
i ++ ; /* next char is escaped */
1681
1691
}
1682
1692
i ++ ;
1683
1693
}
1684
1694
1685
- if (i == npb -> strLen || c [i ] != '"' )
1695
+ if (hadQuote && ( i == npb -> strLen || c [i ] != '"' ) )
1686
1696
goto done ;
1687
1697
1688
1698
/* success, persist */
1689
- * parsed = i + 1 - * offs ; /* "eat" terminal double quote */
1699
+ const size_t charsFound = i - * offs + (hadQuote ? 1 : 0 );
1700
+ fprintf (stderr , "charsFound %zd, i %zd, offs %zd\n" , charsFound , i , * offs );
1701
+ * parsed = charsFound ; /* "eat" terminal double quote */
1690
1702
/* create JSON value to save quoted string contents */
1691
1703
if (value != NULL ) {
1692
- * value = json_object_new_string_len (npb -> str + (* offs ), * parsed );
1704
+ if (charsFound == 3 && data -> dashIsEmpty && !strncmp (npb -> str + (* offs ), "\"-\"" , 3 )) {
1705
+ * value = json_object_new_string_len ("" , 0 );
1706
+ } else {
1707
+ * value = json_object_new_string_len (npb -> str + (* offs ), * parsed );
1708
+ }
1693
1709
}
1694
1710
r = 0 ; /* success */
1695
1711
done :
@@ -1711,8 +1727,8 @@ PARSER_Construct(QuotedString)
1711
1727
struct json_object * const val = json_object_iter_peek_value (& it );
1712
1728
if (!strcasecmp (key , "option.quotesOptional" )) {
1713
1729
data -> quotesOptional = json_object_get_boolean (val );
1714
- } else if (!strcasecmp (key , "option.dashIsNull " )) {
1715
- data -> dashIsNull = json_object_get_boolean (val );
1730
+ } else if (!strcasecmp (key , "option.dashIsEmpty " )) {
1731
+ data -> dashIsEmpty = json_object_get_boolean (val );
1716
1732
} else if (!strcasecmp (key , "option.supportEscape" )) {
1717
1733
data -> supportEscape = json_object_get_boolean (val );
1718
1734
} else {
0 commit comments