1
1
/*
2
2
* liblognorm - a fast samples-based log normalization library
3
- * Copyright 2010-2018 by Rainer Gerhards and Adiscon GmbH.
3
+ * Copyright 2010-2021 by Rainer Gerhards and Adiscon GmbH.
4
4
*
5
5
* Modified by Pavel Levshin ([email protected] ) in 2013
6
6
*
@@ -1644,6 +1644,12 @@ PARSER_Parse(OpQuotedString)
1644
1644
}
1645
1645
1646
1646
1647
+
1648
+ struct data_QuotedString {
1649
+ int dashIsNull ;
1650
+ int quotesOptional ;
1651
+ int supportEscape ;
1652
+ };
1647
1653
/**
1648
1654
* Parse a quoted string. In this initial implementation, escaping of the quote
1649
1655
* char is not supported. A quoted string is one start starts with a double quote,
@@ -1653,6 +1659,7 @@ PARSER_Parse(OpQuotedString)
1653
1659
*/
1654
1660
PARSER_Parse (QuotedString )
1655
1661
const char * c ;
1662
+ struct data_QuotedString * const data = (struct data_QuotedString * ) pdata ;
1656
1663
size_t i ;
1657
1664
1658
1665
assert (npb -> str != NULL );
@@ -1668,8 +1675,12 @@ PARSER_Parse(QuotedString)
1668
1675
++ i ;
1669
1676
1670
1677
/* search end of string */
1671
- while (i < npb -> strLen && c [i ] != '"' )
1678
+ while (i < npb -> strLen && c [i ] != '"' ) {
1679
+ if (data -> supportEscape && c [i ] == '\\' && (i < npb -> strLen )) {
1680
+ i ++ ; /* next char is escaped */
1681
+ }
1672
1682
i ++ ;
1683
+ }
1673
1684
1674
1685
if (i == npb -> strLen || c [i ] != '"' )
1675
1686
goto done ;
@@ -1685,6 +1696,44 @@ PARSER_Parse(QuotedString)
1685
1696
return r ;
1686
1697
}
1687
1698
1699
+ PARSER_Construct (QuotedString )
1700
+ {
1701
+ int r = 0 ;
1702
+ struct data_QuotedString * data = (struct data_QuotedString * ) calloc (1 , sizeof (struct data_QuotedString ));
1703
+
1704
+ if (json == NULL )
1705
+ goto done ;
1706
+
1707
+ struct json_object_iterator it = json_object_iter_begin (json );
1708
+ struct json_object_iterator itEnd = json_object_iter_end (json );
1709
+ while (!json_object_iter_equal (& it , & itEnd )) {
1710
+ const char * key = json_object_iter_peek_name (& it );
1711
+ struct json_object * const val = json_object_iter_peek_value (& it );
1712
+ if (!strcasecmp (key , "option.quotesOptional" )) {
1713
+ data -> quotesOptional = json_object_get_boolean (val );
1714
+ } else if (!strcasecmp (key , "option.dashIsNull" )) {
1715
+ data -> dashIsNull = json_object_get_boolean (val );
1716
+ } else if (!strcasecmp (key , "option.supportEscape" )) {
1717
+ data -> supportEscape = json_object_get_boolean (val );
1718
+ } else {
1719
+ ln_errprintf (ctx , 0 , "invalid param for QuotedString: %s" ,
1720
+ json_object_to_json_string (val ));
1721
+ }
1722
+ json_object_iter_next (& it );
1723
+ }
1724
+
1725
+ done :
1726
+ * pdata = data ;
1727
+ if (r != 0 )
1728
+ free (data );
1729
+ return r ;
1730
+ }
1731
+ PARSER_Destruct (QuotedString )
1732
+ {
1733
+ free (pdata );
1734
+ }
1735
+
1736
+
1688
1737
1689
1738
/**
1690
1739
* Parse an ISO date, that is YYYY-MM-DD (exactly this format).
0 commit comments