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();
|
||||
|
@ -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 = \
|
||||
@ -104,7 +106,7 @@ test_qofsession_LDADD = \
|
||||
$(top_builddir)/$(MODULEPATH)/libgnc-qof.la \
|
||||
$(GLIB_LIBS) \
|
||||
$(GTEST_LIBS) \
|
||||
$(BOOST_LDFLAGS)
|
||||
$(BOOST_LDFLAGS) -lboost_regex
|
||||
|
||||
if !GOOGLE_TEST_LIBS
|
||||
nodist_test_qofsession_SOURCES = \
|
||||
@ -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
|
||||
@ -171,10 +175,12 @@ 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 = \
|
||||
|
Loading…
Reference in New Issue
Block a user