From ece03c3599e6cef2baa760a44f18cbf0aa653b6a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 15 Nov 2014 18:45:56 +0000 Subject: [PATCH] More const String& to StringView --- src/command_manager.cc | 13 ++++++------- src/option_manager.hh | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/command_manager.cc b/src/command_manager.cc index aa966161c..7583ac245 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -33,7 +33,7 @@ void CommandManager::register_command(String command_name, struct parse_error : runtime_error { - parse_error(const String& error) + parse_error(StringView error) : runtime_error{"parse error: " + error} {} }; @@ -122,7 +122,7 @@ String get_until_delimiter(StringView base, ByteCount& pos, struct unknown_expand : parse_error { - unknown_expand(const String& name) + unknown_expand(StringView name) : parse_error{"unknown expand '" + name + "'"} {} }; @@ -169,7 +169,7 @@ void skip_blanks_and_comments(StringView base, ByteCount& pos) struct unterminated_string : parse_error { - unterminated_string(const String& open, const String& close, int nest = 0) + unterminated_string(StringView open, StringView close, int nest = 0) : parse_error{"unterminated string '" + open + "..." + close + "'" + (nest > 0 ? "(nesting: " + to_string(nest) + ")" : "")} {} @@ -204,7 +204,7 @@ Token parse_percent_token(StringView line, ByteCount& pos) closing_delimiter); if (throw_on_unterminated and pos == length) throw unterminated_string("%" + type_name + opening_delimiter, - String{closing_delimiter}, 0); + closing_delimiter, 0); return {type, token_start, pos, std::move(token)}; } else @@ -235,8 +235,7 @@ TokenList parse(StringView line) token_start = ++pos; String token = get_until_delimiter(line, pos, delimiter); if (throw_on_unterminated and pos == length) - throw unterminated_string(String{delimiter}, - String{delimiter}); + throw unterminated_string(delimiter, delimiter); result.emplace_back(delimiter == '"' ? Token::Type::RawEval : Token::Type::Raw, token_start, pos, std::move(token)); @@ -335,7 +334,7 @@ String eval_token(const Token& token, Context& context, struct command_not_found : runtime_error { - command_not_found(const String& command) + command_not_found(StringView command) : runtime_error(command + " : no such command") {} }; diff --git a/src/option_manager.hh b/src/option_manager.hh index 387761fd1..be60bf477 100644 --- a/src/option_manager.hh +++ b/src/option_manager.hh @@ -15,7 +15,7 @@ namespace Kakoune struct option_not_found : public runtime_error { - option_not_found(const String& name) + option_not_found(StringView name) : runtime_error("option not found: " + name) {} }; @@ -210,7 +210,7 @@ public: return *opts.back(); } - bool option_exists(const String& name) const + bool option_exists(StringView name) const { return find_if(m_descs, [&name](const std::unique_ptr& opt) { return opt->name() == name;