Ensure that at least one character follows a ',' or a '+' sign in a face
description (respectively a background color and attributes).
This commit is contained in:
parent
1ed866dbf0
commit
49a5bbf3ca
|
@ -9,10 +9,15 @@ namespace Kakoune
|
||||||
|
|
||||||
static Face parse_face(StringView facedesc)
|
static Face parse_face(StringView facedesc)
|
||||||
{
|
{
|
||||||
|
const String invalid_face_error = "invalid face description, expected <fg>[,<bg>][+<attr>]";
|
||||||
auto bg_it = find(facedesc, ',');
|
auto bg_it = find(facedesc, ',');
|
||||||
auto attr_it = find(facedesc, '+');
|
auto attr_it = find(facedesc, '+');
|
||||||
if (bg_it != facedesc.end() and attr_it < bg_it)
|
if (bg_it != facedesc.end()
|
||||||
throw runtime_error("invalid face description, expected <fg>[,<bg>][+<attr>]");
|
and (attr_it < bg_it or (bg_it + 1) == facedesc.end()))
|
||||||
|
throw runtime_error(invalid_face_error);
|
||||||
|
if (attr_it != facedesc.end()
|
||||||
|
and (attr_it + 1) == facedesc.end())
|
||||||
|
throw runtime_error(invalid_face_error);
|
||||||
Face res;
|
Face res;
|
||||||
res.fg = attr_it != facedesc.begin() ?
|
res.fg = attr_it != facedesc.begin() ?
|
||||||
str_to_color({facedesc.begin(), std::min(attr_it, bg_it)}) : Color::Default;
|
str_to_color({facedesc.begin(), std::min(attr_it, bg_it)}) : Color::Default;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user