Trim whitespaces surrounding docstrings

Closes #1439
This commit is contained in:
Maxime Coste 2017-06-16 10:48:14 +01:00
parent d7806249d9
commit f0f2b1c383
3 changed files with 16 additions and 3 deletions

View File

@ -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());
}
};

View File

@ -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;

View File

@ -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);