mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-11 01:37:41 +03:00
Do not allow / in highlighter names as it is used for hierachies
/ are replaced with <slash> in the highlighter names. Fixes #553
This commit is contained in:
parent
318f1ae781
commit
8bd3395d4d
@ -14,6 +14,8 @@ void HighlighterGroup::highlight(const Context& context, HighlightFlags flags,
|
||||
|
||||
void HighlighterGroup::add_child(HighlighterAndId&& hl)
|
||||
{
|
||||
hl.first = replace(hl.first, "/", "<slash>");
|
||||
|
||||
if (m_highlighters.contains(hl.first))
|
||||
throw runtime_error(format("duplicate id: '{}'", hl.first));
|
||||
|
||||
|
@ -241,6 +241,22 @@ String indent(StringView str, StringView indent)
|
||||
return res;
|
||||
}
|
||||
|
||||
String replace(StringView str, StringView substr, StringView replacement)
|
||||
{
|
||||
String res;
|
||||
for (auto it = str.begin(); it != str.end(); )
|
||||
{
|
||||
auto match = std::search(it, str.end(), substr.begin(), substr.end());
|
||||
res += StringView{it, match};
|
||||
if (match == str.end())
|
||||
break;
|
||||
|
||||
res += replacement;
|
||||
it = match + (int)substr.length();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Optional<int> str_to_int_ifp(StringView str)
|
||||
{
|
||||
unsigned int res = 0;
|
||||
@ -503,6 +519,8 @@ UnitTest test_string{[]()
|
||||
kak_assert(str_to_int(to_string(INT_MIN)) == INT_MIN);
|
||||
kak_assert(str_to_int("00") == 0);
|
||||
kak_assert(str_to_int("-0") == 0);
|
||||
|
||||
kak_assert(replace("tchou/tcha/tchi", "/", "!!") == "tchou!!tcha!!tchi");
|
||||
}};
|
||||
|
||||
}
|
||||
|
@ -280,6 +280,8 @@ String unescape(StringView str, StringView characters, char escape);
|
||||
|
||||
String indent(StringView str, StringView indent = " ");
|
||||
|
||||
String replace(StringView str, StringView substr, StringView replacement);
|
||||
|
||||
template<typename Container>
|
||||
String join(const Container& container, char joiner, bool esc_joiner = true)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user