Browse Source

Replaced boost::regex with std::regex as Ubuntu 14 is no longer supported

merge-requests/365/head
eidheim 10 years ago
parent
commit
61319b9a6b
  1. 2
      CMakeLists.txt
  2. 33
      src/cmake.cc
  3. 17
      src/ctags.cc
  4. 30
      src/source.cc
  5. 20
      src/source.h
  6. 16
      src/source_clang.cc
  7. 10
      src/terminal.cc
  8. 12
      src/terminal.h

2
CMakeLists.txt

@ -34,7 +34,7 @@ else()
message("liblldb not found. Building juCi++ without debugging support") message("liblldb not found. Building juCi++ without debugging support")
endif() endif()
find_package(Boost 1.54 COMPONENTS regex system filesystem REQUIRED) find_package(Boost 1.54 COMPONENTS system filesystem REQUIRED)
find_package(ASPELL REQUIRED) find_package(ASPELL REQUIRED)
include(FindPkgConfig) include(FindPkgConfig)
pkg_check_modules(GTKMM gtkmm-3.0 REQUIRED) pkg_check_modules(GTKMM gtkmm-3.0 REQUIRED)

33
src/cmake.cc

@ -3,25 +3,14 @@
#include "dialogs.h" #include "dialogs.h"
#include "config.h" #include "config.h"
#include "terminal.h" #include "terminal.h"
//Temporary fix for current Arch Linux boost linking problem
#ifdef __GNUC_PREREQ
#if __GNUC_PREREQ(5,1)
#include <regex> #include <regex>
#define REGEX_NS std
#endif
#endif
#ifndef REGEX_NS
#include <boost/regex.hpp>
#define REGEX_NS boost
#endif
CMake::CMake(const boost::filesystem::path &path) { CMake::CMake(const boost::filesystem::path &path) {
const auto find_cmake_project=[this](const boost::filesystem::path &cmake_path) { const auto find_cmake_project=[this](const boost::filesystem::path &cmake_path) {
for(auto &line: filesystem::read_lines(cmake_path)) { for(auto &line: filesystem::read_lines(cmake_path)) {
const static REGEX_NS::regex project_regex("^ *project *\\(.*$", REGEX_NS::regex::icase); const static std::regex project_regex("^ *project *\\(.*$", std::regex::icase);
REGEX_NS::smatch sm; std::smatch sm;
if(REGEX_NS::regex_match(line, sm, project_regex)) if(std::regex_match(line, sm, project_regex))
return true; return true;
} }
return false; return false;
@ -217,9 +206,9 @@ void CMake::find_variables() {
end_line=file.size(); end_line=file.size();
if(end_line>start_line) { if(end_line>start_line) {
auto line=file.substr(start_line, end_line-start_line); auto line=file.substr(start_line, end_line-start_line);
REGEX_NS::smatch sm; std::smatch sm;
const static REGEX_NS::regex set_regex("^ *set *\\( *([A-Za-z_][A-Za-z_0-9]*) +(.*)\\) *$", REGEX_NS::regex::icase); const static std::regex set_regex("^ *set *\\( *([A-Za-z_][A-Za-z_0-9]*) +(.*)\\) *$", std::regex::icase);
if(REGEX_NS::regex_match(line, sm, set_regex)) { if(std::regex_match(line, sm, set_regex)) {
auto data=sm[2].str(); auto data=sm[2].str();
while(data.size()>0 && data.back()==' ') while(data.size()>0 && data.back()==' ')
data.pop_back(); data.pop_back();
@ -227,8 +216,8 @@ void CMake::find_variables() {
variables[sm[1].str()]=data; variables[sm[1].str()]=data;
} }
else { else {
const static REGEX_NS::regex project_regex("^ *project *\\( *([^ ]+).*\\) *$", REGEX_NS::regex::icase); const static std::regex project_regex("^ *project *\\( *([^ ]+).*\\) *$", std::regex::icase);
if(REGEX_NS::regex_match(line, sm, project_regex)) { if(std::regex_match(line, sm, project_regex)) {
auto data=sm[1].str(); auto data=sm[1].str();
parse_variable_parameters(data); parse_variable_parameters(data);
variables["CMAKE_PROJECT_NAME"]=data; //TODO: is this variable deprecated/non-standard? variables["CMAKE_PROJECT_NAME"]=data; //TODO: is this variable deprecated/non-standard?
@ -337,7 +326,7 @@ std::vector<std::string> CMake::get_function_parameters(std::string &data) {
} }
std::vector<std::pair<boost::filesystem::path, std::vector<std::string> > > CMake::get_functions_parameters(const std::string &name) { std::vector<std::pair<boost::filesystem::path, std::vector<std::string> > > 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) if(!parsed)
parse(); parse();
std::vector<std::pair<boost::filesystem::path, std::vector<std::string> > > functions; std::vector<std::pair<boost::filesystem::path, std::vector<std::string> > > functions;
@ -351,8 +340,8 @@ std::vector<std::pair<boost::filesystem::path, std::vector<std::string> > > CMak
end_line=file.size(); end_line=file.size();
if(end_line>start_line) { if(end_line>start_line) {
auto line=file.substr(start_line, end_line-start_line); auto line=file.substr(start_line, end_line-start_line);
REGEX_NS::smatch sm; std::smatch sm;
if(REGEX_NS::regex_match(line, sm, function_regex)) { if(std::regex_match(line, sm, function_regex)) {
auto data=sm[1].str(); auto data=sm[1].str();
while(data.size()>0 && data.back()==' ') while(data.size()>0 && data.back()==' ')
data.pop_back(); data.pop_back();

17
src/ctags.cc

@ -6,18 +6,7 @@
#include "directories.h" #include "directories.h"
#include <iostream> #include <iostream>
#include <vector> #include <vector>
//Temporary fix for current Arch Linux boost linking problem
#ifdef __GNUC_PREREQ
#if __GNUC_PREREQ(5,1)
#include <regex> #include <regex>
#define REGEX_NS std
#endif
#endif
#ifndef REGEX_NS
#include <boost/regex.hpp>
#define REGEX_NS boost
#endif
std::pair<boost::filesystem::path, std::unique_ptr<std::stringstream> > Ctags::get_result(const boost::filesystem::path &path) { std::pair<boost::filesystem::path, std::unique_ptr<std::stringstream> > Ctags::get_result(const boost::filesystem::path &path) {
auto build=Project::Build::create(path); auto build=Project::Build::create(path);
@ -49,9 +38,9 @@ std::pair<boost::filesystem::path, std::unique_ptr<std::stringstream> > Ctags::g
Ctags::Location Ctags::parse_line(const std::string &line, bool markup) { Ctags::Location Ctags::parse_line(const std::string &line, bool markup) {
Location location; Location location;
const static REGEX_NS::regex regex("^([^\t]+)\t([^\t]+)\t(?:/\\^)?([ \t]*)(.+)$"); const static std::regex regex("^([^\t]+)\t([^\t]+)\t(?:/\\^)?([ \t]*)(.+)$");
REGEX_NS::smatch sm; std::smatch sm;
if(REGEX_NS::regex_match(line, sm, regex)) { if(std::regex_match(line, sm, regex)) {
location.source=sm[4].str(); location.source=sm[4].str();
size_t pos=location.source.find(";\"\tline:"); size_t pos=location.source.find(";\"\tline:");
if(pos==std::string::npos) if(pos==std::string::npos)

30
src/source.cc

@ -85,9 +85,9 @@ std::string Source::FixIt::string(Glib::RefPtr<Gtk::TextBuffer> buffer) {
////////////// //////////////
//// View //// //// View ////
////////////// //////////////
const REGEX_NS::regex Source::View::bracket_regex("^([ \\t]*).*\\{ *$"); const std::regex Source::View::bracket_regex("^([ \\t]*).*\\{ *$");
const REGEX_NS::regex Source::View::no_bracket_statement_regex("^([ \\t]*)(if|for|else if|while) *\\(.*[^;}] *$"); const std::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::no_bracket_no_para_statement_regex("^([ \\t]*)(else) *$");
Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::Language> language): Gsv::View(), SpellCheckView(), DiffView(file_path), language(language) { Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::Language> language): Gsv::View(), SpellCheckView(), DiffView(file_path), language(language) {
get_source_buffer()->begin_not_undoable_action(); 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 start_sentence_tabs_end_iter=get_tabs_end_iter(start_of_sentence_iter);
auto tabs=get_line_before(start_sentence_tabs_end_iter); auto tabs=get_line_before(start_sentence_tabs_end_iter);
REGEX_NS::smatch sm; std::smatch sm;
if(iter.backward_char() && *iter=='{') { if(iter.backward_char() && *iter=='{') {
auto found_iter=iter; auto found_iter=iter;
bool found_right_bracket=find_right_bracket_forward(iter, found_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(); 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); get_buffer()->insert_at_cursor("\n"+tabs+tab);
scroll_to(get_buffer()->get_insert()); scroll_to(get_buffer()->get_insert());
get_buffer()->end_user_action(); get_buffer()->end_user_action();
return true; 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); get_buffer()->insert_at_cursor("\n"+tabs+tab);
scroll_to(get_buffer()->get_insert()); scroll_to(get_buffer()->get_insert());
get_buffer()->end_user_action(); 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 //Indenting after for instance if(...)\n...;\n
else if(iter.backward_char() && *iter==';') { 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(); size_t line_nr=get_buffer()->get_insert()->get_iter().get_line();
if(line_nr>0 && tabs.size()>=tab_size) { if(line_nr>0 && tabs.size()>=tab_size) {
std::string previous_line=get_line(line_nr-1); std::string previous_line=get_line(line_nr-1);
if(!REGEX_NS::regex_match(previous_line, sm2, bracket_regex)) { if(!std::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, no_bracket_statement_regex)) {
get_buffer()->insert_at_cursor("\n"+sm2[1].str()); get_buffer()->insert_at_cursor("\n"+sm2[1].str());
scroll_to(get_buffer()->get_insert()); scroll_to(get_buffer()->get_insert());
get_buffer()->end_user_action(); get_buffer()->end_user_action();
return true; 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()); get_buffer()->insert_at_cursor("\n"+sm2[1].str());
scroll_to(get_buffer()->get_insert()); scroll_to(get_buffer()->get_insert());
get_buffer()->end_user_action(); 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(); left_bracket_iter.forward_char();
Gtk::TextIter start_of_left_bracket_sentence_iter; Gtk::TextIter start_of_left_bracket_sentence_iter;
if(find_start_of_closed_expression(left_bracket_iter, 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_end_iter=get_tabs_end_iter(start_of_left_bracket_sentence_iter);
auto tabs_start_of_sentence=get_line_before(tabs_end_iter); auto tabs_start_of_sentence=get_line_before(tabs_end_iter);
if(tabs.size()==(tabs_start_of_sentence.size()+tab_size)) { 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(); size_t line_nr=iter.get_line();
if(line_nr>0 && tabs.size()>=tab_size && iter==tabs_end_iter) { if(line_nr>0 && tabs.size()>=tab_size && iter==tabs_end_iter) {
std::string previous_line=get_line(line_nr-1); std::string previous_line=get_line(line_nr-1);
REGEX_NS::smatch sm; std::smatch sm;
if(!REGEX_NS::regex_match(previous_line, sm, bracket_regex)) { if(!std::regex_match(previous_line, sm, bracket_regex)) {
auto start_iter=iter; auto start_iter=iter;
start_iter.backward_chars(tab_size); start_iter.backward_chars(tab_size);
if(REGEX_NS::regex_match(previous_line, sm, no_bracket_statement_regex) || if(std::regex_match(previous_line, sm, no_bracket_statement_regex) ||
REGEX_NS::regex_match(previous_line, sm, no_bracket_no_para_statement_regex)) { std::regex_match(previous_line, sm, no_bracket_no_para_statement_regex)) {
if((tabs.size()-tab_size)==sm[1].str().size()) { if((tabs.size()-tab_size)==sm[1].str().size()) {
get_buffer()->erase(start_iter, iter); get_buffer()->erase(start_iter, iter);
get_buffer()->insert_at_cursor("{"); get_buffer()->insert_at_cursor("{");

20
src/source.h

@ -2,25 +2,13 @@
#define JUCI_SOURCE_H_ #define JUCI_SOURCE_H_
#include "source_spellcheck.h" #include "source_spellcheck.h"
#include "source_diff.h" #include "source_diff.h"
#include "tooltips.h"
#include <boost/property_tree/xml_parser.hpp> #include <boost/property_tree/xml_parser.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
//Temporary fix for current Arch Linux boost linking problem
#ifdef __GNUC_PREREQ
#if __GNUC_PREREQ(5,1)
#include <regex> #include <regex>
#define REGEX_NS std
#endif
#endif
#ifndef REGEX_NS
#include <boost/regex.hpp>
#define REGEX_NS boost
#endif
#include "tooltips.h"
namespace Source { namespace Source {
Glib::RefPtr<Gsv::Language> guess_language(const boost::filesystem::path &file_path); Glib::RefPtr<Gsv::Language> guess_language(const boost::filesystem::path &file_path);
@ -138,9 +126,9 @@ namespace Source {
std::string get_token(Gtk::TextIter iter); std::string get_token(Gtk::TextIter iter);
const static REGEX_NS::regex bracket_regex; const static std::regex bracket_regex;
const static REGEX_NS::regex no_bracket_statement_regex; const static std::regex no_bracket_statement_regex;
const static REGEX_NS::regex no_bracket_no_para_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(GdkEventKey* key) override;
bool on_key_press_event_basic(GdkEventKey* key); bool on_key_press_event_basic(GdkEventKey* key);

16
src/source_clang.cc

@ -204,9 +204,9 @@ std::vector<std::string> Source::ClangViewParse::get_compilation_commands() {
} }
} }
auto clang_version_string=clang::to_string(clang_getClangVersion()); auto clang_version_string=clang::to_string(clang_getClangVersion());
const static REGEX_NS::regex clang_version_regex("^[A-Za-z ]+([0-9.]+).*$"); const static std::regex clang_version_regex("^[A-Za-z ]+([0-9.]+).*$");
REGEX_NS::smatch sm; std::smatch sm;
if(REGEX_NS::regex_match(clang_version_string, sm, clang_version_regex)) { if(std::regex_match(clang_version_string, sm, clang_version_regex)) {
auto clang_version=sm[1].str(); auto clang_version=sm[1].str();
arguments.emplace_back("-I/usr/lib/clang/"+clang_version+"/include"); arguments.emplace_back("-I/usr/lib/clang/"+clang_version+"/include");
#ifdef __APPLE__ #ifdef __APPLE__
@ -640,10 +640,10 @@ void Source::ClangViewAutocomplete::autocomplete_check() {
get_source_buffer()->iter_has_context_class(iter, "comment"))) get_source_buffer()->iter_has_context_class(iter, "comment")))
return; return;
std::string line=" "+get_line_before(); std::string line=" "+get_line_before();
const static REGEX_NS::regex in_specified_namespace("^(.*[a-zA-Z0-9_\\)\\]\\>])(->|\\.|::)([a-zA-Z0-9_]*)$"); const static std::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,})$"); const static std::regex within_namespace("^(.*)([^a-zA-Z0-9_]+)([a-zA-Z0-9_]{3,})$");
REGEX_NS::smatch sm; std::smatch sm;
if(REGEX_NS::regex_match(line, sm, in_specified_namespace)) { if(std::regex_match(line, sm, in_specified_namespace)) {
{ {
std::unique_lock<std::mutex> lock(prefix_mutex); std::unique_lock<std::mutex> lock(prefix_mutex);
prefix=sm[3].str(); prefix=sm[3].str();
@ -651,7 +651,7 @@ void Source::ClangViewAutocomplete::autocomplete_check() {
if(prefix.size()==0 || prefix[0]<'0' || prefix[0]>'9') if(prefix.size()==0 || prefix[0]<'0' || prefix[0]>'9')
autocomplete(); autocomplete();
} }
else if(REGEX_NS::regex_match(line, sm, within_namespace)) { else if(std::regex_match(line, sm, within_namespace)) {
{ {
std::unique_lock<std::mutex> lock(prefix_mutex); std::unique_lock<std::mutex> lock(prefix_mutex);
prefix=sm[3].str(); prefix=sm[3].str();

10
src/terminal.cc

@ -43,7 +43,7 @@ void Terminal::InProgress::cancel(const std::string& msg) {
Terminal::get().async_print(line_nr-1, 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() { Terminal::Terminal() {
bold_tag=get_buffer()->create_tag(); bold_tag=get_buffer()->create_tag();
@ -201,8 +201,8 @@ void Terminal::apply_link_tags(Gtk::TextIter start_iter, Gtk::TextIter end_iter)
#endif #endif
++colons; ++colons;
if(colons==3 && possible_path) { if(colons==3 && possible_path) {
REGEX_NS::smatch sm; std::smatch sm;
if(REGEX_NS::regex_match(get_buffer()->get_text(start_path_iter, iter).raw(), sm, link_regex)) 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); get_buffer()->apply_tag(link_tag, start_path_iter, iter);
possible_path=false; possible_path=false;
} }
@ -353,8 +353,8 @@ bool Terminal::on_button_press_event(GdkEventButton* button_event) {
if(iter.has_tag(link_tag) && if(iter.has_tag(link_tag) &&
start_iter.backward_to_tag_toggle(link_tag) && end_iter.forward_to_tag_toggle(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); std::string path_str=get_buffer()->get_text(start_iter, end_iter);
REGEX_NS::smatch sm; std::smatch sm;
if(REGEX_NS::regex_match(path_str, sm, link_regex)) { if(std::regex_match(path_str, sm, link_regex)) {
auto path_str=sm[1].str()+sm[2].str(); auto path_str=sm[1].str()+sm[2].str();
auto path=boost::filesystem::path(path_str); auto path=boost::filesystem::path(path_str);
boost::system::error_code ec; boost::system::error_code ec;

12
src/terminal.h

@ -11,17 +11,7 @@
#include "process.hpp" #include "process.hpp"
#include "dispatcher.h" #include "dispatcher.h"
#include <unordered_set> #include <unordered_set>
//Temporary fix for current Arch Linux boost linking problem
#ifdef __GNUC_PREREQ
#if __GNUC_PREREQ(5,1)
#include <regex> #include <regex>
#define REGEX_NS std
#endif
#endif
#ifndef REGEX_NS
#include <boost/regex.hpp>
#define REGEX_NS boost
#endif
class Terminal : public Gtk::TextView { class Terminal : public Gtk::TextView {
public: public:
@ -74,7 +64,7 @@ private:
Glib::RefPtr<Gdk::Cursor> link_mouse_cursor; Glib::RefPtr<Gdk::Cursor> link_mouse_cursor;
Glib::RefPtr<Gdk::Cursor> default_mouse_cursor; Glib::RefPtr<Gdk::Cursor> default_mouse_cursor;
size_t deleted_lines=0; 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); void apply_link_tags(Gtk::TextIter start_iter, Gtk::TextIter end_iter);
std::vector<std::shared_ptr<Process> > processes; std::vector<std::shared_ptr<Process> > processes;

Loading…
Cancel
Save