1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 #ifndef _GNM_STF_PARSE_H_
3 # define _GNM_STF_PARSE_H_
11 PARSE_TYPE_NOTSET
= 1 << 0,
12 PARSE_TYPE_CSV
= 1 << 1,
13 PARSE_TYPE_FIXED
= 1 << 2
19 TRIM_TYPE_LEFT
= 1 << 0,
20 TRIM_TYPE_RIGHT
= 1 << 1
24 StfParseType_t parsetype
; /* The type of import to do */
25 StfTrimType_t trim_spaces
; /* Trim spaces in fields? */
27 GSList
* terminator
; /* Line terminators */
30 struct _StfCompiledTerminator
{
32 } compiled_terminator
;
35 struct _StfSeparator
{
38 gboolean duplicates
; /* See two text separators as one? */
40 gunichar stringindicator
; /* String indicator */
41 gboolean indicator_2x_is_single
;/* 2 quote chars form a single non-terminating quote */
42 gboolean trim_seps
; /* Ignore initial seps. */
44 /* Fixed width related */
45 GArray
*splitpositions
; /* Positions where text will be split vertically */
47 gboolean
*col_autofit_array
; /* 0/1 array indicating */
48 /* which col widths to autofit */
49 gboolean
*col_import_array
; /* 0/1 array indicating */
50 /* which cols to import */
51 unsigned int col_import_array_len
;
53 GPtrArray
*formats
; /* Contains GOFormat *s */
54 GPtrArray
*formats_decimal
; /* Contains GString *s */
55 GPtrArray
*formats_thousand
; /* Contains GString *s */
56 GPtrArray
*formats_curr
; /* Contains GString *s */
58 gboolean cols_exceeded
; /* This is set to TRUE if */
59 /* we tried to import more than */
60 /* SHEET_MAX_COLS columns */
61 gboolean rows_exceeded
; /* Ditto rows. */
62 unsigned ref_count
; /* Boxed type */
65 /* CREATION/DESTRUCTION of stf options struct */
67 GType
stf_parse_options_get_type (void);
68 void stf_parse_options_free (StfParseOptions_t
*parseoptions
);
70 StfParseOptions_t
*stf_parse_options_guess (char const *data
);
71 StfParseOptions_t
*stf_parse_options_guess_csv (char const *data
);
72 void stf_parse_options_guess_formats (StfParseOptions_t
*po
,
75 /* MANIPULATION of stf options struct */
77 void stf_parse_options_set_type (StfParseOptions_t
*parseoptions
,
78 StfParseType_t
const parsetype
);
79 void stf_parse_options_clear_line_terminator (StfParseOptions_t
*parseoptions
);
80 void stf_parse_options_add_line_terminator (StfParseOptions_t
*parseoptions
,
81 char const *terminator
);
82 void stf_parse_options_set_trim_spaces (StfParseOptions_t
*parseoptions
,
83 StfTrimType_t
const trim_spaces
);
84 void stf_parse_options_csv_set_separators (StfParseOptions_t
*parseoptions
,
85 char const *character
, GSList
const *seps
);
86 void stf_parse_options_csv_set_stringindicator (StfParseOptions_t
*parseoptions
,
87 gunichar
const stringindicator
);
88 void stf_parse_options_csv_set_indicator_2x_is_single (StfParseOptions_t
*parseoptions
,
89 gboolean
const indic_2x
);
90 void stf_parse_options_csv_set_duplicates (StfParseOptions_t
*parseoptions
,
91 gboolean
const duplicates
);
92 void stf_parse_options_csv_set_trim_seps (StfParseOptions_t
*parseoptions
,
93 gboolean
const trim_seps
);
94 void stf_parse_options_fixed_splitpositions_clear (StfParseOptions_t
*parseoptions
);
95 void stf_parse_options_fixed_splitpositions_add (StfParseOptions_t
*parseoptions
,
97 void stf_parse_options_fixed_splitpositions_remove (StfParseOptions_t
*parseoptions
,
99 int stf_parse_options_fixed_splitpositions_count (StfParseOptions_t
*parseoptions
);
100 int stf_parse_options_fixed_splitpositions_nth (StfParseOptions_t
*parseoptions
, int n
);
102 /* USING the stf structs to actually do some parsing, these are the lower-level functions and utility functions */
104 GPtrArray
*stf_parse_general (StfParseOptions_t
*parseoptions
,
105 GStringChunk
*lines_chunk
,
107 char const *data_end
);
108 void stf_parse_general_free (GPtrArray
*lines
);
109 GPtrArray
*stf_parse_lines (StfParseOptions_t
*parseoptions
,
110 GStringChunk
*lines_chunk
,
113 gboolean with_lineno
);
115 void stf_parse_options_fixed_autodiscover (StfParseOptions_t
*parseoptions
,
117 char const *data_end
);
119 char const *stf_parse_find_line (StfParseOptions_t
*parseoptions
,
123 /* Higher level functions, can be used for directly parsing into an application specific data container */
124 gboolean
stf_parse_sheet (StfParseOptions_t
*parseoptions
,
125 char const *data
, char const *data_end
,
127 int start_col
, int start_row
);
129 GnmCellRegion
*stf_parse_region (StfParseOptions_t
*parseoptions
,
130 char const *data
, char const *data_end
,
135 #endif /* _GNM_STF_PARSE_H_ */