From 0149193a39451295699bae3084fdf97c585c4398 Mon Sep 17 00:00:00 2001 From: "U-ole-PC\\ole" Date: Mon, 28 Sep 2015 15:30:51 +0200 Subject: [PATCH] Fixed crash on Windows, and now uses std::to_string instead of lexical casts. --- src/source.cc | 21 ++++++++------------- src/window.cc | 32 +++++++++++++++++--------------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/source.cc b/src/source.cc index e361f28..a2e4fbd 100644 --- a/src/source.cc +++ b/src/source.cc @@ -6,7 +6,6 @@ #include #include "singletons.h" #include -#include #include using namespace std; //TODO: remove @@ -331,7 +330,7 @@ void Source::View::configure() { tab_str=""; else tab_str=""; - Singleton::terminal()->print("Tab char and size for file "+file_path.string()+" set to: "+tab_str+", "+boost::lexical_cast(tab_char_and_size.second)+".\n"); + Singleton::terminal()->print("Tab char and size for file "+file_path.string()+" set to: "+tab_str+", "+std::to_string(tab_char_and_size.second)+".\n"); } tab_char=tab_char_and_size.first; @@ -1422,17 +1421,13 @@ void Source::ClangViewParse::update_syntax() { buffer->remove_tag_by_name(tag, buffer->begin(), buffer->end()); last_syntax_tags.clear(); for (auto &range : ranges) { - auto type = boost::lexical_cast(range.kind); - try { - last_syntax_tags.emplace(Singleton::Config::source()->clang_types.at(type)); - } catch (std::exception) { - //cout << range.kind << ": " << range.offsets.first.line << ", " << range.offsets.first.index << endl; //TODO: remove - continue; + auto type_it=Singleton::Config::source()->clang_types.find(std::to_string(range.kind)); + if(type_it!=Singleton::Config::source()->clang_types.end()) { + last_syntax_tags.emplace(type_it->second); + Gtk::TextIter begin_iter = buffer->get_iter_at_line_index(range.offsets.first.line-1, range.offsets.first.index-1); + Gtk::TextIter end_iter = buffer->get_iter_at_line_index(range.offsets.second.line-1, range.offsets.second.index-1); + buffer->apply_tag_by_name(type_it->second, begin_iter, end_iter); } - - Gtk::TextIter begin_iter = buffer->get_iter_at_line_index(range.offsets.first.line-1, range.offsets.first.index-1); - Gtk::TextIter end_iter = buffer->get_iter_at_line_index(range.offsets.second.line-1, range.offsets.second.index-1); - buffer->apply_tag_by_name(Singleton::Config::source()->clang_types.at(type), begin_iter, end_iter); } } @@ -1950,7 +1945,7 @@ void Source::ClangViewAutocomplete::autocomplete() { autocomplete_thread=std::thread([this, ac_data, line_nr, column_nr, buffer_map](){ parsing_mutex.lock(); if(!parse_thread_stop) - *ac_data=move(get_autocomplete_suggestions(line_nr, column_nr, *buffer_map)); + *ac_data=get_autocomplete_suggestions(line_nr, column_nr, *buffer_map); if(!parse_thread_stop) autocomplete_done(); else diff --git a/src/window.cc b/src/window.cc index 2a647cf..44373ad 100644 --- a/src/window.cc +++ b/src/window.cc @@ -4,7 +4,6 @@ #include "sourcefile.h" #include "config.h" //#include "api.h" -#include #include //TODO: remove using namespace std; //TODO: remove @@ -100,7 +99,7 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(directories), compil if(notebook.get_current_page()!=-1) { if(search_entry_shown && entry_box.labels.size()>0) { notebook.get_current_view()->update_search_occurrences=[this](int number){ - entry_box.labels.begin()->update(0, boost::lexical_cast(number)); + entry_box.labels.begin()->update(0, std::to_string(number)); }; notebook.get_current_view()->search_highlight(last_search, case_sensitive_search, regex_search); } @@ -327,7 +326,7 @@ void Window::create_menu() { last_char=executable_path_spaces_fixed[c]; } Singleton::terminal()->async_execute(executable_path_spaces_fixed, project_path, [this, executable_path](int exit_code){ - Singleton::terminal()->async_print(executable_path.string()+" returned: "+boost::lexical_cast(exit_code)+'\n'); + Singleton::terminal()->async_print(executable_path.string()+" returned: "+std::to_string(exit_code)+'\n'); }); } }); @@ -358,7 +357,7 @@ void Window::create_menu() { last_run_command=content; Singleton::terminal()->async_print("Running: "+content+'\n'); Singleton::terminal()->async_execute(content, directories.current_path, [this, content](int exit_code){ - Singleton::terminal()->async_print(content+" returned: "+boost::lexical_cast(exit_code)+'\n'); + Singleton::terminal()->async_print(content+" returned: "+std::to_string(exit_code)+'\n'); }); } entry_box.hide(); @@ -633,13 +632,16 @@ void Window::search_and_replace_entry() { auto label_it=entry_box.labels.begin(); label_it->update=[label_it](int state, const std::string& message){ if(state==0) { - auto number = boost::lexical_cast(message); - if(number==0) - label_it->set_text(""); - else if(number==1) - label_it->set_text("1 result found"); - else if(number>1) - label_it->set_text(boost::lexical_cast(number)+" results found"); + try { + auto number = stoi(message); + if(number==0) + label_it->set_text(""); + else if(number==1) + label_it->set_text("1 result found"); + else if(number>1) + label_it->set_text(message+" results found"); + } + catch(const std::exception &e) {} } }; entry_box.entries.emplace_back(last_search, [this](const std::string& content){ @@ -650,7 +652,7 @@ void Window::search_and_replace_entry() { search_entry_it->set_placeholder_text("Find"); if(notebook.get_current_page()!=-1) { notebook.get_current_view()->update_search_occurrences=[label_it](int number){ - label_it->update(0, boost::lexical_cast(number)); + label_it->update(0, std::to_string(number)); }; notebook.get_current_view()->search_highlight(search_entry_it->get_text(), case_sensitive_search, regex_search); } @@ -721,8 +723,8 @@ void Window::goto_line_entry() { if(notebook.get_current_page()!=-1) { auto buffer=notebook.get_current_view()->get_buffer(); try { - auto line = boost::lexical_cast(content); - if(line>0 && line<=(unsigned long)buffer->get_line_count()) { + auto line = stoi(content); + if(line>0 && line<=buffer->get_line_count()) { line--; buffer->place_cursor(buffer->get_iter_at_line(line)); while(gtk_events_pending()) @@ -762,7 +764,7 @@ void Window::rename_token_entry() { if(view->rename_similar_tokens) { auto number=view->rename_similar_tokens(*token, content); if(number>0) { - Singleton::terminal()->print("Replaced "+boost::lexical_cast(number)+" occurrences in file "+view->file_path.string()+"\n"); + Singleton::terminal()->print("Replaced "+std::to_string(number)+" occurrences in file "+view->file_path.string()+"\n"); notebook.save(c); } }