Skip to content

Commit

Permalink
csvparser/filterx: change parse_csv() "delimiters" arg to singular
Browse files Browse the repository at this point in the history
To match format_csv()

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
  • Loading branch information
bazsi committed Jun 7, 2024
1 parent 330d70d commit 530e4d9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions modules/csvparser/filterx-func-parse-csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,17 @@ _extract_opts(FilterXFunctionParseCSV *self, FilterXFunctionArgs *args, GError *
gboolean flag_err = FALSE;
gboolean flag_val = FALSE;

value = filterx_function_args_get_named_literal_string(args, FILTERX_FUNC_PARSE_CSV_ARG_NAME_DELIMITERS, &len, &exists);
value = filterx_function_args_get_named_literal_string(args, FILTERX_FUNC_PARSE_CSV_ARG_NAME_DELIMITER, &len, &exists);
if (exists)
{
if (len < 1)
{
error_str = FILTERX_FUNC_PARSE_CSV_ARG_NAME_DELIMITERS " can not be empty";
error_str = FILTERX_FUNC_PARSE_CSV_ARG_NAME_DELIMITER " can not be empty";
goto error;
}
if (!value)
{
error_str = FILTERX_FUNC_PARSE_CSV_ARG_NAME_DELIMITERS " must be a string literal";
error_str = FILTERX_FUNC_PARSE_CSV_ARG_NAME_DELIMITER " must be a string literal";
goto error;
}
csv_scanner_options_set_delimiters(&self->options, value);
Expand Down
4 changes: 2 additions & 2 deletions modules/csvparser/filterx-func-parse-csv.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
#include "filterx/expr-function.h"

#define FILTERX_FUNC_PARSE_CSV_ARG_NAME_COLUMNS "columns"
#define FILTERX_FUNC_PARSE_CSV_ARG_NAME_DELIMITERS "delimiters"
#define FILTERX_FUNC_PARSE_CSV_ARG_NAME_DELIMITER "delimiter"
#define FILTERX_FUNC_PARSE_CSV_ARG_NAME_DIALECT "dialect"
#define FILTERX_FUNC_PARSE_CSV_ARG_NAME_STRIP_WHITESPACES "strip_whitespaces"
#define FILTERX_FUNC_PARSE_CSV_ARG_NAME_GREEDY "greedy"
#define FILTERX_FUNC_PARSE_CSV_USAGE "Usage: parse_csv(msg_str [" \
FILTERX_FUNC_PARSE_CSV_ARG_NAME_COLUMNS"=json_array, " \
FILTERX_FUNC_PARSE_CSV_ARG_NAME_DELIMITERS"=string, " \
FILTERX_FUNC_PARSE_CSV_ARG_NAME_DELIMITER"=string, " \
FILTERX_FUNC_PARSE_CSV_ARG_NAME_DIALECT"=string, " \
FILTERX_FUNC_PARSE_CSV_ARG_NAME_STRIP_WHITESPACES"=boolean, " \
FILTERX_FUNC_PARSE_CSV_ARG_NAME_GREEDY"=boolean])"
Expand Down
6 changes: 3 additions & 3 deletions modules/csvparser/tests/test_filterx_func_parse_csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ Test(filterx_func_parse_csv, test_optional_argument_delimiters)
GList *args = NULL;
args = g_list_append(args, filterx_function_arg_new(NULL,
filterx_literal_new(filterx_string_new("foo bar+baz;tik|tak:toe", -1))));
args = g_list_append(args, filterx_function_arg_new(FILTERX_FUNC_PARSE_CSV_ARG_NAME_DELIMITERS,
args = g_list_append(args, filterx_function_arg_new(FILTERX_FUNC_PARSE_CSV_ARG_NAME_DELIMITER,
filterx_literal_new(filterx_string_new(" +;", -1))));

GError *err = NULL;
Expand Down Expand Up @@ -329,7 +329,7 @@ Test(filterx_func_parse_csv, test_optional_argument_flag_strip_whitespace)
GList *args = NULL;
args = g_list_append(args, filterx_function_arg_new(NULL,
filterx_literal_new(filterx_string_new(" foo , bar , baz , tik tak toe", -1))));
args = g_list_append(args, filterx_function_arg_new(FILTERX_FUNC_PARSE_CSV_ARG_NAME_DELIMITERS,
args = g_list_append(args, filterx_function_arg_new(FILTERX_FUNC_PARSE_CSV_ARG_NAME_DELIMITER,
filterx_literal_new(filterx_string_new(",",
-1)))); // delimiter
args = g_list_append(args, filterx_function_arg_new(FILTERX_FUNC_PARSE_CSV_ARG_NAME_STRIP_WHITESPACES,
Expand Down Expand Up @@ -362,7 +362,7 @@ Test(filterx_func_parse_csv, test_optional_argument_flag_not_to_strip_whitespace
GList *args = NULL;
args = g_list_append(args, filterx_function_arg_new(NULL,
filterx_literal_new(filterx_string_new(" foo , bar , baz , tik tak toe", -1))));
args = g_list_append(args, filterx_function_arg_new(FILTERX_FUNC_PARSE_CSV_ARG_NAME_DELIMITERS,
args = g_list_append(args, filterx_function_arg_new(FILTERX_FUNC_PARSE_CSV_ARG_NAME_DELIMITER,
filterx_literal_new(filterx_string_new(",",
-1)))); // delimiter
args = g_list_append(args, filterx_function_arg_new(FILTERX_FUNC_PARSE_CSV_ARG_NAME_STRIP_WHITESPACES,
Expand Down
4 changes: 2 additions & 2 deletions tests/light/functional_tests/filterx/test_filterx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ def test_parse_csv_optional_arg_delimiters(config, syslog_ng):
(file_true, file_false) = create_config(
config, """
custom_message = "foo bar,baz.tik;tak!toe";
$MSG = parse_csv(custom_message, delimiters=" ,.");
$MSG = parse_csv(custom_message, delimiter=" ,.");
""",
)
syslog_ng.start(config)
Expand Down Expand Up @@ -1466,7 +1466,7 @@ def test_parse_csv_optional_arg_strip_whitespace(config, syslog_ng):
(file_true, file_false) = create_config(
config, """
custom_message = " foo , bar , baz, tik, tak, toe ";
$MSG = parse_csv(custom_message, delimiters=",", strip_whitespace=true);
$MSG = parse_csv(custom_message, delimiter=",", strip_whitespace=true);
""",
)
syslog_ng.start(config)
Expand Down

0 comments on commit 530e4d9

Please sign in to comment.