From 61319b9a6b34915bf326eb3d7364fe92a52bbb1d Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 4 Jul 2016 10:38:27 +0200 Subject: [PATCH] Replaced boost::regex with std::regex as Ubuntu 14 is no longer supported --- CMakeLists.txt | 2 +- src/cmake.cc | 33 +++++++++++---------------------- src/ctags.cc | 17 +++-------------- src/source.cc | 30 +++++++++++++++--------------- src/source.h | 20 ++++---------------- src/source_clang.cc | 16 ++++++++-------- src/terminal.cc | 10 +++++----- src/terminal.h | 12 +----------- 8 files changed, 48 insertions(+), 92 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index de149ed..4c2cb2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,7 @@ else() message("liblldb not found. Building juCi++ without debugging support") endif() -find_package(Boost 1.54 COMPONENTS regex system filesystem REQUIRED) +find_package(Boost 1.54 COMPONENTS system filesystem REQUIRED) find_package(ASPELL REQUIRED) include(FindPkgConfig) pkg_check_modules(GTKMM gtkmm-3.0 REQUIRED) diff --git a/src/cmake.cc b/src/cmake.cc index 990c7ba..8005d20 100644 --- a/src/cmake.cc +++ b/src/cmake.cc @@ -3,25 +3,14 @@ #include "dialogs.h" #include "config.h" #include "terminal.h" - -//Temporary fix for current Arch Linux boost linking problem -#ifdef __GNUC_PREREQ -#if __GNUC_PREREQ(5,1) #include -#define REGEX_NS std -#endif -#endif -#ifndef REGEX_NS -#include -#define REGEX_NS boost -#endif CMake::CMake(const boost::filesystem::path &path) { const auto find_cmake_project=[this](const boost::filesystem::path &cmake_path) { for(auto &line: filesystem::read_lines(cmake_path)) { - const static REGEX_NS::regex project_regex("^ *project *\\(.*$", REGEX_NS::regex::icase); - REGEX_NS::smatch sm; - if(REGEX_NS::regex_match(line, sm, project_regex)) + const static std::regex project_regex("^ *project *\\(.*$", std::regex::icase); + std::smatch sm; + if(std::regex_match(line, sm, project_regex)) return true; } return false; @@ -217,9 +206,9 @@ void CMake::find_variables() { end_line=file.size(); if(end_line>start_line) { auto line=file.substr(start_line, end_line-start_line); - REGEX_NS::smatch sm; - const static REGEX_NS::regex set_regex("^ *set *\\( *([A-Za-z_][A-Za-z_0-9]*) +(.*)\\) *$", REGEX_NS::regex::icase); - if(REGEX_NS::regex_match(line, sm, set_regex)) { + std::smatch sm; + const static std::regex set_regex("^ *set *\\( *([A-Za-z_][A-Za-z_0-9]*) +(.*)\\) *$", std::regex::icase); + if(std::regex_match(line, sm, set_regex)) { auto data=sm[2].str(); while(data.size()>0 && data.back()==' ') data.pop_back(); @@ -227,8 +216,8 @@ void CMake::find_variables() { variables[sm[1].str()]=data; } else { - const static REGEX_NS::regex project_regex("^ *project *\\( *([^ ]+).*\\) *$", REGEX_NS::regex::icase); - if(REGEX_NS::regex_match(line, sm, project_regex)) { + const static std::regex project_regex("^ *project *\\( *([^ ]+).*\\) *$", std::regex::icase); + if(std::regex_match(line, sm, project_regex)) { auto data=sm[1].str(); parse_variable_parameters(data); variables["CMAKE_PROJECT_NAME"]=data; //TODO: is this variable deprecated/non-standard? @@ -337,7 +326,7 @@ std::vector CMake::get_function_parameters(std::string &data) { } std::vector > > CMake::get_functions_parameters(const std::string &name) { - const REGEX_NS::regex function_regex("^ *"+name+" *\\( *(.*)\\) *$", REGEX_NS::regex::icase); + const std::regex function_regex("^ *"+name+" *\\( *(.*)\\) *$", std::regex::icase); if(!parsed) parse(); std::vector > > functions; @@ -351,8 +340,8 @@ std::vector > > CMak end_line=file.size(); if(end_line>start_line) { auto line=file.substr(start_line, end_line-start_line); - REGEX_NS::smatch sm; - if(REGEX_NS::regex_match(line, sm, function_regex)) { + std::smatch sm; + if(std::regex_match(line, sm, function_regex)) { auto data=sm[1].str(); while(data.size()>0 && data.back()==' ') data.pop_back(); diff --git a/src/ctags.cc b/src/ctags.cc index b9e1d6e..45b86e2 100644 --- a/src/ctags.cc +++ b/src/ctags.cc @@ -6,18 +6,7 @@ #include "directories.h" #include #include - -//Temporary fix for current Arch Linux boost linking problem -#ifdef __GNUC_PREREQ -#if __GNUC_PREREQ(5,1) #include -#define REGEX_NS std -#endif -#endif -#ifndef REGEX_NS -#include -#define REGEX_NS boost -#endif std::pair > Ctags::get_result(const boost::filesystem::path &path) { auto build=Project::Build::create(path); @@ -49,9 +38,9 @@ std::pair > Ctags::g Ctags::Location Ctags::parse_line(const std::string &line, bool markup) { Location location; - const static REGEX_NS::regex regex("^([^\t]+)\t([^\t]+)\t(?:/\\^)?([ \t]*)(.+)$"); - REGEX_NS::smatch sm; - if(REGEX_NS::regex_match(line, sm, regex)) { + const static std::regex regex("^([^\t]+)\t([^\t]+)\t(?:/\\^)?([ \t]*)(.+)$"); + std::smatch sm; + if(std::regex_match(line, sm, regex)) { location.source=sm[4].str(); size_t pos=location.source.find(";\"\tline:"); if(pos==std::string::npos) diff --git a/src/source.cc b/src/source.cc index 487b8a9..68d431e 100644 --- a/src/source.cc +++ b/src/source.cc @@ -85,9 +85,9 @@ std::string Source::FixIt::string(Glib::RefPtr buffer) { ////////////// //// View //// ////////////// -const REGEX_NS::regex Source::View::bracket_regex("^([ \\t]*).*\\{ *$"); -const REGEX_NS::regex Source::View::no_bracket_statement_regex("^([ \\t]*)(if|for|else if|while) *\\(.*[^;}] *$"); -const REGEX_NS::regex Source::View::no_bracket_no_para_statement_regex("^([ \\t]*)(else) *$"); +const std::regex Source::View::bracket_regex("^([ \\t]*).*\\{ *$"); +const std::regex Source::View::no_bracket_statement_regex("^([ \\t]*)(if|for|else if|while) *\\(.*[^;}] *$"); +const std::regex Source::View::no_bracket_no_para_statement_regex("^([ \\t]*)(else) *$"); Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr language): Gsv::View(), SpellCheckView(), DiffView(file_path), language(language) { get_source_buffer()->begin_not_undoable_action(); @@ -1234,7 +1234,7 @@ bool Source::View::on_key_press_event_bracket_language(GdkEventKey* key) { auto start_sentence_tabs_end_iter=get_tabs_end_iter(start_of_sentence_iter); auto tabs=get_line_before(start_sentence_tabs_end_iter); - REGEX_NS::smatch sm; + std::smatch sm; if(iter.backward_char() && *iter=='{') { auto found_iter=iter; bool found_right_bracket=find_right_bracket_forward(iter, found_iter); @@ -1299,13 +1299,13 @@ bool Source::View::on_key_press_event_bracket_language(GdkEventKey* key) { iter.forward_char(); } } - else if(REGEX_NS::regex_match(line, sm, no_bracket_statement_regex)) { + else if(std::regex_match(line, sm, no_bracket_statement_regex)) { get_buffer()->insert_at_cursor("\n"+tabs+tab); scroll_to(get_buffer()->get_insert()); get_buffer()->end_user_action(); return true; } - else if(REGEX_NS::regex_match(line, sm, no_bracket_no_para_statement_regex)) { + else if(std::regex_match(line, sm, no_bracket_no_para_statement_regex)) { get_buffer()->insert_at_cursor("\n"+tabs+tab); scroll_to(get_buffer()->get_insert()); get_buffer()->end_user_action(); @@ -1313,18 +1313,18 @@ bool Source::View::on_key_press_event_bracket_language(GdkEventKey* key) { } //Indenting after for instance if(...)\n...;\n else if(iter.backward_char() && *iter==';') { - REGEX_NS::smatch sm2; + std::smatch sm2; size_t line_nr=get_buffer()->get_insert()->get_iter().get_line(); if(line_nr>0 && tabs.size()>=tab_size) { std::string previous_line=get_line(line_nr-1); - if(!REGEX_NS::regex_match(previous_line, sm2, bracket_regex)) { - if(REGEX_NS::regex_match(previous_line, sm2, no_bracket_statement_regex)) { + if(!std::regex_match(previous_line, sm2, bracket_regex)) { + if(std::regex_match(previous_line, sm2, no_bracket_statement_regex)) { get_buffer()->insert_at_cursor("\n"+sm2[1].str()); scroll_to(get_buffer()->get_insert()); get_buffer()->end_user_action(); return true; } - else if(REGEX_NS::regex_match(previous_line, sm2, no_bracket_no_para_statement_regex)) { + else if(std::regex_match(previous_line, sm2, no_bracket_no_para_statement_regex)) { get_buffer()->insert_at_cursor("\n"+sm2[1].str()); scroll_to(get_buffer()->get_insert()); get_buffer()->end_user_action(); @@ -1341,7 +1341,7 @@ bool Source::View::on_key_press_event_bracket_language(GdkEventKey* key) { left_bracket_iter.forward_char(); Gtk::TextIter start_of_left_bracket_sentence_iter; if(find_start_of_closed_expression(left_bracket_iter, start_of_left_bracket_sentence_iter)) { - REGEX_NS::smatch sm; + std::smatch sm; auto tabs_end_iter=get_tabs_end_iter(start_of_left_bracket_sentence_iter); auto tabs_start_of_sentence=get_line_before(tabs_end_iter); if(tabs.size()==(tabs_start_of_sentence.size()+tab_size)) { @@ -1395,12 +1395,12 @@ bool Source::View::on_key_press_event_bracket_language(GdkEventKey* key) { size_t line_nr=iter.get_line(); if(line_nr>0 && tabs.size()>=tab_size && iter==tabs_end_iter) { std::string previous_line=get_line(line_nr-1); - REGEX_NS::smatch sm; - if(!REGEX_NS::regex_match(previous_line, sm, bracket_regex)) { + std::smatch sm; + if(!std::regex_match(previous_line, sm, bracket_regex)) { auto start_iter=iter; start_iter.backward_chars(tab_size); - if(REGEX_NS::regex_match(previous_line, sm, no_bracket_statement_regex) || - REGEX_NS::regex_match(previous_line, sm, no_bracket_no_para_statement_regex)) { + if(std::regex_match(previous_line, sm, no_bracket_statement_regex) || + std::regex_match(previous_line, sm, no_bracket_no_para_statement_regex)) { if((tabs.size()-tab_size)==sm[1].str().size()) { get_buffer()->erase(start_iter, iter); get_buffer()->insert_at_cursor("{"); diff --git a/src/source.h b/src/source.h index 8b85745..d6b01de 100644 --- a/src/source.h +++ b/src/source.h @@ -2,25 +2,13 @@ #define JUCI_SOURCE_H_ #include "source_spellcheck.h" #include "source_diff.h" +#include "tooltips.h" #include #include #include #include #include - -//Temporary fix for current Arch Linux boost linking problem -#ifdef __GNUC_PREREQ -#if __GNUC_PREREQ(5,1) #include -#define REGEX_NS std -#endif -#endif -#ifndef REGEX_NS -#include -#define REGEX_NS boost -#endif - -#include "tooltips.h" namespace Source { Glib::RefPtr guess_language(const boost::filesystem::path &file_path); @@ -138,9 +126,9 @@ namespace Source { std::string get_token(Gtk::TextIter iter); - const static REGEX_NS::regex bracket_regex; - const static REGEX_NS::regex no_bracket_statement_regex; - const static REGEX_NS::regex no_bracket_no_para_statement_regex; + const static std::regex bracket_regex; + const static std::regex no_bracket_statement_regex; + const static std::regex no_bracket_no_para_statement_regex; bool on_key_press_event(GdkEventKey* key) override; bool on_key_press_event_basic(GdkEventKey* key); diff --git a/src/source_clang.cc b/src/source_clang.cc index 8f022a1..58930ae 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -204,9 +204,9 @@ std::vector Source::ClangViewParse::get_compilation_commands() { } } auto clang_version_string=clang::to_string(clang_getClangVersion()); - const static REGEX_NS::regex clang_version_regex("^[A-Za-z ]+([0-9.]+).*$"); - REGEX_NS::smatch sm; - if(REGEX_NS::regex_match(clang_version_string, sm, clang_version_regex)) { + const static std::regex clang_version_regex("^[A-Za-z ]+([0-9.]+).*$"); + std::smatch sm; + if(std::regex_match(clang_version_string, sm, clang_version_regex)) { auto clang_version=sm[1].str(); arguments.emplace_back("-I/usr/lib/clang/"+clang_version+"/include"); #ifdef __APPLE__ @@ -640,10 +640,10 @@ void Source::ClangViewAutocomplete::autocomplete_check() { get_source_buffer()->iter_has_context_class(iter, "comment"))) return; std::string line=" "+get_line_before(); - const static REGEX_NS::regex in_specified_namespace("^(.*[a-zA-Z0-9_\\)\\]\\>])(->|\\.|::)([a-zA-Z0-9_]*)$"); - const static REGEX_NS::regex within_namespace("^(.*)([^a-zA-Z0-9_]+)([a-zA-Z0-9_]{3,})$"); - REGEX_NS::smatch sm; - if(REGEX_NS::regex_match(line, sm, in_specified_namespace)) { + const static std::regex in_specified_namespace("^(.*[a-zA-Z0-9_\\)\\]\\>])(->|\\.|::)([a-zA-Z0-9_]*)$"); + const static std::regex within_namespace("^(.*)([^a-zA-Z0-9_]+)([a-zA-Z0-9_]{3,})$"); + std::smatch sm; + if(std::regex_match(line, sm, in_specified_namespace)) { { std::unique_lock lock(prefix_mutex); prefix=sm[3].str(); @@ -651,7 +651,7 @@ void Source::ClangViewAutocomplete::autocomplete_check() { if(prefix.size()==0 || prefix[0]<'0' || prefix[0]>'9') autocomplete(); } - else if(REGEX_NS::regex_match(line, sm, within_namespace)) { + else if(std::regex_match(line, sm, within_namespace)) { { std::unique_lock lock(prefix_mutex); prefix=sm[3].str(); diff --git a/src/terminal.cc b/src/terminal.cc index 6c63554..cc74e2f 100644 --- a/src/terminal.cc +++ b/src/terminal.cc @@ -43,7 +43,7 @@ void Terminal::InProgress::cancel(const std::string& msg) { Terminal::get().async_print(line_nr-1, msg); } -const REGEX_NS::regex Terminal::link_regex("^([A-Z]:)?([^:]+):([0-9]+):([0-9]+)$"); +const std::regex Terminal::link_regex("^([A-Z]:)?([^:]+):([0-9]+):([0-9]+)$"); Terminal::Terminal() { bold_tag=get_buffer()->create_tag(); @@ -201,8 +201,8 @@ void Terminal::apply_link_tags(Gtk::TextIter start_iter, Gtk::TextIter end_iter) #endif ++colons; if(colons==3 && possible_path) { - REGEX_NS::smatch sm; - if(REGEX_NS::regex_match(get_buffer()->get_text(start_path_iter, iter).raw(), sm, link_regex)) + std::smatch sm; + if(std::regex_match(get_buffer()->get_text(start_path_iter, iter).raw(), sm, link_regex)) get_buffer()->apply_tag(link_tag, start_path_iter, iter); possible_path=false; } @@ -353,8 +353,8 @@ bool Terminal::on_button_press_event(GdkEventButton* button_event) { if(iter.has_tag(link_tag) && start_iter.backward_to_tag_toggle(link_tag) && end_iter.forward_to_tag_toggle(link_tag)) { std::string path_str=get_buffer()->get_text(start_iter, end_iter); - REGEX_NS::smatch sm; - if(REGEX_NS::regex_match(path_str, sm, link_regex)) { + std::smatch sm; + if(std::regex_match(path_str, sm, link_regex)) { auto path_str=sm[1].str()+sm[2].str(); auto path=boost::filesystem::path(path_str); boost::system::error_code ec; diff --git a/src/terminal.h b/src/terminal.h index bc3073e..cdde39c 100644 --- a/src/terminal.h +++ b/src/terminal.h @@ -11,17 +11,7 @@ #include "process.hpp" #include "dispatcher.h" #include -//Temporary fix for current Arch Linux boost linking problem -#ifdef __GNUC_PREREQ -#if __GNUC_PREREQ(5,1) #include -#define REGEX_NS std -#endif -#endif -#ifndef REGEX_NS -#include -#define REGEX_NS boost -#endif class Terminal : public Gtk::TextView { public: @@ -74,7 +64,7 @@ private: Glib::RefPtr link_mouse_cursor; Glib::RefPtr default_mouse_cursor; size_t deleted_lines=0; - const static REGEX_NS::regex link_regex; + const static std::regex link_regex; void apply_link_tags(Gtk::TextIter start_iter, Gtk::TextIter end_iter); std::vector > processes;