-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new parameters for quoted-string parser
- Loading branch information
Showing
3 changed files
with
55 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* liblognorm - a fast samples-based log normalization library | ||
* Copyright 2010-2018 by Rainer Gerhards and Adiscon GmbH. | ||
* Copyright 2010-2021 by Rainer Gerhards and Adiscon GmbH. | ||
* | ||
* Modified by Pavel Levshin ([email protected]) in 2013 | ||
* | ||
|
@@ -1644,6 +1644,12 @@ PARSER_Parse(OpQuotedString) | |
} | ||
|
||
|
||
|
||
struct data_QuotedString { | ||
int dashIsNull; | ||
int quotesOptional; | ||
int supportEscape; | ||
}; | ||
/** | ||
* Parse a quoted string. In this initial implementation, escaping of the quote | ||
* char is not supported. A quoted string is one start starts with a double quote, | ||
|
@@ -1653,6 +1659,7 @@ PARSER_Parse(OpQuotedString) | |
*/ | ||
PARSER_Parse(QuotedString) | ||
const char *c; | ||
struct data_QuotedString *const data = (struct data_QuotedString*) pdata; | ||
size_t i; | ||
|
||
assert(npb->str != NULL); | ||
|
@@ -1668,8 +1675,12 @@ PARSER_Parse(QuotedString) | |
++i; | ||
|
||
/* search end of string */ | ||
while(i < npb->strLen && c[i] != '"') | ||
while(i < npb->strLen && c[i] != '"') { | ||
if(data->supportEscape && c[i] == '\\' && (i < npb->strLen)) { | ||
i++; /* next char is escaped */ | ||
} | ||
i++; | ||
} | ||
|
||
if(i == npb->strLen || c[i] != '"') | ||
goto done; | ||
|
@@ -1685,6 +1696,44 @@ PARSER_Parse(QuotedString) | |
return r; | ||
} | ||
|
||
PARSER_Construct(QuotedString) | ||
{ | ||
int r = 0; | ||
struct data_QuotedString *data = (struct data_QuotedString*) calloc(1, sizeof(struct data_QuotedString)); | ||
|
||
if(json == NULL) | ||
goto done; | ||
|
||
struct json_object_iterator it = json_object_iter_begin(json); | ||
struct json_object_iterator itEnd = json_object_iter_end(json); | ||
while (!json_object_iter_equal(&it, &itEnd)) { | ||
const char *key = json_object_iter_peek_name(&it); | ||
struct json_object *const val = json_object_iter_peek_value(&it); | ||
if(!strcasecmp(key, "option.quotesOptional")) { | ||
data->quotesOptional = json_object_get_boolean(val); | ||
} else if(!strcasecmp(key, "option.dashIsNull")) { | ||
data->dashIsNull = json_object_get_boolean(val); | ||
} else if(!strcasecmp(key, "option.supportEscape")) { | ||
data->supportEscape = json_object_get_boolean(val); | ||
} else { | ||
ln_errprintf(ctx, 0, "invalid param for QuotedString: %s", | ||
json_object_to_json_string(val)); | ||
} | ||
json_object_iter_next(&it); | ||
} | ||
|
||
done: | ||
*pdata = data; | ||
if(r != 0) | ||
free(data); | ||
return r; | ||
} | ||
PARSER_Destruct(QuotedString) | ||
{ | ||
free(pdata); | ||
} | ||
|
||
|
||
|
||
/** | ||
* Parse an ISO date, that is YYYY-MM-DD (exactly this format). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* liblognorm - a fast samples-based log normalization library | ||
* Copyright 2010-2015 by Rainer Gerhards and Adiscon GmbH. | ||
* Copyright 2010-2021 by Rainer Gerhards and Adiscon GmbH. | ||
* | ||
* Modified by Pavel Levshin ([email protected]) in 2013 | ||
* | ||
|
@@ -63,7 +63,7 @@ PARSERDEF(Repeat); | |
PARSERDEF(String); | ||
PARSERDEF_NO_DATA(Rest); | ||
PARSERDEF_NO_DATA(OpQuotedString); | ||
PARSERDEF_NO_DATA(QuotedString); | ||
PARSERDEF(QuotedString); | ||
PARSERDEF_NO_DATA(ISODate); | ||
PARSERDEF_NO_DATA(Time12hr); | ||
PARSERDEF_NO_DATA(Time24hr); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters