1 #ifndef _GNM_STF_PARSE_H_
2 # define _GNM_STF_PARSE_H_
10 PARSE_TYPE_NOTSET
= 1 << 0,
11 PARSE_TYPE_CSV
= 1 << 1,
12 PARSE_TYPE_FIXED
= 1 << 2
18 TRIM_TYPE_LEFT
= 1 << 0,
19 TRIM_TYPE_RIGHT
= 1 << 1
23 StfParseType_t parsetype
; /* The type of import to do */
24 StfTrimType_t trim_spaces
; /* Trim spaces in fields? */
26 GSList
* terminator
; /* Line terminators */
29 struct _StfCompiledTerminator
{
31 } compiled_terminator
;
34 struct _StfSeparator
{
37 gboolean duplicates
; /* See two text separators as one? */
39 gunichar stringindicator
; /* String indicator */
40 gboolean indicator_2x_is_single
;/* 2 quote chars form a single non-terminating quote */
41 gboolean trim_seps
; /* Ignore initial seps. */
43 /* Fixed width related */
44 GArray
*splitpositions
; /* Positions where text will be split vertically */
46 gboolean
*col_autofit_array
; /* 0/1 array indicating */
47 /* which col widths to autofit */
48 gboolean
*col_import_array
; /* 0/1 array indicating */
49 /* which cols to import */
50 unsigned int col_import_array_len
;
52 GPtrArray
*formats
; /* Contains GOFormat *s */
53 GPtrArray
*formats_decimal
; /* Contains GString *s */
54 GPtrArray
*formats_thousand
; /* Contains GString *s */
55 GPtrArray
*formats_curr
; /* Contains GString *s */
57 gboolean cols_exceeded
; /* This is set to TRUE if */
58 /* we tried to import more than */
59 /* SHEET_MAX_COLS columns */
60 gboolean rows_exceeded
; /* Ditto rows. */
61 unsigned ref_count
; /* Boxed type */
64 /* CREATION/DESTRUCTION of stf options struct */
66 GType
stf_parse_options_get_type (void);
67 void stf_parse_options_free (StfParseOptions_t
*parseoptions
);
69 StfParseOptions_t
*stf_parse_options_guess (char const *data
);
70 StfParseOptions_t
*stf_parse_options_guess_csv (char const *data
);
71 void stf_parse_options_guess_formats (StfParseOptions_t
*po
,
74 /* MANIPULATION of stf options struct */
76 void stf_parse_options_set_type (StfParseOptions_t
*parseoptions
,
77 StfParseType_t
const parsetype
);
78 void stf_parse_options_clear_line_terminator (StfParseOptions_t
*parseoptions
);
79 void stf_parse_options_add_line_terminator (StfParseOptions_t
*parseoptions
,
80 char const *terminator
);
81 void stf_parse_options_set_trim_spaces (StfParseOptions_t
*parseoptions
,
82 StfTrimType_t
const trim_spaces
);
83 void stf_parse_options_csv_set_separators (StfParseOptions_t
*parseoptions
,
84 char const *character
, GSList
const *seps
);
85 void stf_parse_options_csv_set_stringindicator (StfParseOptions_t
*parseoptions
,
86 gunichar
const stringindicator
);
87 void stf_parse_options_csv_set_indicator_2x_is_single (StfParseOptions_t
*parseoptions
,
88 gboolean
const indic_2x
);
89 void stf_parse_options_csv_set_duplicates (StfParseOptions_t
*parseoptions
,
90 gboolean
const duplicates
);
91 void stf_parse_options_csv_set_trim_seps (StfParseOptions_t
*parseoptions
,
92 gboolean
const trim_seps
);
93 void stf_parse_options_fixed_splitpositions_clear (StfParseOptions_t
*parseoptions
);
94 void stf_parse_options_fixed_splitpositions_add (StfParseOptions_t
*parseoptions
,
96 void stf_parse_options_fixed_splitpositions_remove (StfParseOptions_t
*parseoptions
,
98 int stf_parse_options_fixed_splitpositions_count (StfParseOptions_t
*parseoptions
);
99 int stf_parse_options_fixed_splitpositions_nth (StfParseOptions_t
*parseoptions
, int n
);
101 /* USING the stf structs to actually do some parsing, these are the lower-level functions and utility functions */
103 GPtrArray
*stf_parse_general (StfParseOptions_t
*parseoptions
,
104 GStringChunk
*lines_chunk
,
106 char const *data_end
);
107 void stf_parse_general_free (GPtrArray
*lines
);
108 GPtrArray
*stf_parse_lines (StfParseOptions_t
*parseoptions
,
109 GStringChunk
*lines_chunk
,
112 gboolean with_lineno
);
114 void stf_parse_options_fixed_autodiscover (StfParseOptions_t
*parseoptions
,
116 char const *data_end
);
118 char const *stf_parse_find_line (StfParseOptions_t
*parseoptions
,
122 /* Higher level functions, can be used for directly parsing into an application specific data container */
123 gboolean
stf_parse_sheet (StfParseOptions_t
*parseoptions
,
124 char const *data
, char const *data_end
,
126 int start_col
, int start_row
);
128 GnmCellRegion
*stf_parse_region (StfParseOptions_t
*parseoptions
,
129 char const *data
, char const *data_end
,
134 #endif /* _GNM_STF_PARSE_H_ */