summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/commands.cc6
-rw-r--r--src/string.cc11
-rw-r--r--src/string.hh2
3 files changed, 16 insertions, 3 deletions
diff --git a/src/commands.cc b/src/commands.cc
index 2740d131..ec615515 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -1015,7 +1015,7 @@ void define_command(const ParametersParser& parser, Context& context, const Shel
};
}
- auto docstring = parser.get_switch("docstring").value_or(StringView{});
+ auto docstring = trim_whitespaces(parser.get_switch("docstring").value_or(StringView{}));
cm.register_command(cmd_name, cmd, docstring.str(), desc, flags, CommandHelper{}, completer);
}
@@ -1351,7 +1351,7 @@ const CommandDesc declare_option_cmd = {
if (parser.get_switch("hidden"))
flags = OptionFlags::Hidden;
- auto docstring = parser.get_switch("docstring").value_or(StringView{}).str();
+ auto docstring = trim_whitespaces(parser.get_switch("docstring").value_or(StringView{})).str();
OptionsRegistry& reg = GlobalScope::instance().option_registry();
@@ -1443,7 +1443,7 @@ const CommandDesc map_key_cmd = {
KeyList mapping = parse_keys(parser[3]);
keymaps.map_key(key[0], keymap_mode, std::move(mapping),
- parser.get_switch("docstring").value_or("").str());
+ trim_whitespaces(parser.get_switch("docstring").value_or("")).str());
}
};
diff --git a/src/string.cc b/src/string.cc
index 18ae5d80..6fb64098 100644
--- a/src/string.cc
+++ b/src/string.cc
@@ -207,6 +207,17 @@ Vector<StringView> split(StringView str, char separator)
return res;
}
+StringView trim_whitespaces(StringView str)
+{
+ auto beg = str.begin(), end = str.end();
+ while (beg != end and is_blank(*beg))
+ ++beg;
+ while (beg != end and is_blank(*(end-1)))
+ --end;
+ return {beg, end};
+}
+
+
String escape(StringView str, StringView characters, char escape)
{
String res;
diff --git a/src/string.hh b/src/string.hh
index 056db814..bfafa482 100644
--- a/src/string.hh
+++ b/src/string.hh
@@ -333,6 +333,8 @@ inline StringView operator"" _sv(const char* str, size_t)
Vector<String> split(StringView str, char separator, char escape);
Vector<StringView> split(StringView str, char separator);
+StringView trim_whitespaces(StringView str);
+
String escape(StringView str, StringView characters, char escape);
String unescape(StringView str, StringView characters, char escape);