mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Replace std::regex with boost::regex.
Gcc's std::regex compiler doesn't correctly recognize capture blocks.
This commit is contained in:
parent
b60d6a8466
commit
d0726de391
@ -95,7 +95,7 @@ ADD_LIBRARY (gnc-qof
|
||||
${gnc_qof_noinst_HEADERS}
|
||||
)
|
||||
|
||||
TARGET_LINK_LIBRARIES(gnc-qof ${Boost_DATE_TIME_LIBRARIES} ${REGEX_LDFLAGS} ${GMODULE_LDFLAGS} ${GLIB2_LDFLAGS} ${GOBJECT_LDFLAGS})
|
||||
TARGET_LINK_LIBRARIES(gnc-qof ${Boost_DATE_TIME_LIBRARIES} ${Boost_REGEX_LIBRARIES} ${REGEX_LDFLAGS} ${GMODULE_LDFLAGS} ${GLIB2_LDFLAGS} ${GOBJECT_LDFLAGS})
|
||||
|
||||
TARGET_COMPILE_DEFINITIONS (gnc-qof PRIVATE -DG_LOG_DOMAIN=\"qof\")
|
||||
|
||||
|
@ -11,6 +11,7 @@ libgnc_qof_la_LDFLAGS= \
|
||||
libgnc_qof_common_libs = \
|
||||
$(GLIB_LIBS) \
|
||||
$(REGEX_LIBS) \
|
||||
${BOOST_LDFLAGS} -lboost_regex \
|
||||
$(top_builddir)/lib/libc/libc-missing.la
|
||||
|
||||
libgnc_qof_la_LIBADD = $(libgnc_qof_common_libs)
|
||||
|
@ -36,7 +36,7 @@ extern "C"
|
||||
}
|
||||
|
||||
#include <stdint.h>
|
||||
#include <regex>
|
||||
#include <boost/regex.hpp>
|
||||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
|
||||
@ -103,6 +103,9 @@ GncNumeric::GncNumeric(double d) : m_num(0), m_den(1)
|
||||
m_den = r.denom();
|
||||
}
|
||||
|
||||
using boost::regex;
|
||||
using boost::smatch;
|
||||
using boost::regex_search;
|
||||
GncNumeric::GncNumeric(const std::string& str, bool autoround)
|
||||
{
|
||||
static const std::string numer_frag("(-?[0-9]+)");
|
||||
@ -113,26 +116,21 @@ GncNumeric::GncNumeric(const std::string& str, bool autoround)
|
||||
* numer_frag patter with the default ECMAScript syntax so we use the awk
|
||||
* syntax.
|
||||
*/
|
||||
static const std::regex numeral(numer_frag, std::regex::awk);
|
||||
static const std::regex hex(hex_frag, std::regex::awk);
|
||||
static const std::regex numeral_rational(numer_frag + slash + denom_frag,
|
||||
std::regex::awk);
|
||||
static const std::regex hex_rational(hex_frag + slash + hex_frag,
|
||||
std::regex::awk);
|
||||
static const std::regex hex_over_num(hex_frag + slash + denom_frag,
|
||||
std::regex::awk);
|
||||
static const std::regex num_over_hex(numer_frag + slash + hex_frag,
|
||||
std::regex::awk);
|
||||
static const std::regex decimal(numer_frag + "[.,]" + denom_frag,
|
||||
std::regex::awk);
|
||||
std::smatch m;
|
||||
static const regex numeral(numer_frag);
|
||||
static const regex hex(hex_frag);
|
||||
static const regex numeral_rational(numer_frag + slash + denom_frag);
|
||||
static const regex hex_rational(hex_frag + slash + hex_frag);
|
||||
static const regex hex_over_num(hex_frag + slash + denom_frag);
|
||||
static const regex num_over_hex(numer_frag + slash + hex_frag);
|
||||
static const regex decimal(numer_frag + "[.,]" + denom_frag);
|
||||
smatch m;
|
||||
/* The order of testing the regexes is from the more restrictve to the less
|
||||
* restrictive, as less-restrictive ones will match patterns that would also
|
||||
* match the more-restrictive and so invoke the wrong construction.
|
||||
*/
|
||||
if (str.empty())
|
||||
throw std::invalid_argument("Can't construct a GncNumeric from an empty string.");
|
||||
if (std::regex_search(str, m, hex_rational))
|
||||
if (regex_search(str, m, hex_rational))
|
||||
{
|
||||
GncNumeric n(stoll(m[1].str(), nullptr, 16),
|
||||
stoll(m[2].str(), nullptr, 16));
|
||||
@ -140,7 +138,7 @@ GncNumeric::GncNumeric(const std::string& str, bool autoround)
|
||||
m_den = n.denom();
|
||||
return;
|
||||
}
|
||||
if (std::regex_search(str, m, hex_over_num))
|
||||
if (regex_search(str, m, hex_over_num))
|
||||
{
|
||||
GncNumeric n(stoll(m[1].str(), nullptr, 16),
|
||||
stoll(m[2].str()));
|
||||
@ -148,7 +146,7 @@ GncNumeric::GncNumeric(const std::string& str, bool autoround)
|
||||
m_den = n.denom();
|
||||
return;
|
||||
}
|
||||
if (std::regex_search(str, m, num_over_hex))
|
||||
if (regex_search(str, m, num_over_hex))
|
||||
{
|
||||
GncNumeric n(stoll(m[1].str()),
|
||||
stoll(m[2].str(), nullptr, 16));
|
||||
@ -156,14 +154,14 @@ GncNumeric::GncNumeric(const std::string& str, bool autoround)
|
||||
m_den = n.denom();
|
||||
return;
|
||||
}
|
||||
if (std::regex_search(str, m, numeral_rational))
|
||||
if (regex_search(str, m, numeral_rational))
|
||||
{
|
||||
GncNumeric n(stoll(m[1].str()), stoll(m[2].str()));
|
||||
m_num = n.num();
|
||||
m_den = n.denom();
|
||||
return;
|
||||
}
|
||||
if (std::regex_search(str, m, decimal))
|
||||
if (regex_search(str, m, decimal))
|
||||
{
|
||||
GncInt128 high(stoll(m[1].str()));
|
||||
GncInt128 low(stoll(m[2].str()));
|
||||
@ -193,14 +191,14 @@ GncNumeric::GncNumeric(const std::string& str, bool autoround)
|
||||
m_den = gncn.denom();
|
||||
return;
|
||||
}
|
||||
if (std::regex_search(str, m, hex))
|
||||
if (regex_search(str, m, hex))
|
||||
{
|
||||
GncNumeric n(stoll(m[1].str(), nullptr, 16),INT64_C(1));
|
||||
m_num = n.num();
|
||||
m_den = n.denom();
|
||||
return;
|
||||
}
|
||||
if (std::regex_search(str, m, numeral))
|
||||
if (regex_search(str, m, numeral))
|
||||
{
|
||||
GncNumeric n(stoll(m[1].str()), INT64_C(1));
|
||||
m_num = n.num();
|
||||
|
@ -9,21 +9,21 @@ include $(top_srcdir)/test-templates/Makefile.decl
|
||||
MODULEPATH = src/libqof/qof
|
||||
|
||||
test_qof_SOURCES = \
|
||||
test-gnc-date.c \
|
||||
test-qof.c \
|
||||
test-qofbook.c \
|
||||
test-qofinstance.cpp \
|
||||
test-qofobject.c \
|
||||
test-qof-string-cache.c \
|
||||
${top_srcdir}/src/test-core/unittest-support.c
|
||||
test-gnc-date.c \
|
||||
test-qof.c \
|
||||
test-qofbook.c \
|
||||
test-qofinstance.cpp \
|
||||
test-qofobject.c \
|
||||
test-qof-string-cache.c \
|
||||
${top_srcdir}/src/test-core/unittest-support.c
|
||||
|
||||
test_qof_HEADERS = \
|
||||
$(top_srcdir)/${MODULEPATH}/qofbook.h \
|
||||
$(top_srcdir)/${MODULEPATH}/qofinstance.h \
|
||||
$(top_srcdir)/${MODULEPATH}/kvp_frame.hpp \
|
||||
$(top_srcdir)/${MODULEPATH}/qofobject.h \
|
||||
$(top_srcdir)/${MODULEPATH}/qofsession.h \
|
||||
$(top_srcdir)/src/test-core/unittest-support.h
|
||||
$(top_srcdir)/${MODULEPATH}/qofbook.h \
|
||||
$(top_srcdir)/${MODULEPATH}/qofinstance.h \
|
||||
$(top_srcdir)/${MODULEPATH}/kvp_frame.hpp \
|
||||
$(top_srcdir)/${MODULEPATH}/qofobject.h \
|
||||
$(top_srcdir)/${MODULEPATH}/qofsession.h \
|
||||
$(top_srcdir)/src/test-core/unittest-support.h
|
||||
|
||||
test_numeric_SOURCES = \
|
||||
${top_srcdir}/src/engine/cashobjects.c \
|
||||
@ -40,11 +40,13 @@ test_numeric_CPPFLAGS = \
|
||||
-I${top_srcdir}/src/engine/test-core \
|
||||
-I${top_srcdir}/src \
|
||||
-I${top_srcdir}/${MODULEPATH} \
|
||||
${BOOST_CPPFLAGS} \
|
||||
${GLIB_CFLAGS}
|
||||
|
||||
test_numeric_LDADD = \
|
||||
${top_builddir}/src/engine/libgncmod-engine.la \
|
||||
${top_builddir}/${MODULEPATH}/libgnc-qof.la \
|
||||
${BOOST_LDFLAGS} -lboost_regex \
|
||||
${GLIB_LIBS}
|
||||
|
||||
check_PROGRAMS = \
|
||||
@ -54,13 +56,13 @@ check_PROGRAMS = \
|
||||
TESTS = ${check_PROGRAMS}
|
||||
|
||||
test_gnc_guid_SOURCES = \
|
||||
$(top_srcdir)/$(MODULEPATH)/guid.cpp \
|
||||
test-gnc-guid.cpp
|
||||
$(top_srcdir)/$(MODULEPATH)/guid.cpp \
|
||||
test-gnc-guid.cpp
|
||||
test_gnc_guid_LDADD = \
|
||||
$(top_builddir)/$(MODULEPATH)/libgnc-qof.la \
|
||||
$(top_builddir)/$(MODULEPATH)/libgnc-qof.la \
|
||||
$(GLIB_LIBS) \
|
||||
$(GTEST_LIBS) \
|
||||
$(BOOST_LDFLAGS)
|
||||
$(GTEST_LIBS) \
|
||||
$(BOOST_LDFLAGS)
|
||||
if !GOOGLE_TEST_LIBS
|
||||
nodist_test_gnc_guid_SOURCES = \
|
||||
${GTEST_SRC}/src/gtest_main.cc
|
||||
@ -79,10 +81,10 @@ test_kvp_value_SOURCES = \
|
||||
test-kvp-value.cpp \
|
||||
test-kvp-frame.cpp
|
||||
test_kvp_value_LDADD = \
|
||||
$(top_builddir)/$(MODULEPATH)/libgnc-qof.la \
|
||||
$(top_builddir)/$(MODULEPATH)/libgnc-qof.la \
|
||||
$(GLIB_LIBS) \
|
||||
$(GTEST_LIBS) \
|
||||
$(BOOST_LDFLAGS)
|
||||
$(GTEST_LIBS) \
|
||||
$(BOOST_LDFLAGS)
|
||||
|
||||
if !GOOGLE_TEST_LIBS
|
||||
nodist_test_kvp_value_SOURCES = \
|
||||
@ -98,24 +100,24 @@ test_kvp_value_CPPFLAGS = \
|
||||
check_PROGRAMS += test-kvp-value
|
||||
|
||||
test_qofsession_SOURCES = \
|
||||
$(top_srcdir)/$(MODULEPATH)/qofsession.cpp \
|
||||
test-qofsession.cpp
|
||||
$(top_srcdir)/$(MODULEPATH)/qofsession.cpp \
|
||||
test-qofsession.cpp
|
||||
test_qofsession_LDADD = \
|
||||
$(top_builddir)/$(MODULEPATH)/libgnc-qof.la \
|
||||
$(GLIB_LIBS) \
|
||||
$(GTEST_LIBS) \
|
||||
$(BOOST_LDFLAGS)
|
||||
$(top_builddir)/$(MODULEPATH)/libgnc-qof.la \
|
||||
$(GLIB_LIBS) \
|
||||
$(GTEST_LIBS) \
|
||||
$(BOOST_LDFLAGS) -lboost_regex
|
||||
|
||||
if !GOOGLE_TEST_LIBS
|
||||
nodist_test_qofsession_SOURCES = \
|
||||
${GTEST_SRC}/src/gtest_main.cc
|
||||
${GTEST_SRC}/src/gtest_main.cc
|
||||
endif
|
||||
|
||||
test_qofsession_CPPFLAGS = \
|
||||
-I$(GTEST_HEADERS) \
|
||||
-I$(top_srcdir)/$(MODULEPATH) \
|
||||
$(GLIB_CFLAGS) \
|
||||
$(BOOST_CPPFLAGS)
|
||||
-I$(GTEST_HEADERS) \
|
||||
-I$(top_srcdir)/$(MODULEPATH) \
|
||||
$(GLIB_CFLAGS) \
|
||||
$(BOOST_CPPFLAGS)
|
||||
|
||||
check_PROGRAMS += test-qofsession
|
||||
|
||||
@ -135,9 +137,9 @@ test_gnc_rational_SOURCES = \
|
||||
$(top_srcdir)/${MODULEPATH}/gnc-rational.cpp \
|
||||
$(top_srcdir)/${MODULEPATH}/gnc-numeric.cpp \
|
||||
$(top_srcdir)/${MODULEPATH}/gnc-int128.cpp \
|
||||
$(top_srcdir)/$(MODULEPATH)/gnc-datetime.cpp \
|
||||
$(top_srcdir)/$(MODULEPATH)/gnc-timezone.cpp \
|
||||
$(top_srcdir)/$(MODULEPATH)/gnc-date.cpp \
|
||||
$(top_srcdir)/$(MODULEPATH)/gnc-datetime.cpp \
|
||||
$(top_srcdir)/$(MODULEPATH)/gnc-timezone.cpp \
|
||||
$(top_srcdir)/$(MODULEPATH)/gnc-date.cpp \
|
||||
$(top_srcdir)/${MODULEPATH}/qoflog.cpp \
|
||||
gtest-gnc-rational.cpp
|
||||
|
||||
@ -145,10 +147,12 @@ test_gnc_rational_CPPFLAGS = \
|
||||
-I${top_srcdir}/src \
|
||||
-I${top_srcdir}/src/libqof/qof \
|
||||
-I${GTEST_HEADERS} \
|
||||
${BOOST_CPPFLAGS} \
|
||||
${GLIB_CFLAGS}
|
||||
|
||||
test_gnc_rational_LDADD = \
|
||||
${GTEST_LIBS} \
|
||||
${BOOST_LDFLAGS} -lboost_regex \
|
||||
${GLIB_LIBS}
|
||||
|
||||
if !GOOGLE_TEST_LIBS
|
||||
@ -162,19 +166,21 @@ test_gnc_numeric_SOURCES = \
|
||||
$(top_srcdir)/${MODULEPATH}/gnc-rational.cpp \
|
||||
$(top_srcdir)/${MODULEPATH}/gnc-int128.cpp \
|
||||
$(top_srcdir)/${MODULEPATH}/gnc-numeric.cpp \
|
||||
$(top_srcdir)/$(MODULEPATH)/gnc-datetime.cpp \
|
||||
$(top_srcdir)/$(MODULEPATH)/gnc-timezone.cpp \
|
||||
$(top_srcdir)/$(MODULEPATH)/gnc-date.cpp \
|
||||
$(top_srcdir)/$(MODULEPATH)/gnc-datetime.cpp \
|
||||
$(top_srcdir)/$(MODULEPATH)/gnc-timezone.cpp \
|
||||
$(top_srcdir)/$(MODULEPATH)/gnc-date.cpp \
|
||||
$(top_srcdir)/${MODULEPATH}/qoflog.cpp \
|
||||
gtest-gnc-numeric.cpp
|
||||
test_gnc_numeric_CPPFLAGS = \
|
||||
-I${top_srcdir}/src \
|
||||
-I${top_srcdir}/src/libqof/qof \
|
||||
-I${GTEST_HEADERS} \
|
||||
${BOOST_CPPFLAGS} \
|
||||
${GLIB_CFLAGS}
|
||||
|
||||
test_gnc_numeric_LDADD = \
|
||||
${GTEST_LIBS} \
|
||||
${BOOST_LDFLAGS} -lboost_regex \
|
||||
${GLIB_LIBS}
|
||||
if !GOOGLE_TEST_LIBS
|
||||
nodist_test_gnc_numeric_SOURCES = \
|
||||
@ -189,13 +195,13 @@ test_gnc_timezone_SOURCES = \
|
||||
test_gnc_timezone_CPPFLAGS = \
|
||||
-I${GTEST_HEADERS} \
|
||||
-I$(top_srcdir)/$(MODULEPATH) \
|
||||
-I${top_srcdir}/src \
|
||||
-I${top_srcdir}/src \
|
||||
$(GLIB_CFLAGS) \
|
||||
$(BOOST_CPPFLAGS)
|
||||
$(BOOST_CPPFLAGS)
|
||||
|
||||
test_gnc_timezone_LDADD = \
|
||||
${top_builddir}/${MODULEPATH}/libgnc-qof.la \
|
||||
$(GLIB_LIBS) \
|
||||
${top_builddir}/${MODULEPATH}/libgnc-qof.la \
|
||||
$(GLIB_LIBS) \
|
||||
$(GTEST_LIBS)
|
||||
if !GOOGLE_TEST_LIBS
|
||||
nodist_test_gnc_timezone_SOURCES = \
|
||||
@ -204,24 +210,24 @@ endif
|
||||
check_PROGRAMS += test-gnc-timezone
|
||||
|
||||
test_gnc_datetime_SOURCES = \
|
||||
$(top_srcdir)/$(MODULEPATH)/gnc-datetime.cpp \
|
||||
$(top_srcdir)/$(MODULEPATH)/gnc-timezone.cpp \
|
||||
gtest-gnc-datetime.cpp
|
||||
$(top_srcdir)/$(MODULEPATH)/gnc-datetime.cpp \
|
||||
$(top_srcdir)/$(MODULEPATH)/gnc-timezone.cpp \
|
||||
gtest-gnc-datetime.cpp
|
||||
test_gnc_datetime_CPPFLAGS =\
|
||||
-I$(GTEST_HEADERS) \
|
||||
-I$(GTEST_HEADERS) \
|
||||
-I$(top_srcdir)/$(MODULEPATH) \
|
||||
-I$(top_srcdir)/src \
|
||||
-I$(top_srcdir)/src \
|
||||
$(GLIB_CFLAGS) \
|
||||
$(BOOST_CPPFLAGS)
|
||||
$(BOOST_CPPFLAGS)
|
||||
|
||||
test_gnc_datetime_LDADD = \
|
||||
-lboost_date_time \
|
||||
${top_builddir}/${MODULEPATH}/libgnc-qof.la \
|
||||
$(GLIB_LIBS) \
|
||||
$(GTEST_LIBS)
|
||||
-lboost_date_time \
|
||||
${top_builddir}/${MODULEPATH}/libgnc-qof.la \
|
||||
$(GLIB_LIBS) \
|
||||
$(GTEST_LIBS)
|
||||
if !GOOGLE_TEST_LIBS
|
||||
nodist_test_gnc_datetime_SOURCES = \
|
||||
$(GTEST_SRC)/src/gtest_main.cc
|
||||
$(GTEST_SRC)/src/gtest_main.cc
|
||||
endif
|
||||
check_PROGRAMS += test-gnc-datetime
|
||||
|
||||
@ -231,13 +237,13 @@ test_qofdir = ${GNC_LIBEXECDIR}/${MODULEPATH}/test
|
||||
#The tests might require more libraries, but try to keep them
|
||||
#as independent as possible.
|
||||
test_qof_LDADD = \
|
||||
${top_builddir}/${MODULEPATH}/libgnc-qof.la \
|
||||
$(GLIB_LIBS)
|
||||
${top_builddir}/${MODULEPATH}/libgnc-qof.la \
|
||||
$(GLIB_LIBS)
|
||||
|
||||
test_qof_CPPFLAGS = \
|
||||
${DEFAULT_INCLUDES} \
|
||||
-I$(top_srcdir)/${MODULEPATH} \
|
||||
-I$(top_srcdir)/src/test-core \
|
||||
-DTESTPROG=test_qof \
|
||||
-I$(top_srcdir)/lib/libc \
|
||||
${GLIB_CFLAGS}
|
||||
${DEFAULT_INCLUDES} \
|
||||
-I$(top_srcdir)/${MODULEPATH} \
|
||||
-I$(top_srcdir)/src/test-core \
|
||||
-DTESTPROG=test_qof \
|
||||
-I$(top_srcdir)/lib/libc \
|
||||
${GLIB_CFLAGS}
|
||||
|
Loading…
Reference in New Issue
Block a user