diff --git a/src/client.cc b/src/client.cc index 91e2953c..c0c90336 100644 --- a/src/client.cc +++ b/src/client.cc @@ -108,7 +108,7 @@ DisplayLine Client::generate_mode_line() const if (context().buffer().is_modified()) status.push_back({ "[+]", info_face }); if (m_input_handler.is_recording()) - status.push_back({ "[recording ("_str + m_input_handler.recording_reg() + ")]", info_face }); + status.push_back({ "[recording ("_str + StringView{m_input_handler.recording_reg()} + ")]", info_face }); if (context().buffer().flags() & Buffer::Flags::New) status.push_back({ "[new file]", info_face }); if (context().user_hooks_support().is_disabled()) diff --git a/src/client_manager.cc b/src/client_manager.cc index 960763e1..66b4bf62 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -112,7 +112,7 @@ void ClientManager::ensure_no_client_uses_buffer(Buffer& buffer) if (client->context().is_editing()) throw runtime_error("client '" + client->context().name() + "' is inserting in '" + - buffer.display_name() + '\''); + buffer.display_name() + "'"); // change client context to edit the first buffer which is not the // specified one. As BufferManager stores buffer according to last diff --git a/src/command_manager.cc b/src/command_manager.cc index e3e56cfa..02d95949 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -203,7 +203,7 @@ Token parse_percent_token(StringView line, ByteCount& pos) String token = get_until_delimiter(line, pos, opening_delimiter, closing_delimiter); if (throw_on_unterminated and pos == length) - throw unterminated_string("%" + type_name + opening_delimiter, + throw unterminated_string("%" + type_name + StringView{opening_delimiter}, closing_delimiter, 0); return {type, token_start, pos, std::move(token)}; } diff --git a/src/file.cc b/src/file.cc index ae298ad2..19ef313a 100644 --- a/src/file.cc +++ b/src/file.cc @@ -87,7 +87,7 @@ String compact_path(StringView filename) char cwd[1024]; getcwd(cwd, 1024); - String real_cwd = real_path(cwd) + '/'; + String real_cwd = real_path(cwd) + "/"; if (prefix_match(real_filename, real_cwd)) return real_filename.substr(real_cwd.length()); diff --git a/src/keys.cc b/src/keys.cc index 30bdbe41..a726a8c1 100644 --- a/src/keys.cc +++ b/src/keys.cc @@ -122,7 +122,7 @@ String key_to_str(Key key) default: break; } if (named) - res = '<' + res + '>'; + res = StringView{'<'} + res + StringView{'>'}; return res; } diff --git a/src/main.cc b/src/main.cc index 847c1b2b..c66929aa 100644 --- a/src/main.cc +++ b/src/main.cc @@ -120,7 +120,7 @@ void register_env_vars() [](StringView name, const Context& context) { auto& sel = context.selections().main(); auto beg = sel.min(); - return to_string(beg.line + 1) + '.' + to_string(beg.column + 1) + '+' + + return to_string(beg.line + 1) + "." + to_string(beg.column + 1) + "+" + to_string((int)context.buffer().distance(beg, sel.max())+1); } }, { "selections_desc", @@ -132,7 +132,7 @@ void register_env_vars() auto beg = sel.min(); if (not res.empty()) res += ':'; - res += to_string(beg.line + 1) + '.' + to_string(beg.column + 1) + '+' + + res += to_string(beg.line + 1) + "." + to_string(beg.column + 1) + "+" + to_string((int)context.buffer().distance(beg, sel.max())+1); } return res; diff --git a/src/string.hh b/src/string.hh index fa55c2a2..b752d79d 100644 --- a/src/string.hh +++ b/src/string.hh @@ -44,13 +44,9 @@ public: ByteCount byte_count_to(CharCount count) const { return utf8::advance(begin(), end(), (int)count) - begin(); } CharCount char_count_to(ByteCount count) const { return utf8::distance(begin(), begin() + (int)count); } - String operator+(const String& other) const { return String{stdstr() + other.stdstr()}; } String& operator+=(const String& other) { std::string::operator+=(other); return *this; } - String operator+(const char* other) const { return String{stdstr() + other}; } String& operator+=(const char* other) { std::string::operator+=(other); return *this; } - String operator+(char other) const { return String{stdstr() + other}; } String& operator+=(char other) { std::string::operator+=(other); return *this; } - String operator+(Codepoint cp) const { String res = *this; utf8::dump(back_inserter(res), cp); return res; } String& operator+=(Codepoint cp) { utf8::dump(back_inserter(*this), cp); return *this; } StringView substr(ByteCount pos, ByteCount length = INT_MAX) const; @@ -176,34 +172,26 @@ inline StringView String::substr(CharCount pos, CharCount length) const return StringView{*this}.substr(pos, length); } -inline String operator+(const char* lhs, const String& rhs) -{ - return String(lhs) + rhs; -} - -inline String operator+(const std::string& lhs, const String& rhs) -{ - return String(lhs) + rhs; -} - -inline String operator+(const String& lhs, const std::string& rhs) -{ - return lhs + String(rhs); -} - inline String& operator+=(String& lhs, StringView rhs) { lhs.append(rhs.data(), (size_t)(int)rhs.length()); return lhs; } -inline String operator+(const char* lhs, StringView rhs) +inline String operator+(const String& lhs, const String& rhs) { String res = lhs; res += rhs; return res; } +inline String operator+(StringView lhs, StringView rhs) +{ + String res{lhs.begin(), lhs.end()}; + res += rhs; + return res; +} + inline String operator+(const String& lhs, StringView rhs) { String res = lhs; @@ -218,28 +206,24 @@ inline String operator+(StringView lhs, const String& rhs) return res; } +inline String operator+(const char* lhs, StringView rhs) +{ + return StringView{lhs} + rhs; +} + inline String operator+(StringView lhs, const char* rhs) { - String res{lhs.begin(), lhs.end()}; - res.append(rhs); - return res; + return lhs + StringView{rhs}; } -inline String operator+(char lhs, const String& rhs) +inline String operator+(const char* lhs, const String& rhs) { - return String(lhs) + rhs; + return StringView{lhs} + rhs; } -inline String operator+(Codepoint lhs, const String& rhs) +inline String operator+(const String& lhs, const char* rhs) { - return String(lhs) + rhs; -} - -inline String operator+(StringView lhs, StringView rhs) -{ - String res{lhs.begin(), lhs.end()}; - res += rhs; - return res; + return lhs + StringView{rhs}; } std::vector split(StringView str, char separator, char escape);