syslog-ng source
csv-scanner.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2015 Balabit
3  * Copyright (c) 1998-2015 Balázs Scheidler
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * As an additional exemption you are allowed to compile & link against the
20  * OpenSSL libraries as published by the OpenSSL project. See the file
21  * COPYING for details.
22  *
23  */
24 
25 
26 #ifndef CSVSCANNER_H_INCLUDED
27 #define CSVSCANNER_H_INCLUDED
28 
29 #include "syslog-ng.h"
30 
31 typedef enum
32 {
38 
39 #define CSV_SCANNER_STRIP_WHITESPACE 0x0001
40 #define CSV_SCANNER_GREEDY 0x0002
41 
42 typedef struct _CSVScannerOptions
43 {
44  gchar *delimiters;
45  gchar *quotes_start;
46  gchar *quotes_end;
47  gchar *null_value;
51  guint32 flags;
53 
57 
59 void csv_scanner_options_set_flags(CSVScannerOptions *options, guint32 flags);
60 void csv_scanner_options_set_expected_columns(CSVScannerOptions *options, gint expected_columns);
61 void csv_scanner_options_set_delimiters(CSVScannerOptions *options, const gchar *delimiters);
62 void csv_scanner_options_set_string_delimiters(CSVScannerOptions *options, GList *string_delimiters);
63 void csv_scanner_options_set_quotes_start_and_end(CSVScannerOptions *options, const gchar *quotes_start,
64  const gchar *quotes_end);
65 void csv_scanner_options_set_quotes(CSVScannerOptions *options, const gchar *quotes);
66 void csv_scanner_options_set_quote_pairs(CSVScannerOptions *options, const gchar *quote_pairs);
67 void csv_scanner_options_set_null_value(CSVScannerOptions *options, const gchar *null_value);
68 
69 typedef struct
70 {
72  enum
73  {
79  } state;
80  const gchar *src;
82  GString *current_value;
84 } CSVScanner;
85 
87 const gchar *csv_scanner_get_current_value(CSVScanner *pstate);
89 gboolean csv_scanner_scan_next(CSVScanner *pstate);
92 
93 void csv_scanner_init(CSVScanner *pstate, CSVScannerOptions *options, const gchar *input);
94 void csv_scanner_deinit(CSVScanner *pstate);
95 
96 #endif
void csv_scanner_options_copy(CSVScannerOptions *dst, CSVScannerOptions *src)
Definition: csv-scanner.c:113
CSVScannerDialect
Definition: csv-scanner.h:32
@ CSV_SCANNER_ESCAPE_NONE
Definition: csv-scanner.h:33
@ CSV_SCANNER_ESCAPE_BACKSLASH_WITH_SEQUENCES
Definition: csv-scanner.h:35
@ CSV_SCANNER_ESCAPE_BACKSLASH
Definition: csv-scanner.h:34
@ CSV_SCANNER_ESCAPE_DOUBLE_CHAR
Definition: csv-scanner.h:36
gboolean csv_scanner_options_validate(CSVScannerOptions *options)
Definition: csv-scanner.c:135
const gchar * csv_scanner_get_current_value(CSVScanner *pstate)
Definition: csv-scanner.c:519
gint csv_scanner_get_current_column(CSVScanner *self)
Definition: csv-scanner.c:487
gint csv_scanner_get_current_value_len(CSVScanner *self)
Definition: csv-scanner.c:525
gboolean csv_scanner_is_scan_complete(CSVScanner *pstate)
Definition: csv-scanner.c:493
void csv_scanner_init(CSVScanner *pstate, CSVScannerOptions *options, const gchar *input)
Definition: csv-scanner.c:503
void csv_scanner_options_set_flags(CSVScannerOptions *options, guint32 flags)
Definition: csv-scanner.c:37
gboolean csv_scanner_scan_next(CSVScanner *pstate)
Definition: csv-scanner.c:456
void csv_scanner_options_set_null_value(CSVScannerOptions *options, const gchar *null_value)
Definition: csv-scanner.c:100
void csv_scanner_options_set_expected_columns(CSVScannerOptions *options, gint expected_columns)
Definition: csv-scanner.c:107
void csv_scanner_options_set_delimiters(CSVScannerOptions *options, const gchar *delimiters)
Definition: csv-scanner.c:49
gchar * csv_scanner_dup_current_value(CSVScanner *self)
Definition: csv-scanner.c:531
void csv_scanner_options_set_quotes(CSVScannerOptions *options, const gchar *quotes)
Definition: csv-scanner.c:73
void csv_scanner_options_set_quote_pairs(CSVScannerOptions *options, const gchar *quote_pairs)
Definition: csv-scanner.c:79
void csv_scanner_options_set_dialect(CSVScannerOptions *options, CSVScannerDialect dialect)
Definition: csv-scanner.c:43
void csv_scanner_deinit(CSVScanner *pstate)
Definition: csv-scanner.c:514
void csv_scanner_options_clean(CSVScannerOptions *options)
Definition: csv-scanner.c:125
void csv_scanner_options_set_string_delimiters(CSVScannerOptions *options, GList *string_delimiters)
Definition: csv-scanner.c:56
void csv_scanner_options_set_quotes_start_and_end(CSVScannerOptions *options, const gchar *quotes_start, const gchar *quotes_end)
Definition: csv-scanner.c:63
Definition: csv-scanner.h:43
gint expected_columns
Definition: csv-scanner.h:50
CSVScannerDialect dialect
Definition: csv-scanner.h:49
guint32 flags
Definition: csv-scanner.h:51
gchar * quotes_end
Definition: csv-scanner.h:46
gchar * delimiters
Definition: csv-scanner.h:44
gchar * quotes_start
Definition: csv-scanner.h:45
gchar * null_value
Definition: csv-scanner.h:47
GList * string_delimiters
Definition: csv-scanner.h:48
Definition: csv-scanner.h:70
GString * current_value
Definition: csv-scanner.h:82
CSVScannerOptions * options
Definition: csv-scanner.h:71
@ CSV_STATE_GREEDY_COLUMN
Definition: csv-scanner.h:76
@ CSV_STATE_FINISH
Definition: csv-scanner.h:78
@ CSV_STATE_INITIAL
Definition: csv-scanner.h:74
@ CSV_STATE_COLUMNS
Definition: csv-scanner.h:75
@ CSV_STATE_PARTIAL_INPUT
Definition: csv-scanner.h:77
const gchar * src
Definition: csv-scanner.h:80
gint current_column
Definition: csv-scanner.h:81
gchar current_quote
Definition: csv-scanner.h:83
struct @95 state