Revert "Convert uses of boost::regex and related functions/types to their stdlib counterparts"

This reverts commit 29ee9a7150. It broke GUI2 schema validation
for keys with formulas. Also, it seems std::regex does have a form of match_not_dot_null
(std::regex_constants::match_not_null). Will need to rethink.

StackOverflow tells me boost::regex used Perl regex, whereas the stdlib regex does not. Shall
have to confer with @celticminstrel...
This commit is contained in:
Charles Dang 2018-03-21 18:13:36 +11:00
parent 00dac71a90
commit f081a1c133
6 changed files with 33 additions and 29 deletions

View file

@ -26,7 +26,7 @@
#include "ai/formula/ai.hpp"
#include <regex>
#include <boost/regex.hpp>
namespace pathfind {
@ -141,10 +141,10 @@ static component *find_component(component *root, const std::string &path, path_
}
//match path elements in [modify_ai] tag
std::regex re(R"""(([^\.^\[]+)(\[(\d*)\]|\[([^\]]+)\]|()))""");
boost::regex re(R"""(([^\.^\[]+)(\[(\d*)\]|\[([^\]]+)\]|()))""");
const int sub_matches[] {1,3,4};
std::sregex_token_iterator i(path.begin(), path.end(), re, sub_matches);
std::sregex_token_iterator j;
boost::sregex_token_iterator i(path.begin(), path.end(), re, sub_matches);
boost::sregex_token_iterator j;
component *c = root;

View file

@ -30,7 +30,7 @@
#include "terrain/type_data.hpp"
#include "units/unit.hpp"
#include <regex>
#include <boost/regex.hpp>
namespace editor
{
@ -154,10 +154,11 @@ map_context::map_context(const config& game_config, const std::string& filename)
}
// 1.0 Pure map data
std::regex rexpression_map_data(R"""(map_data\s*=\s*"(.+?)")""");
std::smatch matched_map_data;
boost::regex rexpression_map_data(R"""(map_data\s*=\s*"(.+?)")""");
boost::smatch matched_map_data;
if(!std::regex_search(file_string, matched_map_data, rexpression_map_data)
if(!boost::regex_search(
file_string, matched_map_data, rexpression_map_data, boost::regex_constants::match_not_dot_null)
) {
map_ = editor_map::from_string(game_config, file_string); // throws on error
pure_map_ = true;
@ -169,14 +170,14 @@ map_context::map_context(const config& game_config, const std::string& filename)
// 2.0 Embedded map
const std::string& map_data = matched_map_data[1];
std::regex rexpression_macro(R"""(\{(.+?)\})""");
std::smatch matched_macro;
boost::regex rexpression_macro(R"""(\{(.+?)\})""");
boost::smatch matched_macro;
if(!std::regex_search(map_data, matched_macro, rexpression_macro)) {
if(!boost::regex_search(map_data, matched_macro, rexpression_macro)) {
// We have a map_data string but no macro ---> embedded or scenario
std::regex rexpression_scenario(R"""(\[(scenario|test|multiplayer|tutorial)\])""");
if(!std::regex_search(file_string, rexpression_scenario)) {
boost::regex rexpression_scenario(R"""(\[(scenario|test|multiplayer|tutorial)\])""");
if(!boost::regex_search(file_string, rexpression_scenario)) {
LOG_ED << "Loading generated scenario file" << std::endl;
// 4.0 editor generated scenario
try {
@ -547,7 +548,7 @@ config map_context::to_config()
u["name"].write_if_not_empty(i->name());
u["facing"] = map_location::write_direction(i->facing());
if(!std::regex_match(i->id(), std::regex(".*-[0-9]+"))) {
if(!boost::regex_match(i->id(), boost::regex(".*-[0-9]+"))) {
u["id"] = i->id();
}
@ -616,10 +617,11 @@ bool map_context::save_map()
} else {
std::string map_string = filesystem::read_file(get_filename());
std::regex rexpression_map_data(R"""((.*map_data\s*=\s*")(.+?)(".*))""");
std::smatch matched_map_data;
boost::regex rexpression_map_data(R"""((.*map_data\s*=\s*")(.+?)(".*))""");
boost::smatch matched_map_data;
if(std::regex_search(map_string, matched_map_data, rexpression_map_data)) {
if(boost::regex_search(map_string, matched_map_data, rexpression_map_data,
boost::regex_constants::match_not_dot_null)) {
std::stringstream ss;
ss << matched_map_data[1];
ss << map_data;

View file

@ -62,7 +62,7 @@
#include "wml_exception.hpp"
#include "whiteboard/manager.hpp"
#include <regex>
#include <boost/regex.hpp>
static lg::log_domain log_engine("engine");
#define DBG_NG LOG_STREAM(debug, log_engine)
@ -552,7 +552,7 @@ namespace {
static const std::string s_sep = "(, |\\n)";
static const std::string s_prefix = R"""((\d+ )?)""";
static const std::string s_all = "(" + s_prefix + s_terrain + s_sep + ")+";
static const std::regex r_all(s_all);
static const boost::regex r_all(s_all);
const std::string& mapfile = filesystem::get_wml_location(filename_);
std::string res = "";
@ -560,7 +560,7 @@ namespace {
res = filesystem::read_file(mapfile);
}
config retv;
if(std::regex_match(res, r_all))
if(boost::regex_match(res, r_all))
{
retv["map_data"] = res;
}

View file

@ -163,7 +163,7 @@ bool schema_validator::read_config_file(const std::string& filename)
for(const config& type : g.child_range("type")) {
try {
types_[type["name"].str()] = std::regex(type["value"].str());
types_[type["name"].str()] = boost::regex(type["value"].str());
} catch(std::exception&) {
// Need to check all type values in schema-generator
}
@ -269,8 +269,8 @@ void schema_validator::validate_key(
auto itt = types_.find(key->get_type());
if(itt != types_.end()) {
std::smatch sub;
bool res = std::regex_match(value, sub, itt->second);
boost::smatch sub;
bool res = boost::regex_match(value, sub, itt->second);
if(!res) {
cache_.top()[&cfg].emplace_back(

View file

@ -19,9 +19,10 @@
#include "serialization/tag.hpp"
#include "serialization/validator.hpp"
#include <boost/regex.hpp>
#include <iostream>
#include <queue>
#include <regex>
#include <stack>
#include <string>
@ -146,6 +147,6 @@ private:
std::stack<message_map> cache_;
/** Type validators. */
std::map<std::string, std::regex> types_;
std::map<std::string, boost::regex> types_;
};
} // namespace schema_validation{

View file

@ -32,8 +32,9 @@
#include "gui/auxiliary/typed_formula.hpp"
#include "gui/dialogs/loading_screen.hpp"
#include <boost/regex.hpp>
#include <locale>
#include <regex>
static lg::log_domain log_config("config");
#define ERR_CF LOG_STREAM(err, log_config)
@ -1074,7 +1075,7 @@ void handle_variations(config& ut_cfg)
ut_cfg.splice_children(variations, "variation");
}
const std::regex fai_identifier("[a-zA-Z_]+");
const boost::regex fai_identifier("[a-zA-Z_]+");
template<typename MoveT>
void patch_movetype(
@ -1091,8 +1092,8 @@ void patch_movetype(
gui2::typed_formula<int> formula(formula_str);
wfl::map_formula_callable original;
std::sregex_iterator m(formula_str.begin(), formula_str.end(), fai_identifier);
for(const std::sregex_iterator::value_type& p : std::make_pair(m, std::sregex_iterator())) {
boost::sregex_iterator m(formula_str.begin(), formula_str.end(), fai_identifier);
for(const boost::sregex_iterator::value_type& p : std::make_pair(m, boost::sregex_iterator())) {
const std::string var_name = p.str();
wfl::variant val(original_cfg[var_name].to_int(default_val));