struct string_set *strings;
};
+#define LOAD_TEXT_FILE_REMOVE_QUOTES 0x00000001
+
extern int
do_load_text_file(const tchar *path, tchar *buf, size_t buflen, tchar **buf_ret,
const struct text_file_section *pos_sections,
- int num_pos_sections, line_mangle_t mangle_line);
+ int num_pos_sections, int flags,
+ line_mangle_t mangle_line);
static inline int
load_text_file(const tchar *path, tchar **buf_ret,
int num_pos_sections, line_mangle_t mangle_line)
{
return do_load_text_file(path, NULL, 0, buf_ret,
- pos_sections, num_pos_sections, mangle_line);
+ pos_sections, num_pos_sections,
+ LOAD_TEXT_FILE_REMOVE_QUOTES, mangle_line);
}
static inline int
int num_pos_sections, line_mangle_t mangle_line)
{
return do_load_text_file(NULL, buf, buflen, &buf,
- pos_sections, num_pos_sections, mangle_line);
+ pos_sections, num_pos_sections,
+ LOAD_TEXT_FILE_REMOVE_QUOTES, mangle_line);
}
#endif /* _WIMLIB_TEXTFILE_H_ */
static int
mangle_pat(tchar *pat, const tchar *path, unsigned long line_no)
{
- /* Remove quotes */
- if (pat[0] == T('"') || pat[0] == T('\'')) {
- tchar quote = pat[0];
- tchar *last = pat + tstrlen(pat) - 1;
- if (last > pat && *last == quote) {
- tmemmove(pat, pat + 1, last - (pat + 1));
- *(last - 1) = T('\0');
- }
- }
-
if (!is_any_path_separator(pat[0]) &&
pat[0] != T('\0') && pat[1] == T(':'))
{
};
ret = do_load_text_file(config_file, buf, buflen, &buf,
- sections, ARRAY_LEN(sections), mangle_pat);
+ sections, ARRAY_LEN(sections),
+ LOAD_TEXT_FILE_REMOVE_QUOTES, mangle_pat);
if (ret)
return ret;
static int
parse_text_file(const tchar *path, tchar *buf, size_t buflen,
const struct text_file_section *pos_sections,
- int num_pos_sections, line_mangle_t mangle_line)
+ int num_pos_sections, int flags, line_mangle_t mangle_line)
{
int current_section = NOT_IN_SECTION;
bool have_named_sections = false;
continue;
}
+ if (flags & LOAD_TEXT_FILE_REMOVE_QUOTES) {
+ if (line_begin[0] == T('"') || line_begin[0] == T('\'')) {
+ tchar quote = line_begin[0];
+ if (line_len >= 2 &&
+ line_begin[line_len - 1] == quote)
+ {
+ line_begin++;
+ line_len -= 2;
+ line_begin[line_len] = T('\0');
+ }
+ }
+ }
+
if (mangle_line) {
ret = (*mangle_line)(line_begin, path, line_no);
if (ret)
* not in any section.
* @num_pos_sections
* Length of @pos_sections array.
+ * @flags
+ * LOAD_TEXT_FILE_REMOVE_QUOTES or 0.
* @mangle_line
* Optional callback to modify each line being read.
*
tchar **buf_ret,
const struct text_file_section *pos_sections,
int num_pos_sections,
+ int flags,
line_mangle_t mangle_line)
{
int ret;
}
ret = parse_text_file(path, buf, buflen, pos_sections,
- num_pos_sections, mangle_line);
+ num_pos_sections, flags, mangle_line);
if (ret) {
for (int i = 0; i < num_pos_sections; i++)
FREE(pos_sections[i].strings->strings);