From 9f935268844351be909ca3dcacc6563b1a90adc9 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Mon, 16 Dec 2019 22:41:17 +0200 Subject: [PATCH] move parser/utils to utils, Mux->Mu Move the parser utils to utils/ and rename the Mux namespace into Mu. --- lib/Makefile.am | 2 +- lib/mu-contacts.cc | 6 +-- lib/mu-query.cc | 22 +++++----- lib/mu-store.cc | 22 +++++----- lib/parser/Makefile.am | 46 ++++++++++++-------- lib/parser/data.hh | 6 +-- lib/parser/dummy-processor.hh | 30 ------------- lib/parser/parse.cc | 4 +- lib/parser/parser.cc | 50 +++++++++++----------- lib/parser/parser.hh | 4 +- lib/parser/proc-iface.hh | 4 +- lib/parser/test-parser.cc | 2 +- lib/parser/test-tokenizer.cc | 4 +- lib/parser/tokenize.cc | 2 +- lib/parser/tokenizer.cc | 12 +++--- lib/parser/tokenizer.hh | 4 +- lib/parser/tree.hh | 10 ++++- lib/parser/xapian.cc | 10 ++--- lib/parser/xapian.hh | 6 +-- lib/utils/Makefile.am | 11 ++++- lib/{parser/utils.cc => utils/mu-utils.cc} | 26 +++++------ lib/{parser/utils.hh => utils/mu-utils.hh} | 28 ++++++++---- lib/{parser => utils}/test-utils.cc | 10 +++-- mu/Makefile.am | 1 - 24 files changed, 165 insertions(+), 157 deletions(-) delete mode 100644 lib/parser/dummy-processor.hh rename lib/{parser/utils.cc => utils/mu-utils.cc} (95%) rename lib/{parser/utils.hh => utils/mu-utils.hh} (86%) rename lib/{parser => utils}/test-utils.cc (95%) diff --git a/lib/Makefile.am b/lib/Makefile.am index d80fbd88..a1aee16a 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -109,7 +109,7 @@ libmu_la_LIBADD= \ $(GUILE_LIBS) \ $(JSON_GLIB_LIBS) \ ${builddir}/utils/libmu-utils.la \ - ${builddir}/parser/libmuxparser.la + ${builddir}/parser/libmu-parser.la libmu_la_LDFLAGS= \ $(ASAN_LDFLAGS) diff --git a/lib/mu-contacts.cc b/lib/mu-contacts.cc index 740bf6a6..e5bb21f6 100644 --- a/lib/mu-contacts.cc +++ b/lib/mu-contacts.cc @@ -26,7 +26,7 @@ #include #include -#include +#include #include using namespace Mu; @@ -117,7 +117,7 @@ Contacts::Private::deserialize(const std::string& serialized) const while (getline (ss, line)) { - const auto parts = Mux::split (line, Separator); + const auto parts = Mu::split (line, Separator); if (G_UNLIKELY(parts.size() != 6)) { g_warning ("error: '%s'", line.c_str()); continue; @@ -152,7 +152,7 @@ Contacts::serialize() const for (auto& item: priv_->contacts_) { const auto& ci{item.second}; - s += Mux::format("%s%s" + s += Mu::format("%s%s" "%s%s" "%s%s" "%d%s" diff --git a/lib/mu-query.cc b/lib/mu-query.cc index 09747138..aeb8fa6c 100644 --- a/lib/mu-query.cc +++ b/lib/mu-query.cc @@ -34,12 +34,12 @@ #include "utils/mu-str.h" #include "utils/mu-date.h" +#include #include -#include #include -struct MuProc: public Mux::ProcIface { +struct MuProc: public Mu::ProcIface { MuProc (const Xapian::Database& db): db_{db} {} @@ -145,11 +145,11 @@ struct MuProc: public Mux::ProcIface { std::string u2 = upper; if (id == MU_MSG_FIELD_ID_DATE) { - l2 = Mux::date_to_time_t_string (lower, true); - u2 = Mux::date_to_time_t_string (upper, false); + l2 = Mu::date_to_time_t_string (lower, true); + u2 = Mu::date_to_time_t_string (upper, false); } else if (id == MU_MSG_FIELD_ID_SIZE) { - l2 = Mux::size_to_string (lower, true); - u2 = Mux::size_to_string (upper, false); + l2 = Mu::size_to_string (lower, true); + u2 = Mu::size_to_string (upper, false); } return { l2, u2 }; @@ -195,13 +195,13 @@ private: static const Xapian::Query get_query (MuQuery *mqx, const char* searchexpr, bool raw, GError **err) try { - Mux::WarningVec warns; - const auto tree = Mux::parse (searchexpr, warns, + Mu::WarningVec warns; + const auto tree = Mu::parse (searchexpr, warns, std::make_unique(mqx->db())); for (const auto w: warns) std::cerr << w << std::endl; - return Mux::xapian_query (tree); + return Mu::xapian_query (tree); } catch (...) { mu_util_g_set_error (err,MU_ERROR_XAPIAN_QUERY, @@ -488,8 +488,8 @@ mu_query_internal (MuQuery *self, const char *searchexpr, g_return_val_if_fail (searchexpr, NULL); try { - Mux::WarningVec warns; - const auto tree = Mux::parse (searchexpr, warns, + Mu::WarningVec warns; + const auto tree = Mu::parse (searchexpr, warns, std::make_unique(self->db())); std::stringstream ss; ss << tree; diff --git a/lib/mu-store.cc b/lib/mu-store.cc index 558a8bf5..ab900d4c 100644 --- a/lib/mu-store.cc +++ b/lib/mu-store.cc @@ -29,7 +29,7 @@ #include "mu-store.hh" #include "utils/mu-str.h" #include "mu-msg-part.h" -#include "parser/utils.hh" +#include "utils/mu-utils.hh" using namespace Mu; @@ -98,7 +98,7 @@ struct Store::Private { maildir_{db()->get_metadata(MaildirKey)}, created_{atoll(db()->get_metadata(CreatedKey).c_str())}, schema_version_{db()->get_metadata(SchemaVersionKey)}, - personal_addresses_{Mux::split(db()->get_metadata(PersonalAddressesKey),",")}, + personal_addresses_{Mu::split(db()->get_metadata(PersonalAddressesKey),",")}, contacts_{db()->get_metadata(ContactsKey)} { } @@ -113,7 +113,7 @@ struct Store::Private { writable_db()->set_metadata(SchemaVersionKey, schema_version_); writable_db()->set_metadata(MaildirKey, maildir_); writable_db()->set_metadata(CreatedKey, - Mux::format("%" PRId64, (int64_t)created_)); + Mu::format("%" PRId64, (int64_t)created_)); } ~Private() { @@ -732,7 +732,7 @@ mu_store_flush (MuStore *store) try { static void add_terms_values_date (Xapian::Document& doc, MuMsg *msg, MuMsgFieldId mfid) { - const auto dstr = Mux::date_to_time_t_string ( + const auto dstr = Mu::date_to_time_t_string ( (time_t)mu_msg_get_field_numeric (msg, mfid)); doc.add_value ((Xapian::valueno)mfid, dstr); @@ -742,7 +742,7 @@ static void add_terms_values_size (Xapian::Document& doc, MuMsg *msg, MuMsgFieldId mfid) { const auto szstr = - Mux::size_to_string (mu_msg_get_field_numeric (msg, mfid)); + Mu::size_to_string (mu_msg_get_field_numeric (msg, mfid)); doc.add_value ((Xapian::valueno)mfid, szstr); } @@ -848,7 +848,7 @@ add_terms_values_number (Xapian::Document& doc, MuMsg *msg, MuMsgFieldId mfid) static void add_terms_values_str (Xapian::Document& doc, const char *val, MuMsgFieldId mfid) { - const auto flat = Mux::utf8_flatten (val); + const auto flat = Mu::utf8_flatten (val); if (mu_msg_field_xapian_index (mfid)) { Xapian::TermGenerator termgen; @@ -928,7 +928,7 @@ maybe_index_text_part (MuMsg *msg, MuMsgPart *part, PartData *pdata) return; termgen.set_document(pdata->_doc); - const auto str = Mux::utf8_flatten (txt); + const auto str = Mu::utf8_flatten (txt); g_free (txt); termgen.index_text (str, 1, prefix(MU_MSG_FIELD_ID_EMBEDDED_TEXT)); @@ -951,7 +951,7 @@ each_part (MuMsg *msg, MuMsgPart *part, PartData *pdata) } if ((fname = mu_msg_part_get_filename (part, FALSE))) { - const auto flat = Mux::utf8_flatten (fname); + const auto flat = Mu::utf8_flatten (fname); g_free (fname); add_term(pdata->_doc, file + flat); } @@ -986,7 +986,7 @@ add_terms_values_body (Xapian::Document& doc, MuMsg *msg, Xapian::TermGenerator termgen; termgen.set_document(doc); - const auto flat = Mux::utf8_flatten(str); + const auto flat = Mu::utf8_flatten(str); termgen.index_text (flat, 1, prefix(mfid)); } @@ -1111,12 +1111,12 @@ each_contact_info (MuMsgContact *contact, MsgDoc *msgdoc) if (!mu_str_is_empty(contact->name)) { Xapian::TermGenerator termgen; termgen.set_document (*msgdoc->_doc); - const auto flat = Mux::utf8_flatten(contact->name); + const auto flat = Mu::utf8_flatten(contact->name); termgen.index_text (flat, 1, pfx); } if (!mu_str_is_empty(contact->email)) { - const auto flat = Mux::utf8_flatten(contact->email); + const auto flat = Mu::utf8_flatten(contact->email); add_term(*msgdoc->_doc, pfx + flat); add_address_subfields (*msgdoc->_doc, contact->email, pfx); /* store it also in our contacts cache */ diff --git a/lib/parser/Makefile.am b/lib/parser/Makefile.am index b5acfb54..20b2a41d 100644 --- a/lib/parser/Makefile.am +++ b/lib/parser/Makefile.am @@ -1,4 +1,4 @@ -## Copyright (C) 2017 Dirk-Jan C. Binnema +## Copyright (C) 2017-2019 Dirk-Jan C. Binnema ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -47,7 +47,8 @@ tokenize_SOURCES= \ tokenize_LDADD= \ $(WARN_LDFLAGS) \ $(GCOV_LDADD) \ - libmuxparser.la + libmu-parser.la \ + ../utils/libmu-utils.la parse_SOURCES= \ parse.cc @@ -55,13 +56,13 @@ parse_SOURCES= \ parse_LDADD= \ $(WARN_LDFLAGS) \ $(GCOV_LDADD) \ - libmuxparser.la - + libmu-parser.la \ + ../utils/libmu-utils.la noinst_LTLIBRARIES= \ - libmuxparser.la + libmu-parser.la -libmuxparser_la_SOURCES= \ +libmu_parser_la_SOURCES= \ data.hh \ parser.cc \ parser.hh \ @@ -69,30 +70,37 @@ libmuxparser_la_SOURCES= \ tokenizer.cc \ tokenizer.hh \ tree.hh \ - utils.cc \ - utils.hh \ xapian.cc \ xapian.hh -libmuxparser_la_LIBADD= \ +libmu_parser_la_LIBADD= \ $(WARN_LDFLAGS) \ $(GLIB_LIBS) \ $(XAPIAN_LIBS) -VALGRIND_SUPPRESSIONS_FILES= ${top_srcdir}/mux.supp + +VALGRIND_SUPPRESSIONS_FILES= \ + ${top_srcdir}/mu.supp noinst_PROGRAMS+=$(TEST_PROGS) -TEST_PROGS += test-tokenizer -test_tokenizer_SOURCES=test-tokenizer.cc -test_tokenizer_LDADD=$(GCOV_LDADD) libmuxparser.la +TEST_PROGS+= \ + test-tokenizer +test_tokenizer_SOURCES= \ + test-tokenizer.cc +test_tokenizer_LDADD= \ + $(GCOV_LDADD) \ + libmu-parser.la \ + ../utils/libmu-utils.la -TEST_PROGS += test-parser -test_parser_SOURCES=test-parser.cc -test_parser_LDADD=$(GCOV_LDADD) libmuxparser.la +TEST_PROGS+= \ + test-parser +test_parser_SOURCES= \ + test-parser.cc +test_parser_LDADD= \ + $(GCOV_LDADD) \ + libmu-parser.la \ + ../utils/libmu-utils.la -TEST_PROGS += test-utils -test_utils_SOURCES=test-utils.cc -test_utils_LDADD= $(GCOV_LDADD) libmuxparser.la TESTS=$(TEST_PROGS) diff --git a/lib/parser/data.hh b/lib/parser/data.hh index 123aea49..25d3634a 100644 --- a/lib/parser/data.hh +++ b/lib/parser/data.hh @@ -24,9 +24,9 @@ #include #include -#include +#include -namespace Mux { +namespace Mu { // class representing some data item; either a Value or a Range a Value can still be a Regex (but // that's not a separate type here) @@ -149,7 +149,7 @@ operator<< (std::ostream& os, const std::unique_ptr& v) return os; } -} // namespace Mux +} // namespace Mu #endif /* __DATA_HH__ */ diff --git a/lib/parser/dummy-processor.hh b/lib/parser/dummy-processor.hh deleted file mode 100644 index 436dc8c2..00000000 --- a/lib/parser/dummy-processor.hh +++ /dev/null @@ -1,30 +0,0 @@ -/* -** Copyright (C) 2017 Dirk-Jan C. Binnema -** -** This library is free software; you can redistribute it and/or -** modify it under the terms of the GNU Lesser General Public License -** as published by the Free Software Foundation; either version 2.1 -** of the License, or (at your option) any later version. -** -** This library is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** Lesser General Public License for more details. -** -** You should have received a copy of the GNU Lesser General Public -** License along with this library; if not, write to the Free -** Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA -** 02110-1301, USA. -*/ -#ifndef __DUMMY_PROCESSOR_HH__ -#define __DUMMY_PROCESSOR_HH__ - -#include -#include -#include - -namespace Mux { - - - -#endif /* __FIELDS_HH__ */ diff --git a/lib/parser/parse.cc b/lib/parser/parse.cc index 297d11d7..620a1cac 100644 --- a/lib/parser/parse.cc +++ b/lib/parser/parse.cc @@ -29,9 +29,9 @@ main (int argc, char *argv[]) for (auto i = 1; i < argc; ++i) s += " " + std::string(argv[i]); - Mux::WarningVec warnings; + Mu::WarningVec warnings; - const auto tree = Mux::parse (s, warnings); + const auto tree = Mu::parse (s, warnings); for (const auto& w: warnings) std::cerr << "1:" << w.pos << ": " << w.msg << std::endl; diff --git a/lib/parser/parser.cc b/lib/parser/parser.cc index 8b5d8c84..5ac5c36f 100644 --- a/lib/parser/parser.cc +++ b/lib/parser/parser.cc @@ -18,9 +18,9 @@ */ #include "parser.hh" #include "tokenizer.hh" -#include "utils.hh" +#include "utils/mu-utils.hh" -using namespace Mux; +using namespace Mu; // 3 precedence levels: units (NOT,()) > factors (OR) > terms (AND) @@ -40,21 +40,21 @@ using namespace Mux; + format(__VA_ARGS__)) static Token -look_ahead (const Mux::Tokens& tokens) +look_ahead (const Mu::Tokens& tokens) { return tokens.front(); } -static Mux::Tree +static Mu::Tree empty() { return {{Node::Type::Empty}}; } -static Mux::Tree term_1 (Mux::Tokens& tokens, ProcPtr proc, WarningVec& warnings); +static Mu::Tree term_1 (Mu::Tokens& tokens, ProcPtr proc, WarningVec& warnings); -static Mux::Tree +static Mu::Tree value (const ProcIface::FieldInfoVec& fields, const std::string& v, size_t pos, ProcPtr proc, WarningVec& warnings) { @@ -83,7 +83,7 @@ value (const ProcIface::FieldInfoVec& fields, const std::string& v, return tree; } -static Mux::Tree +static Mu::Tree regex (const ProcIface::FieldInfoVec& fields, const std::string& v, size_t pos, ProcPtr proc, WarningVec& warnings) { @@ -119,7 +119,7 @@ regex (const ProcIface::FieldInfoVec& fields, const std::string& v, -static Mux::Tree +static Mu::Tree range (const ProcIface::FieldInfoVec& fields, const std::string& lower, const std::string& upper, size_t pos, ProcPtr proc, WarningVec& warnings) @@ -141,8 +141,8 @@ range (const ProcIface::FieldInfoVec& fields, const std::string& lower, } -static Mux::Tree -data (Mux::Tokens& tokens, ProcPtr proc, WarningVec& warnings) +static Mu::Tree +data (Mu::Tokens& tokens, ProcPtr proc, WarningVec& warnings) { const auto token = look_ahead(tokens); if (token.type != Token::Type::Data) @@ -185,8 +185,8 @@ data (Mux::Tokens& tokens, ProcPtr proc, WarningVec& warnings) return value (fields, val, token.pos, proc, warnings); } -static Mux::Tree -unit (Mux::Tokens& tokens, ProcPtr proc, WarningVec& warnings) +static Mu::Tree +unit (Mu::Tokens& tokens, ProcPtr proc, WarningVec& warnings) { if (tokens.empty()) { warnings.push_back ({0, "expected: unit"}); @@ -225,11 +225,11 @@ unit (Mux::Tokens& tokens, ProcPtr proc, WarningVec& warnings) return data (tokens, proc, warnings); } -static Mux::Tree factor_1 (Mux::Tokens& tokens, ProcPtr proc, +static Mu::Tree factor_1 (Mu::Tokens& tokens, ProcPtr proc, WarningVec& warnings); -static Mux::Tree -factor_2 (Mux::Tokens& tokens, Node::Type& op, ProcPtr proc, +static Mu::Tree +factor_2 (Mu::Tokens& tokens, Node::Type& op, ProcPtr proc, WarningVec& warnings) { if (tokens.empty()) @@ -256,8 +256,8 @@ factor_2 (Mux::Tokens& tokens, Node::Type& op, ProcPtr proc, return factor_1 (tokens, proc, warnings); } -static Mux::Tree -factor_1 (Mux::Tokens& tokens, ProcPtr proc, WarningVec& warnings) +static Mu::Tree +factor_1 (Mu::Tokens& tokens, ProcPtr proc, WarningVec& warnings) { Node::Type op { Node::Type::Invalid }; @@ -275,8 +275,8 @@ factor_1 (Mux::Tokens& tokens, ProcPtr proc, WarningVec& warnings) } -static Mux::Tree -term_2 (Mux::Tokens& tokens, Node::Type& op, ProcPtr proc, +static Mu::Tree +term_2 (Mu::Tokens& tokens, Node::Type& op, ProcPtr proc, WarningVec& warnings) { if (tokens.empty()) @@ -302,8 +302,8 @@ term_2 (Mux::Tokens& tokens, Node::Type& op, ProcPtr proc, return term_1 (tokens, proc, warnings); } -static Mux::Tree -term_1 (Mux::Tokens& tokens, ProcPtr proc, WarningVec& warnings) +static Mu::Tree +term_1 (Mu::Tokens& tokens, ProcPtr proc, WarningVec& warnings) { Node::Type op { Node::Type::Invalid }; @@ -320,8 +320,8 @@ term_1 (Mux::Tokens& tokens, ProcPtr proc, WarningVec& warnings) } } -static Mux::Tree -query (Mux::Tokens& tokens, ProcPtr proc, WarningVec& warnings) +static Mu::Tree +query (Mu::Tokens& tokens, ProcPtr proc, WarningVec& warnings) { if (tokens.empty()) return empty (); @@ -329,8 +329,8 @@ query (Mux::Tokens& tokens, ProcPtr proc, WarningVec& warnings) return term_1 (tokens, proc, warnings); } -Mux::Tree -Mux::parse (const std::string& expr, WarningVec& warnings, ProcPtr proc) +Mu::Tree +Mu::parse (const std::string& expr, WarningVec& warnings, ProcPtr proc) { try { auto tokens = tokenize (expr); diff --git a/lib/parser/parser.hh b/lib/parser/parser.hh index 34cbb529..f9f7537f 100644 --- a/lib/parser/parser.hh +++ b/lib/parser/parser.hh @@ -32,7 +32,7 @@ // A simple recursive-descent parser for queries. Follows the Xapian syntax, // but better handles non-alphanum; also implements regexp -namespace Mux { +namespace Mu { /** * A parser warning @@ -84,6 +84,6 @@ using ProcPtr = const std::unique_ptr&; Tree parse (const std::string& query, WarningVec& warnings, ProcPtr proc = std::make_unique()); -} // namespace Mux +} // namespace Mu #endif /* __PARSER_HH__ */ diff --git a/lib/parser/proc-iface.hh b/lib/parser/proc-iface.hh index e13fd0ff..b43ef413 100644 --- a/lib/parser/proc-iface.hh +++ b/lib/parser/proc-iface.hh @@ -24,7 +24,7 @@ #include #include -namespace Mux { +namespace Mu { struct ProcIface { @@ -127,6 +127,6 @@ struct DummyProc: public ProcIface { // For testing }; //Dummy -} // Mux +} // Mu #endif /* __PROC_IFACE_HH__ */ diff --git a/lib/parser/test-parser.cc b/lib/parser/test-parser.cc index 5fe5e0a0..d16dfbf3 100644 --- a/lib/parser/test-parser.cc +++ b/lib/parser/test-parser.cc @@ -24,7 +24,7 @@ #include #include "parser.hh" -using namespace Mux; +using namespace Mu; struct Case { const std::string expr; diff --git a/lib/parser/test-tokenizer.cc b/lib/parser/test-tokenizer.cc index d796d957..002e845f 100644 --- a/lib/parser/test-tokenizer.cc +++ b/lib/parser/test-tokenizer.cc @@ -26,12 +26,12 @@ struct Case { const char *str; - const Mux::Tokens tokens; + const Mu::Tokens tokens; }; using CaseVec = std::vector; -using namespace Mux; +using namespace Mu; using TT = Token::Type; static void diff --git a/lib/parser/tokenize.cc b/lib/parser/tokenize.cc index 13c17882..6d7a64a5 100644 --- a/lib/parser/tokenize.cc +++ b/lib/parser/tokenize.cc @@ -30,7 +30,7 @@ main (int argc, char *argv[]) for (auto i = 1; i < argc; ++i) s += " " + std::string(argv[i]); - const auto tvec = Mux::tokenize (s); + const auto tvec = Mu::tokenize (s); for (const auto& t : tvec) std::cout << t << std::endl; diff --git a/lib/parser/tokenizer.cc b/lib/parser/tokenizer.cc index d1fc0e97..f0307aff 100644 --- a/lib/parser/tokenizer.cc +++ b/lib/parser/tokenizer.cc @@ -18,13 +18,13 @@ */ #include "tokenizer.hh" -#include "utils.hh" +#include "utils/mu-utils.hh" #include #include #include -using namespace Mux; +using namespace Mu; static bool is_separator (char c) @@ -37,7 +37,7 @@ is_separator (char c) } -static Mux::Token +static Mu::Token op_or_value (size_t pos, const std::string& val) { auto s = val; @@ -62,7 +62,7 @@ unread_char (std::string& food, char kar, size_t& pos) --pos; } -static Mux::Token +static Mu::Token eat_token (std::string& food, size_t& pos) { bool quoted{}; @@ -115,8 +115,8 @@ eat_token (std::string& food, size_t& pos) } -Mux::Tokens -Mux::tokenize (const std::string& s) +Mu::Tokens +Mu::tokenize (const std::string& s) { Tokens tokens{}; diff --git a/lib/parser/tokenizer.hh b/lib/parser/tokenizer.hh index 1f0da014..ac083c8f 100644 --- a/lib/parser/tokenizer.hh +++ b/lib/parser/tokenizer.hh @@ -36,7 +36,7 @@ // Furthermore, we detect ranges ("a..b") and regexps (/../) at the parser level, since we need a // bit more context to resolve ambiguities. -namespace Mux { +namespace Mu { // A token struct Token { @@ -135,6 +135,6 @@ operator<< (std::ostream& os, const Token& t) using Tokens = std::deque; Tokens tokenize (const std::string& s); -} // namespace Mux +} // namespace Mu #endif /* __TOKENIZER_HH__ */ diff --git a/lib/parser/tree.hh b/lib/parser/tree.hh index 8303eede..5ff02559 100644 --- a/lib/parser/tree.hh +++ b/lib/parser/tree.hh @@ -17,13 +17,16 @@ ** 02110-1301, USA. */ +#ifndef TREE_HH__ +#define TREE_HH__ + #include #include #include #include -namespace Mux { +namespace Mu { // A node in the parse tree struct Node { @@ -101,4 +104,7 @@ operator<< (std::ostream& os, const Tree& tree) return os; } -} // namespace Mux +} // namespace Mu + + +#endif /* TREE_HH__ */ diff --git a/lib/parser/xapian.cc b/lib/parser/xapian.cc index 33f094ce..19afb663 100644 --- a/lib/parser/xapian.cc +++ b/lib/parser/xapian.cc @@ -24,10 +24,10 @@ #include #include "parser/xapian.hh" -using namespace Mux; +using namespace Mu; static Xapian::Query -xapian_query_op (const Mux::Tree& tree) +xapian_query_op (const Mu::Tree& tree) { Xapian::Query::op op; @@ -68,7 +68,7 @@ make_query (const Value* val, const std::string& str, bool maybe_wildcard) } static Xapian::Query -xapian_query_value (const Mux::Tree& tree) +xapian_query_value (const Mu::Tree& tree) { const auto v = dynamic_cast (tree.node.data.get()); if (!v->phrase) @@ -89,7 +89,7 @@ xapian_query_value (const Mux::Tree& tree) } static Xapian::Query -xapian_query_range (const Mux::Tree& tree) +xapian_query_range (const Mu::Tree& tree) { const auto r { dynamic_cast(tree.node.data.get()) }; @@ -98,7 +98,7 @@ xapian_query_range (const Mux::Tree& tree) } Xapian::Query -Mux::xapian_query (const Mux::Tree& tree) +Mu::xapian_query (const Mu::Tree& tree) { switch (tree.node.type) { case Node::Type::Empty: diff --git a/lib/parser/xapian.hh b/lib/parser/xapian.hh index 4f30a01b..c969054e 100644 --- a/lib/parser/xapian.hh +++ b/lib/parser/xapian.hh @@ -24,7 +24,7 @@ #include #include -namespace Mux { +namespace Mu { /** * Transform a parse-tree into a Xapian query object @@ -33,8 +33,8 @@ namespace Mux { * * @return a Xapian query object */ -Xapian::Query xapian_query (const Mux::Tree& tree); +Xapian::Query xapian_query (const Mu::Tree& tree); -}; +} // namespace Mu #endif /* __XAPIAN_H__ */ diff --git a/lib/utils/Makefile.am b/lib/utils/Makefile.am index 20f6727d..d04c1010 100644 --- a/lib/utils/Makefile.am +++ b/lib/utils/Makefile.am @@ -43,7 +43,9 @@ libmu_utils_la_SOURCES= \ mu-str.c \ mu-str.h \ mu-util.c \ - mu-util.h + mu-util.h \ + mu-utils.cc \ + mu-utils.hh libmu_utils_la_LIBADD= \ $(GLIB_LIBS) @@ -61,6 +63,13 @@ test_mu_util_SOURCES= \ test_mu_util_LDADD= \ libmu-utils.la +TEST_PROGS+= \ + test-mu-utils +test_mu_utils_SOURCES= \ + test-utils.cc +test_mu_utils_LDADD= \ + libmu-utils.la + TEST_PROGS+= \ test-mu-str test_mu_str_SOURCES= \ diff --git a/lib/parser/utils.cc b/lib/utils/mu-utils.cc similarity index 95% rename from lib/parser/utils.cc rename to lib/utils/mu-utils.cc index 0cea85a6..fc7e3810 100644 --- a/lib/parser/utils.cc +++ b/lib/utils/mu-utils.cc @@ -17,6 +17,7 @@ ** 02110-1301, USA. */ + #define _XOPEN_SOURCE #include @@ -24,8 +25,6 @@ #include #include -#include "utils.hh" - #include #include #include @@ -33,7 +32,10 @@ #include #include -using namespace Mux; +#include "mu-utils.hh" + + +using namespace Mu; namespace { @@ -100,7 +102,7 @@ gx_utf8_flatten (const gchar *str, gssize len) } // namespace std::string // gx_utf8_flatten -Mux::utf8_flatten (const char *str) +Mu::utf8_flatten (const char *str) { if (!str) return {}; @@ -125,7 +127,7 @@ Mux::utf8_flatten (const char *str) } std::string -Mux::utf8_clean (const std::string& dirty) +Mu::utf8_clean (const std::string& dirty) { GString *gstr = g_string_sized_new (dirty.length()); @@ -148,7 +150,7 @@ Mux::utf8_clean (const std::string& dirty) } std::vector -Mux::split (const std::string& str, const std::string& sepa) +Mu::split (const std::string& str, const std::string& sepa) { char **parts = g_strsplit(str.c_str(), sepa.c_str(), -1); std::vector vec; @@ -161,7 +163,7 @@ Mux::split (const std::string& str, const std::string& sepa) } std::string -Mux::quote (const std::string& str) +Mu::quote (const std::string& str) { char *s = g_strescape (str.c_str(), NULL); if (!s) @@ -174,7 +176,7 @@ Mux::quote (const std::string& str) } std::string - Mux::format (const char *frm, ...) + Mu::format (const char *frm, ...) { va_list args; @@ -207,7 +209,7 @@ date_boundary (bool is_first) } std::string -Mux::date_to_time_t_string (int64_t t) +Mu::date_to_time_t_string (int64_t t) { char buf[sizeof(InternalDateMax)]; snprintf (buf, sizeof(buf), InternalDateFormat, t); @@ -319,7 +321,7 @@ fixup_month (struct tm *tbuf) } std::string -Mux::date_to_time_t_string (const std::string& dstr, bool is_first) +Mu::date_to_time_t_string (const std::string& dstr, bool is_first) { gint64 t; struct tm tbuf; @@ -385,7 +387,7 @@ size_boundary (bool is_first) } std::string -Mux::size_to_string (int64_t size) +Mu::size_to_string (int64_t size) { char buf[sizeof(SizeMax)]; snprintf (buf, sizeof(buf), SizeFormat, size); @@ -394,7 +396,7 @@ Mux::size_to_string (int64_t size) } std::string -Mux::size_to_string (const std::string& val, bool is_first) +Mu::size_to_string (const std::string& val, bool is_first) { std::string str; GRegex *rx; diff --git a/lib/parser/utils.hh b/lib/utils/mu-utils.hh similarity index 86% rename from lib/parser/utils.hh rename to lib/utils/mu-utils.hh index f243cdbf..78d18056 100644 --- a/lib/parser/utils.hh +++ b/lib/utils/mu-utils.hh @@ -17,13 +17,14 @@ ** 02110-1301, USA. */ +#ifndef __MU_UTILS_HH__ +#define __MU_UTILS_HH__ + #include #include +#include -#ifndef __UTILS_HH__ -#define __UTILS_HH__ - -namespace Mux { +namespace Mu { /** * Flatten a string -- downcase and fold diacritics etc. @@ -75,8 +76,19 @@ std::string quote (const std::string& str); * * @return a formatted string */ -std::string format (const char *frm, ...) - __attribute__((format(printf, 1, 2))); +std::string format (const char *frm, ...) __attribute__((format(printf, 1, 2))); + +/** + * Format a string, printf style + * + * @param frm format string + * @param ... parameters + * + * @return a formatted string + */ +std::string format (const char *frm, va_list args) __attribute__((format(printf, 1, 0))); + + /** * Convert an ISO date to the corresponding time expressed as a string @@ -121,6 +133,6 @@ std::string size_to_string (const std::string& sizestr, bool first); */ std::string size_to_string (int64_t size); -} // namespace Mux +} // namespace Mu -#endif /* __UTILS_HH__ */ +#endif /* __MU_UTILS_HH__ */ diff --git a/lib/parser/test-utils.cc b/lib/utils/test-utils.cc similarity index 95% rename from lib/parser/test-utils.cc rename to lib/utils/test-utils.cc index c0412d90..c43c2530 100644 --- a/lib/parser/test-utils.cc +++ b/lib/utils/test-utils.cc @@ -22,9 +22,11 @@ #include #include +#include -#include "parser.hh" -using namespace Mux; +#include "mu-utils.hh" + +using namespace Mu; struct Case { const std::string expr; @@ -95,7 +97,7 @@ test_date_ymwdhMs (void) for (auto i = 0; i != G_N_ELEMENTS(tests); ++i) { const auto diff = time(NULL) - - strtol(Mux::date_to_time_t_string(tests[i].expr, true).c_str(), + strtol(Mu::date_to_time_t_string(tests[i].expr, true).c_str(), NULL, 10); if (g_test_verbose()) std::cerr << tests[i].expr << ' ' @@ -105,7 +107,7 @@ test_date_ymwdhMs (void) g_assert_true (tests[i].diff - diff <= tests[i].tolerance); } - g_assert_true (strtol(Mux::date_to_time_t_string("-1y", true).c_str(), + g_assert_true (strtol(Mu::date_to_time_t_string("-1y", true).c_str(), NULL, 10) == 0); } diff --git a/mu/Makefile.am b/mu/Makefile.am index 97f6c991..d43197aa 100644 --- a/mu/Makefile.am +++ b/mu/Makefile.am @@ -65,7 +65,6 @@ mu-help-strings.h: mu-help-strings.txt mu-help-strings.awk mu_LDADD= \ ${top_builddir}/lib/libmu.la \ - ${top_builddir}/lib/parser/libmuxparser.la \ $(GLIB_LIBS) EXTRA_DIST= \