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:
@ -109,7 +109,7 @@ libmu_la_LIBADD= \
|
|||||||
$(GUILE_LIBS) \
|
$(GUILE_LIBS) \
|
||||||
$(JSON_GLIB_LIBS) \
|
$(JSON_GLIB_LIBS) \
|
||||||
${builddir}/utils/libmu-utils.la \
|
${builddir}/utils/libmu-utils.la \
|
||||||
${builddir}/parser/libmuxparser.la
|
${builddir}/parser/libmu-parser.la
|
||||||
|
|
||||||
libmu_la_LDFLAGS= \
|
libmu_la_LDFLAGS= \
|
||||||
$(ASAN_LDFLAGS)
|
$(ASAN_LDFLAGS)
|
||||||
|
|||||||
@ -26,7 +26,7 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include <parser/utils.hh>
|
#include <utils/mu-utils.hh>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
using namespace Mu;
|
using namespace Mu;
|
||||||
@ -117,7 +117,7 @@ Contacts::Private::deserialize(const std::string& serialized) const
|
|||||||
|
|
||||||
while (getline (ss, line)) {
|
while (getline (ss, line)) {
|
||||||
|
|
||||||
const auto parts = Mux::split (line, Separator);
|
const auto parts = Mu::split (line, Separator);
|
||||||
if (G_UNLIKELY(parts.size() != 6)) {
|
if (G_UNLIKELY(parts.size() != 6)) {
|
||||||
g_warning ("error: '%s'", line.c_str());
|
g_warning ("error: '%s'", line.c_str());
|
||||||
continue;
|
continue;
|
||||||
@ -152,7 +152,7 @@ Contacts::serialize() const
|
|||||||
|
|
||||||
for (auto& item: priv_->contacts_) {
|
for (auto& item: priv_->contacts_) {
|
||||||
const auto& ci{item.second};
|
const auto& ci{item.second};
|
||||||
s += Mux::format("%s%s"
|
s += Mu::format("%s%s"
|
||||||
"%s%s"
|
"%s%s"
|
||||||
"%s%s"
|
"%s%s"
|
||||||
"%d%s"
|
"%d%s"
|
||||||
|
|||||||
@ -34,12 +34,12 @@
|
|||||||
|
|
||||||
#include "utils/mu-str.h"
|
#include "utils/mu-str.h"
|
||||||
#include "utils/mu-date.h"
|
#include "utils/mu-date.h"
|
||||||
|
#include <utils/mu-utils.hh>
|
||||||
|
|
||||||
#include <parser/proc-iface.hh>
|
#include <parser/proc-iface.hh>
|
||||||
#include <parser/utils.hh>
|
|
||||||
#include <parser/xapian.hh>
|
#include <parser/xapian.hh>
|
||||||
|
|
||||||
struct MuProc: public Mux::ProcIface {
|
struct MuProc: public Mu::ProcIface {
|
||||||
|
|
||||||
MuProc (const Xapian::Database& db): db_{db} {}
|
MuProc (const Xapian::Database& db): db_{db} {}
|
||||||
|
|
||||||
@ -145,11 +145,11 @@ struct MuProc: public Mux::ProcIface {
|
|||||||
std::string u2 = upper;
|
std::string u2 = upper;
|
||||||
|
|
||||||
if (id == MU_MSG_FIELD_ID_DATE) {
|
if (id == MU_MSG_FIELD_ID_DATE) {
|
||||||
l2 = Mux::date_to_time_t_string (lower, true);
|
l2 = Mu::date_to_time_t_string (lower, true);
|
||||||
u2 = Mux::date_to_time_t_string (upper, false);
|
u2 = Mu::date_to_time_t_string (upper, false);
|
||||||
} else if (id == MU_MSG_FIELD_ID_SIZE) {
|
} else if (id == MU_MSG_FIELD_ID_SIZE) {
|
||||||
l2 = Mux::size_to_string (lower, true);
|
l2 = Mu::size_to_string (lower, true);
|
||||||
u2 = Mux::size_to_string (upper, false);
|
u2 = Mu::size_to_string (upper, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { l2, u2 };
|
return { l2, u2 };
|
||||||
@ -195,13 +195,13 @@ private:
|
|||||||
static const Xapian::Query
|
static const Xapian::Query
|
||||||
get_query (MuQuery *mqx, const char* searchexpr, bool raw, GError **err) try {
|
get_query (MuQuery *mqx, const char* searchexpr, bool raw, GError **err) try {
|
||||||
|
|
||||||
Mux::WarningVec warns;
|
Mu::WarningVec warns;
|
||||||
const auto tree = Mux::parse (searchexpr, warns,
|
const auto tree = Mu::parse (searchexpr, warns,
|
||||||
std::make_unique<MuProc>(mqx->db()));
|
std::make_unique<MuProc>(mqx->db()));
|
||||||
for (const auto w: warns)
|
for (const auto w: warns)
|
||||||
std::cerr << w << std::endl;
|
std::cerr << w << std::endl;
|
||||||
|
|
||||||
return Mux::xapian_query (tree);
|
return Mu::xapian_query (tree);
|
||||||
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
mu_util_g_set_error (err,MU_ERROR_XAPIAN_QUERY,
|
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);
|
g_return_val_if_fail (searchexpr, NULL);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Mux::WarningVec warns;
|
Mu::WarningVec warns;
|
||||||
const auto tree = Mux::parse (searchexpr, warns,
|
const auto tree = Mu::parse (searchexpr, warns,
|
||||||
std::make_unique<MuProc>(self->db()));
|
std::make_unique<MuProc>(self->db()));
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << tree;
|
ss << tree;
|
||||||
|
|||||||
@ -29,7 +29,7 @@
|
|||||||
#include "mu-store.hh"
|
#include "mu-store.hh"
|
||||||
#include "utils/mu-str.h"
|
#include "utils/mu-str.h"
|
||||||
#include "mu-msg-part.h"
|
#include "mu-msg-part.h"
|
||||||
#include "parser/utils.hh"
|
#include "utils/mu-utils.hh"
|
||||||
|
|
||||||
using namespace Mu;
|
using namespace Mu;
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ struct Store::Private {
|
|||||||
maildir_{db()->get_metadata(MaildirKey)},
|
maildir_{db()->get_metadata(MaildirKey)},
|
||||||
created_{atoll(db()->get_metadata(CreatedKey).c_str())},
|
created_{atoll(db()->get_metadata(CreatedKey).c_str())},
|
||||||
schema_version_{db()->get_metadata(SchemaVersionKey)},
|
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)} {
|
contacts_{db()->get_metadata(ContactsKey)} {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ struct Store::Private {
|
|||||||
writable_db()->set_metadata(SchemaVersionKey, schema_version_);
|
writable_db()->set_metadata(SchemaVersionKey, schema_version_);
|
||||||
writable_db()->set_metadata(MaildirKey, maildir_);
|
writable_db()->set_metadata(MaildirKey, maildir_);
|
||||||
writable_db()->set_metadata(CreatedKey,
|
writable_db()->set_metadata(CreatedKey,
|
||||||
Mux::format("%" PRId64, (int64_t)created_));
|
Mu::format("%" PRId64, (int64_t)created_));
|
||||||
}
|
}
|
||||||
|
|
||||||
~Private() {
|
~Private() {
|
||||||
@ -732,7 +732,7 @@ mu_store_flush (MuStore *store) try {
|
|||||||
static void
|
static void
|
||||||
add_terms_values_date (Xapian::Document& doc, MuMsg *msg, MuMsgFieldId mfid)
|
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));
|
(time_t)mu_msg_get_field_numeric (msg, mfid));
|
||||||
|
|
||||||
doc.add_value ((Xapian::valueno)mfid, dstr);
|
doc.add_value ((Xapian::valueno)mfid, dstr);
|
||||||
@ -742,7 +742,7 @@ static void
|
|||||||
add_terms_values_size (Xapian::Document& doc, MuMsg *msg, MuMsgFieldId mfid)
|
add_terms_values_size (Xapian::Document& doc, MuMsg *msg, MuMsgFieldId mfid)
|
||||||
{
|
{
|
||||||
const auto szstr =
|
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);
|
doc.add_value ((Xapian::valueno)mfid, szstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -848,7 +848,7 @@ add_terms_values_number (Xapian::Document& doc, MuMsg *msg, MuMsgFieldId mfid)
|
|||||||
static void
|
static void
|
||||||
add_terms_values_str (Xapian::Document& doc, const char *val, MuMsgFieldId mfid)
|
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)) {
|
if (mu_msg_field_xapian_index (mfid)) {
|
||||||
Xapian::TermGenerator termgen;
|
Xapian::TermGenerator termgen;
|
||||||
@ -928,7 +928,7 @@ maybe_index_text_part (MuMsg *msg, MuMsgPart *part, PartData *pdata)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
termgen.set_document(pdata->_doc);
|
termgen.set_document(pdata->_doc);
|
||||||
const auto str = Mux::utf8_flatten (txt);
|
const auto str = Mu::utf8_flatten (txt);
|
||||||
g_free (txt);
|
g_free (txt);
|
||||||
|
|
||||||
termgen.index_text (str, 1, prefix(MU_MSG_FIELD_ID_EMBEDDED_TEXT));
|
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))) {
|
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);
|
g_free (fname);
|
||||||
add_term(pdata->_doc, file + flat);
|
add_term(pdata->_doc, file + flat);
|
||||||
}
|
}
|
||||||
@ -986,7 +986,7 @@ add_terms_values_body (Xapian::Document& doc, MuMsg *msg,
|
|||||||
Xapian::TermGenerator termgen;
|
Xapian::TermGenerator termgen;
|
||||||
termgen.set_document(doc);
|
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));
|
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)) {
|
if (!mu_str_is_empty(contact->name)) {
|
||||||
Xapian::TermGenerator termgen;
|
Xapian::TermGenerator termgen;
|
||||||
termgen.set_document (*msgdoc->_doc);
|
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);
|
termgen.index_text (flat, 1, pfx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mu_str_is_empty(contact->email)) {
|
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_term(*msgdoc->_doc, pfx + flat);
|
||||||
add_address_subfields (*msgdoc->_doc, contact->email, pfx);
|
add_address_subfields (*msgdoc->_doc, contact->email, pfx);
|
||||||
/* store it also in our contacts cache */
|
/* 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
|
## 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
|
## it under the terms of the GNU General Public License as published by
|
||||||
@ -47,7 +47,8 @@ tokenize_SOURCES= \
|
|||||||
tokenize_LDADD= \
|
tokenize_LDADD= \
|
||||||
$(WARN_LDFLAGS) \
|
$(WARN_LDFLAGS) \
|
||||||
$(GCOV_LDADD) \
|
$(GCOV_LDADD) \
|
||||||
libmuxparser.la
|
libmu-parser.la \
|
||||||
|
../utils/libmu-utils.la
|
||||||
|
|
||||||
parse_SOURCES= \
|
parse_SOURCES= \
|
||||||
parse.cc
|
parse.cc
|
||||||
@ -55,13 +56,13 @@ parse_SOURCES= \
|
|||||||
parse_LDADD= \
|
parse_LDADD= \
|
||||||
$(WARN_LDFLAGS) \
|
$(WARN_LDFLAGS) \
|
||||||
$(GCOV_LDADD) \
|
$(GCOV_LDADD) \
|
||||||
libmuxparser.la
|
libmu-parser.la \
|
||||||
|
../utils/libmu-utils.la
|
||||||
|
|
||||||
noinst_LTLIBRARIES= \
|
noinst_LTLIBRARIES= \
|
||||||
libmuxparser.la
|
libmu-parser.la
|
||||||
|
|
||||||
libmuxparser_la_SOURCES= \
|
libmu_parser_la_SOURCES= \
|
||||||
data.hh \
|
data.hh \
|
||||||
parser.cc \
|
parser.cc \
|
||||||
parser.hh \
|
parser.hh \
|
||||||
@ -69,30 +70,37 @@ libmuxparser_la_SOURCES= \
|
|||||||
tokenizer.cc \
|
tokenizer.cc \
|
||||||
tokenizer.hh \
|
tokenizer.hh \
|
||||||
tree.hh \
|
tree.hh \
|
||||||
utils.cc \
|
|
||||||
utils.hh \
|
|
||||||
xapian.cc \
|
xapian.cc \
|
||||||
xapian.hh
|
xapian.hh
|
||||||
|
|
||||||
libmuxparser_la_LIBADD= \
|
libmu_parser_la_LIBADD= \
|
||||||
$(WARN_LDFLAGS) \
|
$(WARN_LDFLAGS) \
|
||||||
$(GLIB_LIBS) \
|
$(GLIB_LIBS) \
|
||||||
$(XAPIAN_LIBS)
|
$(XAPIAN_LIBS)
|
||||||
|
|
||||||
VALGRIND_SUPPRESSIONS_FILES= ${top_srcdir}/mux.supp
|
|
||||||
|
VALGRIND_SUPPRESSIONS_FILES= \
|
||||||
|
${top_srcdir}/mu.supp
|
||||||
|
|
||||||
noinst_PROGRAMS+=$(TEST_PROGS)
|
noinst_PROGRAMS+=$(TEST_PROGS)
|
||||||
|
|
||||||
TEST_PROGS += test-tokenizer
|
TEST_PROGS+= \
|
||||||
test_tokenizer_SOURCES=test-tokenizer.cc
|
test-tokenizer
|
||||||
test_tokenizer_LDADD=$(GCOV_LDADD) libmuxparser.la
|
test_tokenizer_SOURCES= \
|
||||||
|
test-tokenizer.cc
|
||||||
|
test_tokenizer_LDADD= \
|
||||||
|
$(GCOV_LDADD) \
|
||||||
|
libmu-parser.la \
|
||||||
|
../utils/libmu-utils.la
|
||||||
|
|
||||||
TEST_PROGS += test-parser
|
TEST_PROGS+= \
|
||||||
test_parser_SOURCES=test-parser.cc
|
test-parser
|
||||||
test_parser_LDADD=$(GCOV_LDADD) libmuxparser.la
|
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)
|
TESTS=$(TEST_PROGS)
|
||||||
|
|||||||
@ -24,9 +24,9 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <regex>
|
#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
|
// 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)
|
// that's not a separate type here)
|
||||||
@ -149,7 +149,7 @@ operator<< (std::ostream& os, const std::unique_ptr<Data>& v)
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Mux
|
} // namespace Mu
|
||||||
|
|
||||||
|
|
||||||
#endif /* __DATA_HH__ */
|
#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)
|
for (auto i = 1; i < argc; ++i)
|
||||||
s += " " + std::string(argv[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)
|
for (const auto& w: warnings)
|
||||||
std::cerr << "1:" << w.pos << ": " << w.msg << std::endl;
|
std::cerr << "1:" << w.pos << ": " << w.msg << std::endl;
|
||||||
|
|
||||||
|
|||||||
@ -18,9 +18,9 @@
|
|||||||
*/
|
*/
|
||||||
#include "parser.hh"
|
#include "parser.hh"
|
||||||
#include "tokenizer.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)
|
// 3 precedence levels: units (NOT,()) > factors (OR) > terms (AND)
|
||||||
|
|
||||||
@ -40,21 +40,21 @@ using namespace Mux;
|
|||||||
+ format(__VA_ARGS__))
|
+ format(__VA_ARGS__))
|
||||||
|
|
||||||
static Token
|
static Token
|
||||||
look_ahead (const Mux::Tokens& tokens)
|
look_ahead (const Mu::Tokens& tokens)
|
||||||
{
|
{
|
||||||
return tokens.front();
|
return tokens.front();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Mux::Tree
|
static Mu::Tree
|
||||||
empty()
|
empty()
|
||||||
{
|
{
|
||||||
return {{Node::Type::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,
|
value (const ProcIface::FieldInfoVec& fields, const std::string& v,
|
||||||
size_t pos, ProcPtr proc, WarningVec& warnings)
|
size_t pos, ProcPtr proc, WarningVec& warnings)
|
||||||
{
|
{
|
||||||
@ -83,7 +83,7 @@ value (const ProcIface::FieldInfoVec& fields, const std::string& v,
|
|||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Mux::Tree
|
static Mu::Tree
|
||||||
regex (const ProcIface::FieldInfoVec& fields, const std::string& v,
|
regex (const ProcIface::FieldInfoVec& fields, const std::string& v,
|
||||||
size_t pos, ProcPtr proc, WarningVec& warnings)
|
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,
|
range (const ProcIface::FieldInfoVec& fields, const std::string& lower,
|
||||||
const std::string& upper, size_t pos, ProcPtr proc,
|
const std::string& upper, size_t pos, ProcPtr proc,
|
||||||
WarningVec& warnings)
|
WarningVec& warnings)
|
||||||
@ -141,8 +141,8 @@ range (const ProcIface::FieldInfoVec& fields, const std::string& lower,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Mux::Tree
|
static Mu::Tree
|
||||||
data (Mux::Tokens& tokens, ProcPtr proc, WarningVec& warnings)
|
data (Mu::Tokens& tokens, ProcPtr proc, WarningVec& warnings)
|
||||||
{
|
{
|
||||||
const auto token = look_ahead(tokens);
|
const auto token = look_ahead(tokens);
|
||||||
if (token.type != Token::Type::Data)
|
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);
|
return value (fields, val, token.pos, proc, warnings);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Mux::Tree
|
static Mu::Tree
|
||||||
unit (Mux::Tokens& tokens, ProcPtr proc, WarningVec& warnings)
|
unit (Mu::Tokens& tokens, ProcPtr proc, WarningVec& warnings)
|
||||||
{
|
{
|
||||||
if (tokens.empty()) {
|
if (tokens.empty()) {
|
||||||
warnings.push_back ({0, "expected: unit"});
|
warnings.push_back ({0, "expected: unit"});
|
||||||
@ -225,11 +225,11 @@ unit (Mux::Tokens& tokens, ProcPtr proc, WarningVec& warnings)
|
|||||||
return data (tokens, proc, 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);
|
WarningVec& warnings);
|
||||||
|
|
||||||
static Mux::Tree
|
static Mu::Tree
|
||||||
factor_2 (Mux::Tokens& tokens, Node::Type& op, ProcPtr proc,
|
factor_2 (Mu::Tokens& tokens, Node::Type& op, ProcPtr proc,
|
||||||
WarningVec& warnings)
|
WarningVec& warnings)
|
||||||
{
|
{
|
||||||
if (tokens.empty())
|
if (tokens.empty())
|
||||||
@ -256,8 +256,8 @@ factor_2 (Mux::Tokens& tokens, Node::Type& op, ProcPtr proc,
|
|||||||
return factor_1 (tokens, proc, warnings);
|
return factor_1 (tokens, proc, warnings);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Mux::Tree
|
static Mu::Tree
|
||||||
factor_1 (Mux::Tokens& tokens, ProcPtr proc, WarningVec& warnings)
|
factor_1 (Mu::Tokens& tokens, ProcPtr proc, WarningVec& warnings)
|
||||||
{
|
{
|
||||||
Node::Type op { Node::Type::Invalid };
|
Node::Type op { Node::Type::Invalid };
|
||||||
|
|
||||||
@ -275,8 +275,8 @@ factor_1 (Mux::Tokens& tokens, ProcPtr proc, WarningVec& warnings)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Mux::Tree
|
static Mu::Tree
|
||||||
term_2 (Mux::Tokens& tokens, Node::Type& op, ProcPtr proc,
|
term_2 (Mu::Tokens& tokens, Node::Type& op, ProcPtr proc,
|
||||||
WarningVec& warnings)
|
WarningVec& warnings)
|
||||||
{
|
{
|
||||||
if (tokens.empty())
|
if (tokens.empty())
|
||||||
@ -302,8 +302,8 @@ term_2 (Mux::Tokens& tokens, Node::Type& op, ProcPtr proc,
|
|||||||
return term_1 (tokens, proc, warnings);
|
return term_1 (tokens, proc, warnings);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Mux::Tree
|
static Mu::Tree
|
||||||
term_1 (Mux::Tokens& tokens, ProcPtr proc, WarningVec& warnings)
|
term_1 (Mu::Tokens& tokens, ProcPtr proc, WarningVec& warnings)
|
||||||
{
|
{
|
||||||
Node::Type op { Node::Type::Invalid };
|
Node::Type op { Node::Type::Invalid };
|
||||||
|
|
||||||
@ -320,8 +320,8 @@ term_1 (Mux::Tokens& tokens, ProcPtr proc, WarningVec& warnings)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Mux::Tree
|
static Mu::Tree
|
||||||
query (Mux::Tokens& tokens, ProcPtr proc, WarningVec& warnings)
|
query (Mu::Tokens& tokens, ProcPtr proc, WarningVec& warnings)
|
||||||
{
|
{
|
||||||
if (tokens.empty())
|
if (tokens.empty())
|
||||||
return empty ();
|
return empty ();
|
||||||
@ -329,8 +329,8 @@ query (Mux::Tokens& tokens, ProcPtr proc, WarningVec& warnings)
|
|||||||
return term_1 (tokens, proc, warnings);
|
return term_1 (tokens, proc, warnings);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mux::Tree
|
Mu::Tree
|
||||||
Mux::parse (const std::string& expr, WarningVec& warnings, ProcPtr proc)
|
Mu::parse (const std::string& expr, WarningVec& warnings, ProcPtr proc)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
auto tokens = tokenize (expr);
|
auto tokens = tokenize (expr);
|
||||||
|
|||||||
@ -32,7 +32,7 @@
|
|||||||
// A simple recursive-descent parser for queries. Follows the Xapian syntax,
|
// A simple recursive-descent parser for queries. Follows the Xapian syntax,
|
||||||
// but better handles non-alphanum; also implements regexp
|
// but better handles non-alphanum; also implements regexp
|
||||||
|
|
||||||
namespace Mux {
|
namespace Mu {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A parser warning
|
* A parser warning
|
||||||
@ -84,6 +84,6 @@ using ProcPtr = const std::unique_ptr<ProcIface>&;
|
|||||||
Tree parse (const std::string& query, WarningVec& warnings,
|
Tree parse (const std::string& query, WarningVec& warnings,
|
||||||
ProcPtr proc = std::make_unique<DummyProc>());
|
ProcPtr proc = std::make_unique<DummyProc>());
|
||||||
|
|
||||||
} // namespace Mux
|
} // namespace Mu
|
||||||
|
|
||||||
#endif /* __PARSER_HH__ */
|
#endif /* __PARSER_HH__ */
|
||||||
|
|||||||
@ -24,7 +24,7 @@
|
|||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
namespace Mux {
|
namespace Mu {
|
||||||
|
|
||||||
struct ProcIface {
|
struct ProcIface {
|
||||||
|
|
||||||
@ -127,6 +127,6 @@ struct DummyProc: public ProcIface { // For testing
|
|||||||
}; //Dummy
|
}; //Dummy
|
||||||
|
|
||||||
|
|
||||||
} // Mux
|
} // Mu
|
||||||
|
|
||||||
#endif /* __PROC_IFACE_HH__ */
|
#endif /* __PROC_IFACE_HH__ */
|
||||||
|
|||||||
@ -24,7 +24,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "parser.hh"
|
#include "parser.hh"
|
||||||
using namespace Mux;
|
using namespace Mu;
|
||||||
|
|
||||||
struct Case {
|
struct Case {
|
||||||
const std::string expr;
|
const std::string expr;
|
||||||
|
|||||||
@ -26,12 +26,12 @@
|
|||||||
|
|
||||||
struct Case {
|
struct Case {
|
||||||
const char *str;
|
const char *str;
|
||||||
const Mux::Tokens tokens;
|
const Mu::Tokens tokens;
|
||||||
};
|
};
|
||||||
|
|
||||||
using CaseVec = std::vector<Case>;
|
using CaseVec = std::vector<Case>;
|
||||||
|
|
||||||
using namespace Mux;
|
using namespace Mu;
|
||||||
using TT = Token::Type;
|
using TT = Token::Type;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
@ -30,7 +30,7 @@ main (int argc, char *argv[])
|
|||||||
for (auto i = 1; i < argc; ++i)
|
for (auto i = 1; i < argc; ++i)
|
||||||
s += " " + std::string(argv[i]);
|
s += " " + std::string(argv[i]);
|
||||||
|
|
||||||
const auto tvec = Mux::tokenize (s);
|
const auto tvec = Mu::tokenize (s);
|
||||||
for (const auto& t : tvec)
|
for (const auto& t : tvec)
|
||||||
std::cout << t << std::endl;
|
std::cout << t << std::endl;
|
||||||
|
|
||||||
|
|||||||
@ -18,13 +18,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "tokenizer.hh"
|
#include "tokenizer.hh"
|
||||||
#include "utils.hh"
|
#include "utils/mu-utils.hh"
|
||||||
|
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
using namespace Mux;
|
using namespace Mu;
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
is_separator (char c)
|
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)
|
op_or_value (size_t pos, const std::string& val)
|
||||||
{
|
{
|
||||||
auto s = val;
|
auto s = val;
|
||||||
@ -62,7 +62,7 @@ unread_char (std::string& food, char kar, size_t& pos)
|
|||||||
--pos;
|
--pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Mux::Token
|
static Mu::Token
|
||||||
eat_token (std::string& food, size_t& pos)
|
eat_token (std::string& food, size_t& pos)
|
||||||
{
|
{
|
||||||
bool quoted{};
|
bool quoted{};
|
||||||
@ -115,8 +115,8 @@ eat_token (std::string& food, size_t& pos)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Mux::Tokens
|
Mu::Tokens
|
||||||
Mux::tokenize (const std::string& s)
|
Mu::tokenize (const std::string& s)
|
||||||
{
|
{
|
||||||
Tokens tokens{};
|
Tokens tokens{};
|
||||||
|
|
||||||
|
|||||||
@ -36,7 +36,7 @@
|
|||||||
// Furthermore, we detect ranges ("a..b") and regexps (/../) at the parser level, since we need a
|
// Furthermore, we detect ranges ("a..b") and regexps (/../) at the parser level, since we need a
|
||||||
// bit more context to resolve ambiguities.
|
// bit more context to resolve ambiguities.
|
||||||
|
|
||||||
namespace Mux {
|
namespace Mu {
|
||||||
|
|
||||||
// A token
|
// A token
|
||||||
struct Token {
|
struct Token {
|
||||||
@ -135,6 +135,6 @@ operator<< (std::ostream& os, const Token& t)
|
|||||||
using Tokens = std::deque<Token>;
|
using Tokens = std::deque<Token>;
|
||||||
Tokens tokenize (const std::string& s);
|
Tokens tokenize (const std::string& s);
|
||||||
|
|
||||||
} // namespace Mux
|
} // namespace Mu
|
||||||
|
|
||||||
#endif /* __TOKENIZER_HH__ */
|
#endif /* __TOKENIZER_HH__ */
|
||||||
|
|||||||
@ -17,13 +17,16 @@
|
|||||||
** 02110-1301, USA.
|
** 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef TREE_HH__
|
||||||
|
#define TREE_HH__
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <parser/data.hh>
|
#include <parser/data.hh>
|
||||||
|
|
||||||
namespace Mux {
|
namespace Mu {
|
||||||
|
|
||||||
// A node in the parse tree
|
// A node in the parse tree
|
||||||
struct Node {
|
struct Node {
|
||||||
@ -101,4 +104,7 @@ operator<< (std::ostream& os, const Tree& tree)
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Mux
|
} // namespace Mu
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* TREE_HH__ */
|
||||||
|
|||||||
@ -24,10 +24,10 @@
|
|||||||
#include <xapian.h>
|
#include <xapian.h>
|
||||||
#include "parser/xapian.hh"
|
#include "parser/xapian.hh"
|
||||||
|
|
||||||
using namespace Mux;
|
using namespace Mu;
|
||||||
|
|
||||||
static Xapian::Query
|
static Xapian::Query
|
||||||
xapian_query_op (const Mux::Tree& tree)
|
xapian_query_op (const Mu::Tree& tree)
|
||||||
{
|
{
|
||||||
Xapian::Query::op op;
|
Xapian::Query::op op;
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ make_query (const Value* val, const std::string& str, bool maybe_wildcard)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Xapian::Query
|
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());
|
const auto v = dynamic_cast<Value*> (tree.node.data.get());
|
||||||
if (!v->phrase)
|
if (!v->phrase)
|
||||||
@ -89,7 +89,7 @@ xapian_query_value (const Mux::Tree& tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Xapian::Query
|
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()) };
|
const auto r { dynamic_cast<Range *>(tree.node.data.get()) };
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ xapian_query_range (const Mux::Tree& tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Xapian::Query
|
Xapian::Query
|
||||||
Mux::xapian_query (const Mux::Tree& tree)
|
Mu::xapian_query (const Mu::Tree& tree)
|
||||||
{
|
{
|
||||||
switch (tree.node.type) {
|
switch (tree.node.type) {
|
||||||
case Node::Type::Empty:
|
case Node::Type::Empty:
|
||||||
|
|||||||
@ -24,7 +24,7 @@
|
|||||||
#include <xapian.h>
|
#include <xapian.h>
|
||||||
#include <parser/parser.hh>
|
#include <parser/parser.hh>
|
||||||
|
|
||||||
namespace Mux {
|
namespace Mu {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transform a parse-tree into a Xapian query object
|
* Transform a parse-tree into a Xapian query object
|
||||||
@ -33,8 +33,8 @@ namespace Mux {
|
|||||||
*
|
*
|
||||||
* @return a Xapian query object
|
* @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__ */
|
#endif /* __XAPIAN_H__ */
|
||||||
|
|||||||
@ -43,7 +43,9 @@ libmu_utils_la_SOURCES= \
|
|||||||
mu-str.c \
|
mu-str.c \
|
||||||
mu-str.h \
|
mu-str.h \
|
||||||
mu-util.c \
|
mu-util.c \
|
||||||
mu-util.h
|
mu-util.h \
|
||||||
|
mu-utils.cc \
|
||||||
|
mu-utils.hh
|
||||||
|
|
||||||
libmu_utils_la_LIBADD= \
|
libmu_utils_la_LIBADD= \
|
||||||
$(GLIB_LIBS)
|
$(GLIB_LIBS)
|
||||||
@ -61,6 +63,13 @@ test_mu_util_SOURCES= \
|
|||||||
test_mu_util_LDADD= \
|
test_mu_util_LDADD= \
|
||||||
libmu-utils.la
|
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_PROGS+= \
|
||||||
test-mu-str
|
test-mu-str
|
||||||
test_mu_str_SOURCES= \
|
test_mu_str_SOURCES= \
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
** 02110-1301, USA.
|
** 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#define _XOPEN_SOURCE
|
#define _XOPEN_SOURCE
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
@ -24,8 +25,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "utils.hh"
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -33,7 +32,10 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <glib/gprintf.h>
|
#include <glib/gprintf.h>
|
||||||
|
|
||||||
using namespace Mux;
|
#include "mu-utils.hh"
|
||||||
|
|
||||||
|
|
||||||
|
using namespace Mu;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@ -100,7 +102,7 @@ gx_utf8_flatten (const gchar *str, gssize len)
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
std::string // gx_utf8_flatten
|
std::string // gx_utf8_flatten
|
||||||
Mux::utf8_flatten (const char *str)
|
Mu::utf8_flatten (const char *str)
|
||||||
{
|
{
|
||||||
if (!str)
|
if (!str)
|
||||||
return {};
|
return {};
|
||||||
@ -125,7 +127,7 @@ Mux::utf8_flatten (const char *str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
Mux::utf8_clean (const std::string& dirty)
|
Mu::utf8_clean (const std::string& dirty)
|
||||||
{
|
{
|
||||||
GString *gstr = g_string_sized_new (dirty.length());
|
GString *gstr = g_string_sized_new (dirty.length());
|
||||||
|
|
||||||
@ -148,7 +150,7 @@ Mux::utf8_clean (const std::string& dirty)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string>
|
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);
|
char **parts = g_strsplit(str.c_str(), sepa.c_str(), -1);
|
||||||
std::vector<std::string> vec;
|
std::vector<std::string> vec;
|
||||||
@ -161,7 +163,7 @@ Mux::split (const std::string& str, const std::string& sepa)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
Mux::quote (const std::string& str)
|
Mu::quote (const std::string& str)
|
||||||
{
|
{
|
||||||
char *s = g_strescape (str.c_str(), NULL);
|
char *s = g_strescape (str.c_str(), NULL);
|
||||||
if (!s)
|
if (!s)
|
||||||
@ -174,7 +176,7 @@ Mux::quote (const std::string& str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
Mux::format (const char *frm, ...)
|
Mu::format (const char *frm, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
@ -207,7 +209,7 @@ date_boundary (bool is_first)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
Mux::date_to_time_t_string (int64_t t)
|
Mu::date_to_time_t_string (int64_t t)
|
||||||
{
|
{
|
||||||
char buf[sizeof(InternalDateMax)];
|
char buf[sizeof(InternalDateMax)];
|
||||||
snprintf (buf, sizeof(buf), InternalDateFormat, t);
|
snprintf (buf, sizeof(buf), InternalDateFormat, t);
|
||||||
@ -319,7 +321,7 @@ fixup_month (struct tm *tbuf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
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;
|
gint64 t;
|
||||||
struct tm tbuf;
|
struct tm tbuf;
|
||||||
@ -385,7 +387,7 @@ size_boundary (bool is_first)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
Mux::size_to_string (int64_t size)
|
Mu::size_to_string (int64_t size)
|
||||||
{
|
{
|
||||||
char buf[sizeof(SizeMax)];
|
char buf[sizeof(SizeMax)];
|
||||||
snprintf (buf, sizeof(buf), SizeFormat, size);
|
snprintf (buf, sizeof(buf), SizeFormat, size);
|
||||||
@ -394,7 +396,7 @@ Mux::size_to_string (int64_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
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;
|
std::string str;
|
||||||
GRegex *rx;
|
GRegex *rx;
|
||||||
@ -17,13 +17,14 @@
|
|||||||
** 02110-1301, USA.
|
** 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef __MU_UTILS_HH__
|
||||||
|
#define __MU_UTILS_HH__
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <cstdarg>
|
||||||
|
|
||||||
#ifndef __UTILS_HH__
|
namespace Mu {
|
||||||
#define __UTILS_HH__
|
|
||||||
|
|
||||||
namespace Mux {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flatten a string -- downcase and fold diacritics etc.
|
* Flatten a string -- downcase and fold diacritics etc.
|
||||||
@ -75,8 +76,19 @@ std::string quote (const std::string& str);
|
|||||||
*
|
*
|
||||||
* @return a formatted string
|
* @return a formatted string
|
||||||
*/
|
*/
|
||||||
std::string format (const char *frm, ...)
|
std::string format (const char *frm, ...) __attribute__((format(printf, 1, 2)));
|
||||||
__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
|
* 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);
|
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 <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
#include "parser.hh"
|
#include "mu-utils.hh"
|
||||||
using namespace Mux;
|
|
||||||
|
using namespace Mu;
|
||||||
|
|
||||||
struct Case {
|
struct Case {
|
||||||
const std::string expr;
|
const std::string expr;
|
||||||
@ -95,7 +97,7 @@ test_date_ymwdhMs (void)
|
|||||||
|
|
||||||
for (auto i = 0; i != G_N_ELEMENTS(tests); ++i) {
|
for (auto i = 0; i != G_N_ELEMENTS(tests); ++i) {
|
||||||
const auto diff = time(NULL) -
|
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);
|
NULL, 10);
|
||||||
if (g_test_verbose())
|
if (g_test_verbose())
|
||||||
std::cerr << tests[i].expr << ' '
|
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 (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);
|
NULL, 10) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +65,6 @@ mu-help-strings.h: mu-help-strings.txt mu-help-strings.awk
|
|||||||
|
|
||||||
mu_LDADD= \
|
mu_LDADD= \
|
||||||
${top_builddir}/lib/libmu.la \
|
${top_builddir}/lib/libmu.la \
|
||||||
${top_builddir}/lib/parser/libmuxparser.la \
|
|
||||||
$(GLIB_LIBS)
|
$(GLIB_LIBS)
|
||||||
|
|
||||||
EXTRA_DIST= \
|
EXTRA_DIST= \
|
||||||
|
|||||||
Reference in New Issue
Block a user