From 8ffab2f002672ab3e9228cfb6277feb3d899401d Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 24 Jun 2019 02:41:02 +0200 Subject: [PATCH] Dependencies: get rid of boost-regexp (see #995) Mostly, std::regexp can be used as a drop-in replacement. Note: unfortunately ECMA regexps do not support lookbehind assertions. This lookbehind is necesary here because we want to allow parsing values from strings with additional content, which means we need explicitly to exclude mismatches due to invalid syntax. We can work around that issue like "either line start, or *not* one of these characters. Alternatively we could consider to make the match more rigid, i.e we would require the string to conain *only* the timecode spec to be parsed. --- admin/scons/Platform.py | 2 -- ...Dependencies.txt => BuildDependencies.txt} | 5 ++--- doc/technical/build/index.txt | 4 ++-- src/common/advice/binding.cpp | 10 ++++----- src/lib/cmdline.cpp | 17 +++++++-------- src/lib/cmdline.hpp | 1 + src/lib/query-util.cpp | 21 ++++++++++--------- src/lib/searchpath.cpp | 4 +++- src/lib/searchpath.hpp | 14 +++++-------- src/lib/time/timecode.cpp | 18 ++++++++-------- src/steam/asset/media.cpp | 12 +++++------ tests/basics/time/time-parsing-test.cpp | 1 + 12 files changed, 53 insertions(+), 56 deletions(-) rename doc/technical/build/{Dependencies.txt => BuildDependencies.txt} (98%) diff --git a/admin/scons/Platform.py b/admin/scons/Platform.py index 8060c4630..3da22293f 100644 --- a/admin/scons/Platform.py +++ b/admin/scons/Platform.py @@ -92,8 +92,6 @@ def configure(env): problems.append('We need the boost::system support library (including binary lib).') if not conf.CheckLibWithHeader('boost_filesystem','boost/filesystem.hpp','C++'): problems.append('We need the boost::filesystem lib (including binary lib for linking).') - if not conf.CheckLibWithHeader('boost_regex','boost/regex.hpp','C++'): - problems.append('We need the boost regular expression lib (incl. binary lib for linking).') if not conf.CheckPkgConfig('gavl', '1.4'): diff --git a/doc/technical/build/Dependencies.txt b/doc/technical/build/BuildDependencies.txt similarity index 98% rename from doc/technical/build/Dependencies.txt rename to doc/technical/build/BuildDependencies.txt index 29b6b16c1..de350c20d 100644 --- a/doc/technical/build/Dependencies.txt +++ b/doc/technical/build/BuildDependencies.txt @@ -1,5 +1,5 @@ -Dependencies -============ +Build Dependencies +================== :Author: core-devs :Date: 11/2015 :toc: @@ -66,7 +66,6 @@ Languages and Tools - libboost-program-options-dev - libboost-program-options-dev - libboost-filesystem-dev - - libboost-regex-dev * Script languages - Python (*2.7*) for build scripts diff --git a/doc/technical/build/index.txt b/doc/technical/build/index.txt index 41a7dd76d..a6a2437b8 100644 --- a/doc/technical/build/index.txt +++ b/doc/technical/build/index.txt @@ -4,14 +4,14 @@ Lumiera build system As work progresses, we will add more information on the Lumiera build system. //Menu: label Build System -//Menu: prepend child 'Dependencies' +//Menu: prepend child 'BuildDependencies' //Menu: prepend child 'SCons' build -- continuous integration -- packaging * link:SCons.html[Buildsystem] -* link:Dependencies.html[Dependencies] +* link:BuildDependencies.html[Lumiera Build Dependencies] * link:BuildDroneDraft.html[»Builddrone« concept from 2008] * Packaging: link:LumieraDebianPackage.html[Debian] RPM * Lumiera link:../infra/debianDepot.html/[debian depot] diff --git a/src/common/advice/binding.cpp b/src/common/advice/binding.cpp index 88c1f87f4..159948333 100644 --- a/src/common/advice/binding.cpp +++ b/src/common/advice/binding.cpp @@ -36,16 +36,16 @@ #include #include -#include +#include using lib::Literal; using util::isnil; -using boost::regex; -using boost::smatch; -using boost::sregex_iterator; -using boost::match_continuous; +using std::regex; +using std::smatch; +using std::sregex_iterator; +using std::regex_constants::match_continuous; using boost::hash_combine; using boost::lexical_cast; diff --git a/src/lib/cmdline.cpp b/src/lib/cmdline.cpp index 1d3015fc7..a0125562f 100644 --- a/src/lib/cmdline.cpp +++ b/src/lib/cmdline.cpp @@ -30,15 +30,14 @@ #include "lib/util.hpp" #include "include/logging.h" #include "lib/cmdline.hpp" +#include "lib/format-util.hpp" -#include -#include - -using boost::regex; -using boost::smatch; -using boost::regex_search; -using boost::algorithm::join; +#include +using std::regex; +using std::smatch; +using std::regex_search; +using util::join; using util::noneg; @@ -64,12 +63,12 @@ namespace lib { */ Cmdline::Cmdline (const string cmdline) { - regex tokendef("[^ \r\n\t]+"); + static regex TOKENDEF{"\\S+"}; smatch match; string::const_iterator it = cmdline.begin(); string::const_iterator end = cmdline.end(); - while (regex_search(it, end, match, tokendef)) + while (regex_search(it, end, match, TOKENDEF)) { string ss(match[0]); this->push_back(ss); diff --git a/src/lib/cmdline.hpp b/src/lib/cmdline.hpp index ec67eef25..70a8eb8e5 100644 --- a/src/lib/cmdline.hpp +++ b/src/lib/cmdline.hpp @@ -27,6 +27,7 @@ ** the referred data into a vector of strings. Thus `Cmdline` is a way to ** express explicitly on APIs that we are consuming commandline contents, ** and, moreover, it offers a way more sane interface to deal with those. + ** @see CmdlineWrapper_test */ diff --git a/src/lib/query-util.cpp b/src/lib/query-util.cpp index b370018d9..26bedbc1a 100644 --- a/src/lib/query-util.cpp +++ b/src/lib/query-util.cpp @@ -31,14 +31,15 @@ #include "lib/util.hpp" #include -#include +#include +#include #include using std::map; -using boost::regex; -using boost::smatch; -using boost::regex_search; -using boost::sregex_iterator; +using std::regex; +using std::smatch; +using std::regex_search; +using std::sregex_iterator; using util::contains; using util::isnil; @@ -49,7 +50,7 @@ namespace lib { namespace { // local definitions - typedef boost::function ChPredicate; + using ChPredicate = std::function ; ChPredicate is_alpha = boost::algorithm::is_alpha(); ChPredicate is_upper = boost::algorithm::is_upper(); @@ -79,14 +80,14 @@ namespace lib { map regexTable; - Literal matchArgument = "\\(\\s*([\\w_\\.\\-]+)\\s*\\),?\\s*"; - regex findPredicate (string("(\\w+)")+matchArgument); + Literal MATCH_ARGUMENT = R"~(\(\s*([\w_\.\-]+)\s*\),?\s*)~"; + const regex FIND_PREDICATE{string{"(\\w+)"} + MATCH_ARGUMENT}; inline regex& getTermRegex (Symbol sym) { if (!contains (regexTable, sym)) - regexTable[sym] = regex (string(sym)+matchArgument); + regexTable[sym] = regex (string(sym)+MATCH_ARGUMENT); return regexTable[sym]; } } @@ -146,7 +147,7 @@ namespace lib { { uint cnt (0); sregex_iterator end; - for (sregex_iterator i (q.begin(),q.end(), findPredicate); + for (sregex_iterator i (q.begin(),q.end(), FIND_PREDICATE); i != end; ++i) ++cnt; return cnt; diff --git a/src/lib/searchpath.cpp b/src/lib/searchpath.cpp index 5f20e7068..5f21460c6 100644 --- a/src/lib/searchpath.cpp +++ b/src/lib/searchpath.cpp @@ -43,6 +43,8 @@ namespace lib { LUMIERA_ERROR_DEFINE (FILE_NOT_DIRECTORY, "path element points at a file instead of a directory"); + using std::regex; + using std::regex_replace; const regex SearchPathSplitter::EXTRACT_PATHSPEC ("[^:]+"); @@ -78,7 +80,7 @@ namespace lib { static const string expandedOriginDir = fsys::path (findExePath()).parent_path().string() + "/"; ///////////TICKET #896 - return boost::regex_replace(src, PICK_ORIGIN_TOKEN, expandedOriginDir); + return regex_replace(src, PICK_ORIGIN_TOKEN, expandedOriginDir); } diff --git a/src/lib/searchpath.hpp b/src/lib/searchpath.hpp index 617552b63..c0633bd61 100644 --- a/src/lib/searchpath.hpp +++ b/src/lib/searchpath.hpp @@ -37,19 +37,15 @@ #include "lib/nocopy.hpp" #include -#include #include +#include namespace lib { using std::string; - using boost::regex; - using boost::smatch; - using boost::regex_search; - using boost::sregex_iterator; - typedef smatch::value_type const& SubMatch; + using SubMatch = std::smatch::value_type const&; namespace error = lumiera::error; namespace fsys = boost::filesystem; @@ -77,10 +73,10 @@ namespace lib { : util::NonCopyable { string pathSpec_; - sregex_iterator pos_, - end_; + std::sregex_iterator pos_, + end_; - static const regex EXTRACT_PATHSPEC; + static const std::regex EXTRACT_PATHSPEC; public: SearchPathSplitter (string const& searchPath) diff --git a/src/lib/time/timecode.cpp b/src/lib/time/timecode.cpp index a375d825d..2e30a9e79 100644 --- a/src/lib/time/timecode.cpp +++ b/src/lib/time/timecode.cpp @@ -36,17 +36,17 @@ #include "lib/util.hpp" #include "lib/util-quant.hpp" +#include #include -#include #include -using std::string; using util::unConst; using util::isSameObject; using util::floorwrap; -using boost::regex; -using boost::smatch; -using boost::regex_search; +using std::string; +using std::regex; +using std::smatch; +using std::regex_search; using boost::lexical_cast; namespace error = lumiera::error; @@ -71,8 +71,8 @@ namespace time { TimeValue Frames::parse (string const& frameNumber, QuantR frameGrid) { - static regex frameNr_parser ("(? (match[1])); else @@ -119,8 +119,8 @@ namespace time { TimeValue Seconds::parse (string const& seconds, QuantR grid) { - static regex fracSecs_parser ("(? (match[N]) smatch match; diff --git a/src/steam/asset/media.cpp b/src/steam/asset/media.cpp index 33b2d2c68..0e4bef65d 100644 --- a/src/steam/asset/media.cpp +++ b/src/steam/asset/media.cpp @@ -38,7 +38,7 @@ #include "lib/util.hpp" #include "include/logging.h" -#include +#include using util::_Fmt; @@ -48,9 +48,9 @@ using lib::time::Duration; using backend_interface::MediaDesc; using backend_interface::MediaAccessFacade; -using boost::regex; -using boost::smatch; -using boost::regex_search; +using std::regex; +using std::smatch; +using std::regex_search; using std::dynamic_pointer_cast; namespace error = lumiera::error; @@ -66,10 +66,10 @@ namespace asset { */ string extractName (const string& path) { - regex pathname_pattern("([^/\\.]+)(\\.\\w+)?$"); + static regex PATHNAME_PATTERN("([^/\\.]+)(\\.\\w+)?$"); smatch match; - if (regex_search (path, match, pathname_pattern)) + if (regex_search (path, match, PATHNAME_PATTERN)) return util::sanitise (string (match[1])); else return ""; diff --git a/tests/basics/time/time-parsing-test.cpp b/tests/basics/time/time-parsing-test.cpp index 1f2cbf284..3a20977cf 100644 --- a/tests/basics/time/time-parsing-test.cpp +++ b/tests/basics/time/time-parsing-test.cpp @@ -144,6 +144,7 @@ namespace test{ Parsing ("xxx25#xxx") .should_yield (1); Parsing ("12 25#") .should_yield (1); Parsing ("12 25# 33#") .should_yield (1); // note pitfall: the first valid number is used + Parsing ("12 25# \n 33#") .should_yield (1); Parsing ("12\n 25# \n 33#") .should_yield (1); Parsing ("12.25#") .should_fail(); // rejected because of leading dot (ambiguity) }