Browse Source

Replace to_string and stoi with lexical_cast

merge-requests/365/head
Jørgen Lien Sellæg 10 years ago
parent
commit
c3c9e09722
  1. 3
      src/source.cc
  2. 15
      src/window.cc

3
src/source.cc

@ -7,6 +7,7 @@
#include <regex> #include <regex>
#include "singletons.h" #include "singletons.h"
#include <gtksourceview/gtksource.h> #include <gtksourceview/gtksource.h>
#include <boost/lexical_cast.hpp>
#include <iostream> //TODO: remove #include <iostream> //TODO: remove
using namespace std; //TODO: remove using namespace std; //TODO: remove
@ -601,7 +602,7 @@ void Source::ClangViewParse::update_syntax() {
buffer->remove_tag_by_name(tag, buffer->begin(), buffer->end()); buffer->remove_tag_by_name(tag, buffer->begin(), buffer->end());
last_syntax_tags.clear(); last_syntax_tags.clear();
for (auto &range : ranges) { for (auto &range : ranges) {
auto type = std::to_string(range.kind); auto type = boost::lexical_cast<std::string>(range.kind);
try { try {
last_syntax_tags.emplace(Singleton::Config::source()->types.at(type)); last_syntax_tags.emplace(Singleton::Config::source()->types.at(type));
} catch (std::exception) { } catch (std::exception) {

15
src/window.cc

@ -4,6 +4,7 @@
#include "sourcefile.h" #include "sourcefile.h"
#include "config.h" #include "config.h"
#include "api.h" #include "api.h"
#include <boost/lexical_cast.hpp>
#include <iostream> //TODO: remove #include <iostream> //TODO: remove
using namespace std; //TODO: remove using namespace std; //TODO: remove
@ -76,7 +77,7 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(directories), compil
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
if(search_entry_shown && entry_box.labels.size()>0) { if(search_entry_shown && entry_box.labels.size()>0) {
notebook.get_current_view()->update_search_occurrences=[this](int number){ notebook.get_current_view()->update_search_occurrences=[this](int number){
entry_box.labels.begin()->update(0, std::to_string(number)); entry_box.labels.begin()->update(0, boost::lexical_cast<std::string>(number));
}; };
notebook.get_current_view()->search_highlight(last_search, case_sensitive_search, regex_search); notebook.get_current_view()->search_highlight(last_search, case_sensitive_search, regex_search);
} }
@ -235,7 +236,7 @@ void Window::create_menu() {
compile_success(); compile_success();
//TODO: Windows... //TODO: Windows...
Singleton::terminal()->async_execute(executable_path.string(), project_path, [this, executable_path](int exit_code){ Singleton::terminal()->async_execute(executable_path.string(), project_path, [this, executable_path](int exit_code){
Singleton::terminal()->async_print(executable_path.string()+" returned: "+std::to_string(exit_code)+'\n'); Singleton::terminal()->async_print(executable_path.string()+" returned: "+boost::lexical_cast<std::string>(exit_code)+'\n');
}); });
} }
}); });
@ -270,7 +271,7 @@ void Window::create_menu() {
last_run_command=content; last_run_command=content;
Singleton::terminal()->async_print("Running: "+content+'\n'); Singleton::terminal()->async_print("Running: "+content+'\n');
Singleton::terminal()->async_execute(content, directories.current_path, [this, content](int exit_code){ Singleton::terminal()->async_execute(content, directories.current_path, [this, content](int exit_code){
Singleton::terminal()->async_print(content+" returned: "+std::to_string(exit_code)+'\n'); Singleton::terminal()->async_print(content+" returned: "+boost::lexical_cast<std::string>(exit_code)+'\n');
}); });
} }
entry_box.hide(); entry_box.hide();
@ -509,13 +510,13 @@ void Window::search_and_replace_entry() {
auto label_it=entry_box.labels.begin(); auto label_it=entry_box.labels.begin();
label_it->update=[label_it](int state, const std::string& message){ label_it->update=[label_it](int state, const std::string& message){
if(state==0) { if(state==0) {
int number=stoi(message); auto number = boost::lexical_cast<int>(message);
if(number==0) if(number==0)
label_it->set_text(""); label_it->set_text("");
else if(number==1) else if(number==1)
label_it->set_text("1 result found"); label_it->set_text("1 result found");
else if(number>1) else if(number>1)
label_it->set_text(std::to_string(number)+" results found"); label_it->set_text(boost::lexical_cast<std::string>(number)+" results found");
} }
}; };
entry_box.entries.emplace_back(last_search, [this](const std::string& content){ entry_box.entries.emplace_back(last_search, [this](const std::string& content){
@ -526,7 +527,7 @@ void Window::search_and_replace_entry() {
search_entry_it->set_placeholder_text("Find"); search_entry_it->set_placeholder_text("Find");
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
notebook.get_current_view()->update_search_occurrences=[label_it](int number){ notebook.get_current_view()->update_search_occurrences=[label_it](int number){
label_it->update(0, std::to_string(number)); label_it->update(0, boost::lexical_cast<std::string>(number));
}; };
notebook.get_current_view()->search_highlight(search_entry_it->get_text(), case_sensitive_search, regex_search); notebook.get_current_view()->search_highlight(search_entry_it->get_text(), case_sensitive_search, regex_search);
} }
@ -642,7 +643,7 @@ void Window::rename_token_entry() {
if(notebook.get_view(c)->rename_similar_tokens) { if(notebook.get_view(c)->rename_similar_tokens) {
auto number=notebook.get_view(c)->rename_similar_tokens(*token, content); auto number=notebook.get_view(c)->rename_similar_tokens(*token, content);
if(number>0) { if(number>0) {
Singleton::terminal()->print("Replaced "+std::to_string(number)+" occurrences in file "+notebook.get_view(c)->file_path.string()+"\n"); Singleton::terminal()->print("Replaced "+boost::lexical_cast<std::string>(number)+" occurrences in file "+notebook.get_view(c)->file_path.string()+"\n");
notebook.save(c); notebook.save(c);
} }
} }

Loading…
Cancel
Save