summaryrefslogtreecommitdiffstats
path: root/include/orcus/csv_parser_base.hpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:48:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:48:59 +0000
commitc484829272cd13a738e35412498e12f2c9a194ac (patch)
treea1f5ec09629ee895bd3963fa8820b45f2f4c574b /include/orcus/csv_parser_base.hpp
parentInitial commit. (diff)
downloadliborcus-upstream.tar.xz
liborcus-upstream.zip
Adding upstream version 0.19.2.upstream/0.19.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'include/orcus/csv_parser_base.hpp')
-rw-r--r--include/orcus/csv_parser_base.hpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/include/orcus/csv_parser_base.hpp b/include/orcus/csv_parser_base.hpp
new file mode 100644
index 0000000..506d4e5
--- /dev/null
+++ b/include/orcus/csv_parser_base.hpp
@@ -0,0 +1,80 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef CSV_PARSER_BASE_HPP
+#define CSV_PARSER_BASE_HPP
+
+#include "env.hpp"
+#include "cell_buffer.hpp"
+#include "parser_global.hpp"
+#include "parser_base.hpp"
+
+#include <cstdlib>
+#include <cstring>
+#include <exception>
+#include <string>
+#include <cassert>
+#include <sstream>
+
+#define ORCUS_DEBUG_CSV 0
+
+#if ORCUS_DEBUG_CSV
+#include <iostream>
+using std::cout;
+using std::endl;
+#endif
+
+namespace orcus { namespace csv {
+
+/**
+ * Run-time configuration object for csv_parser.
+ */
+struct ORCUS_PSR_DLLPUBLIC parser_config
+{
+ /**
+ * One or more characters that serve as cell boundaries.
+ */
+ std::string delimiters;
+
+ /**
+ * A single character used as a text quote value.
+ */
+ char text_qualifier;
+
+ /**
+ * When true, the value of each cell gets trimmed i.e. any leading or
+ * trailing white spaces will get ignored.
+ */
+ bool trim_cell_value:1;
+
+ parser_config();
+};
+
+class ORCUS_PSR_DLLPUBLIC parser_base : public ::orcus::parser_base
+{
+protected:
+ const csv::parser_config& m_config;
+ cell_buffer m_cell_buf;
+
+protected:
+ parser_base(std::string_view content, const parser_config& config);
+
+ /**
+ * This is different from the global 'is_blank' in that it doesn't treat
+ * linefeed and carriage return characters as non-blanks.
+ */
+ bool is_blank(char c) const;
+ bool is_delim(char c) const;
+ bool is_text_qualifier(char c) const;
+
+ void skip_blanks();
+};
+
+}}
+
+#endif
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */