mirror of https://github.com/djcb/mu.git
move parser/utils to utils, Mux->Mu
Move the parser utils to utils/ and rename the Mux namespace into Mu.
This commit is contained in:
parent
b55e191421
commit
9f93526884
|
@ -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)
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include <functional>
|
||||
#include <algorithm>
|
||||
|
||||
#include <parser/utils.hh>
|
||||
#include <utils/mu-utils.hh>
|
||||
#include <glib.h>
|
||||
|
||||
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"
|
||||
|
|
|
@ -34,12 +34,12 @@
|
|||
|
||||
#include "utils/mu-str.h"
|
||||
#include "utils/mu-date.h"
|
||||
#include <utils/mu-utils.hh>
|
||||
|
||||
#include <parser/proc-iface.hh>
|
||||
#include <parser/utils.hh>
|
||||
#include <parser/xapian.hh>
|
||||
|
||||
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<MuProc>(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<MuProc>(self->db()));
|
||||
std::stringstream ss;
|
||||
ss << tree;
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
## Copyright (C) 2017 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
## Copyright (C) 2017-2019 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
##
|
||||
## 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)
|
||||
|
|
|
@ -24,9 +24,9 @@
|
|||
#include <iostream>
|
||||
#include <regex>
|
||||
|
||||
#include <parser/utils.hh>
|
||||
#include <utils//mu-utils.hh>
|
||||
|
||||
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<Data>& v)
|
|||
return os;
|
||||
}
|
||||
|
||||
} // namespace Mux
|
||||
} // namespace Mu
|
||||
|
||||
|
||||
#endif /* __DATA_HH__ */
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2017 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** 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 <string>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
namespace Mux {
|
||||
|
||||
|
||||
|
||||
#endif /* __FIELDS_HH__ */
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<ProcIface>&;
|
|||
Tree parse (const std::string& query, WarningVec& warnings,
|
||||
ProcPtr proc = std::make_unique<DummyProc>());
|
||||
|
||||
} // namespace Mux
|
||||
} // namespace Mu
|
||||
|
||||
#endif /* __PARSER_HH__ */
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include <tuple>
|
||||
#include <regex>
|
||||
|
||||
namespace Mux {
|
||||
namespace Mu {
|
||||
|
||||
struct ProcIface {
|
||||
|
||||
|
@ -127,6 +127,6 @@ struct DummyProc: public ProcIface { // For testing
|
|||
}; //Dummy
|
||||
|
||||
|
||||
} // Mux
|
||||
} // Mu
|
||||
|
||||
#endif /* __PROC_IFACE_HH__ */
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include <sstream>
|
||||
|
||||
#include "parser.hh"
|
||||
using namespace Mux;
|
||||
using namespace Mu;
|
||||
|
||||
struct Case {
|
||||
const std::string expr;
|
||||
|
|
|
@ -26,12 +26,12 @@
|
|||
|
||||
struct Case {
|
||||
const char *str;
|
||||
const Mux::Tokens tokens;
|
||||
const Mu::Tokens tokens;
|
||||
};
|
||||
|
||||
using CaseVec = std::vector<Case>;
|
||||
|
||||
using namespace Mux;
|
||||
using namespace Mu;
|
||||
using TT = Token::Type;
|
||||
|
||||
static void
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -18,13 +18,13 @@
|
|||
*/
|
||||
|
||||
#include "tokenizer.hh"
|
||||
#include "utils.hh"
|
||||
#include "utils/mu-utils.hh"
|
||||
|
||||
#include <cctype>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
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{};
|
||||
|
||||
|
|
|
@ -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<Token>;
|
||||
Tokens tokenize (const std::string& s);
|
||||
|
||||
} // namespace Mux
|
||||
} // namespace Mu
|
||||
|
||||
#endif /* __TOKENIZER_HH__ */
|
||||
|
|
|
@ -17,13 +17,16 @@
|
|||
** 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef TREE_HH__
|
||||
#define TREE_HH__
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include <parser/data.hh>
|
||||
|
||||
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__ */
|
||||
|
|
|
@ -24,10 +24,10 @@
|
|||
#include <xapian.h>
|
||||
#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<Value*> (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<Range *>(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:
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include <xapian.h>
|
||||
#include <parser/parser.hh>
|
||||
|
||||
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__ */
|
||||
|
|
|
@ -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= \
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
** 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#define _XOPEN_SOURCE
|
||||
#include <time.h>
|
||||
|
||||
|
@ -24,8 +25,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "utils.hh"
|
||||
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
@ -33,7 +32,10 @@
|
|||
#include <glib.h>
|
||||
#include <glib/gprintf.h>
|
||||
|
||||
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<std::string>
|
||||
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<std::string> 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;
|
|
@ -17,13 +17,14 @@
|
|||
** 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __MU_UTILS_HH__
|
||||
#define __MU_UTILS_HH__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdarg>
|
||||
|
||||
#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__ */
|
|
@ -22,9 +22,11 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <functional>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
|
@ -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= \
|
||||
|
|
Loading…
Reference in New Issue