summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-06-01 19:06:35 +0100
committerMaxime Coste <frrrwww@gmail.com>2015-06-01 19:06:35 +0100
commitf19bb4fe6d1de14f9539768ad9a67391fc52ed87 (patch)
tree54ff5c0da1702afb910abe6d341b9e66f5f65cbd /src
parent57a03d84955a3811a029f7190b00f50b00af5521 (diff)
Port more code to use the format function instead of adhoc string concat
Diffstat (limited to 'src')
-rw-r--r--src/buffer_manager.cc2
-rw-r--r--src/file.cc2
-rw-r--r--src/highlighter_group.cc2
-rw-r--r--src/highlighters.cc2
-rw-r--r--src/main.cc6
-rw-r--r--src/normal.cc6
-rw-r--r--src/option_types.hh2
-rw-r--r--src/regex.cc2
-rw-r--r--src/remote.cc4
-rw-r--r--src/shell_manager.cc8
-rw-r--r--src/string.hh2
11 files changed, 17 insertions, 21 deletions
diff --git a/src/buffer_manager.cc b/src/buffer_manager.cc
index 09ee1aca..43aa2f58 100644
--- a/src/buffer_manager.cc
+++ b/src/buffer_manager.cc
@@ -86,7 +86,7 @@ Buffer& BufferManager::get_buffer(StringView name)
{
Buffer* res = get_buffer_ifp(name);
if (not res)
- throw runtime_error("no such buffer '"_str + name + "'");
+ throw runtime_error(format("no such buffer '{}'", name));
return *res;
}
diff --git a/src/file.cc b/src/file.cc
index bc68e6f1..adbb37cc 100644
--- a/src/file.cc
+++ b/src/file.cc
@@ -28,7 +28,7 @@ String parse_filename(StringView filename)
{
if (filename.length() >= 1 and filename[0_byte] == '~' and
(filename.length() == 1 or filename[1_byte] == '/'))
- return parse_filename("$HOME"_str + filename.substr(1_byte));
+ return parse_filename("$HOME" + filename.substr(1_byte));
ByteCount pos = 0;
String result;
diff --git a/src/highlighter_group.cc b/src/highlighter_group.cc
index ecaafa95..8a9d364f 100644
--- a/src/highlighter_group.cc
+++ b/src/highlighter_group.cc
@@ -31,7 +31,7 @@ Highlighter& HighlighterGroup::get_child(StringView path)
StringView id(path.begin(), sep_it);
auto it = m_highlighters.find(id);
if (it == m_highlighters.end())
- throw child_not_found("no such id: "_str + id);
+ throw child_not_found("no such id: " + id);
if (sep_it == path.end())
return *it->second;
else
diff --git a/src/highlighters.cc b/src/highlighters.cc
index aa1e09eb..a7e5b47a 100644
--- a/src/highlighters.cc
+++ b/src/highlighters.cc
@@ -1150,7 +1150,7 @@ public:
StringView id(path.begin(), sep_it);
auto it = m_groups.find(id);
if (it == m_groups.end())
- throw child_not_found("no such id: "_str + id);
+ throw child_not_found(format("no such id: {}", id));
if (sep_it == path.end())
return it->second;
else
diff --git a/src/main.cc b/src/main.cc
index 7c7dc86d..b38ccc26 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -390,12 +390,12 @@ int run_server(StringView session, StringView init_command,
if (not ignore_kakrc) try
{
Context initialisation_context{Context::EmptyContextFlag{}};
- command_manager.execute("source " + runtime_directory() + "/kakrc",
+ command_manager.execute(format("source {}/kakrc", runtime_directory()),
initialisation_context);
}
catch (Kakoune::runtime_error& error)
{
- write_debug("error while parsing kakrc:\n "_str + error.what());
+ write_debug(format("error while parsing kakrc:\n {}", error.what()));
}
catch (Kakoune::client_removed&)
{
@@ -419,7 +419,7 @@ int run_server(StringView session, StringView init_command,
}
catch (Kakoune::runtime_error& error)
{
- write_debug("error while opening command line files: "_str + error.what());
+ write_debug(format("error while opening command line files: {}", error.what()));
}
else
new Buffer("*scratch*", Buffer::Flags::None);
diff --git a/src/normal.cc b/src/normal.cc
index 6ca83ab2..ef4231bf 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -585,14 +585,14 @@ void regex_prompt(Context& context, const String prompt, T func)
catch (RegexError& err)
{
if (event == PromptEvent::Validate)
- throw runtime_error("regex error: "_str + err.what());
+ throw runtime_error(format("regex error: {}", err.what()));
else
context.input_handler().set_prompt_face(get_face("Error"));
}
catch (std::runtime_error& err)
{
if (event == PromptEvent::Validate)
- throw runtime_error("regex error: "_str + err.what());
+ throw runtime_error(format("regex error: {}", err.what()));
else
{
context.input_handler().set_prompt_face(get_face("Error"));
@@ -643,7 +643,7 @@ void search_next(Context& context, NormalParams params)
}
catch (RegexError& err)
{
- throw runtime_error("regex error: "_str + err.what());
+ throw runtime_error(format("regex error: ", err.what()));
}
}
else
diff --git a/src/option_types.hh b/src/option_types.hh
index a8fd7d78..265d3c23 100644
--- a/src/option_types.hh
+++ b/src/option_types.hh
@@ -178,7 +178,7 @@ inline void option_from_string(StringView str, LineAndColumn<EffectiveType, Line
{
auto vals = split(str, tuple_separator);
if (vals.size() != 2)
- throw runtime_error("expected <line>"_str + tuple_separator + "<column>");
+ throw runtime_error(format("expected <line>{}<column>", tuple_separator));
opt.line = str_to_int(vals[0]);
opt.column = str_to_int(vals[1]);
}
diff --git a/src/regex.cc b/src/regex.cc
index 4df06dc6..d678a62a 100644
--- a/src/regex.cc
+++ b/src/regex.cc
@@ -19,7 +19,7 @@ void option_from_string(StringView str, Regex& re)
}
catch (RegexError& err)
{
- throw runtime_error("unable to create regex: "_str + err.what());
+ throw runtime_error(format("unable to create regex: {}", err.what()));
}
}
diff --git a/src/remote.cc b/src/remote.cc
index 94cdd6c4..05da041c 100644
--- a/src/remote.cc
+++ b/src/remote.cc
@@ -624,10 +624,10 @@ Server::Server(String session_name)
sockaddr_un addr = session_addr(m_session);
if (bind(listen_sock, (sockaddr*) &addr, sizeof(sockaddr_un)) == -1)
- throw runtime_error("unable to bind listen socket "_str + addr.sun_path);
+ throw runtime_error(format("unable to bind listen socket '{}'", addr.sun_path));
if (listen(listen_sock, 4) == -1)
- throw runtime_error("unable to listen on socket "_str + addr.sun_path);
+ throw runtime_error(format("unable to listen on socket '{}'", addr.sun_path));
auto accepter = [this](FDWatcher& watcher, EventMode mode) {
sockaddr_un client_addr;
diff --git a/src/shell_manager.cc b/src/shell_manager.cc
index 15453296..a7dae6cb 100644
--- a/src/shell_manager.cc
+++ b/src/shell_manager.cc
@@ -18,11 +18,7 @@ static const Regex env_var_regex(R"(\bkak_(\w+)\b)");
ShellManager::ShellManager()
{
const char* path = getenv("PATH");
- String new_path;
- if (path)
- new_path = path + ":"_str;
-
- new_path += split_path(get_kak_binary_path()).first;
+ auto new_path = format("{}:{}", path, split_path(get_kak_binary_path()).first);
setenv("PATH", new_path.c_str(), 1);
}
@@ -98,7 +94,7 @@ std::pair<String, int> ShellManager::eval(
else try
{
String value = get_val(name, context);
- setenv(("kak_"_str + name).c_str(), value.c_str(), 1);
+ setenv(format("kak_{}", name).c_str(), value.c_str(), 1);
}
catch (runtime_error&) {}
}
diff --git a/src/string.hh b/src/string.hh
index 2108c64e..5d3855f1 100644
--- a/src/string.hh
+++ b/src/string.hh
@@ -132,7 +132,7 @@ public:
constexpr StringView() = default;
constexpr StringView(const char* data, ByteCount length)
: m_data{data}, m_length{length} {}
- constexpr StringView(const char* data) : m_data{data}, m_length{strlen(data)} {}
+ constexpr StringView(const char* data) : m_data{data}, m_length{data ? strlen(data) : 0} {}
constexpr StringView(const char* begin, const char* end) : m_data{begin}, m_length{(int)(end - begin)} {}
StringView(const String& str) : m_data{str.data()}, m_length{(int)str.length()} {}
StringView(const char& c) : m_data(&c), m_length(1) {}