From 49a5bbf3ca441e71cdeea376a2809b289efc5b33 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Fri, 11 Dec 2015 22:58:28 +0300 Subject: Ensure that at least one character follows a ',' or a '+' sign in a face description (respectively a background color and attributes). --- src/face_registry.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/face_registry.cc b/src/face_registry.cc index 5e10c540..79781c24 100644 --- a/src/face_registry.cc +++ b/src/face_registry.cc @@ -9,10 +9,15 @@ namespace Kakoune static Face parse_face(StringView facedesc) { + const String invalid_face_error = "invalid face description, expected [,][+]"; auto bg_it = find(facedesc, ','); auto attr_it = find(facedesc, '+'); - if (bg_it != facedesc.end() and attr_it < bg_it) - throw runtime_error("invalid face description, expected [,][+]"); + if (bg_it != facedesc.end() + 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; res.fg = attr_it != facedesc.begin() ? str_to_color({facedesc.begin(), std::min(attr_it, bg_it)}) : Color::Default; -- cgit v1.2.3 From bd56ed5faded9a0da2f6071d1816a9308afb0187 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Sat, 12 Dec 2015 12:00:52 +0300 Subject: Avoid instanciation of a `String` object everytime the `parse_color` function is called. --- src/face_registry.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/face_registry.cc b/src/face_registry.cc index 79781c24..cf404e63 100644 --- a/src/face_registry.cc +++ b/src/face_registry.cc @@ -9,15 +9,15 @@ namespace Kakoune static Face parse_face(StringView facedesc) { - const String invalid_face_error = "invalid face description, expected [,][+]"; + constexpr StringView invalid_face_error = "invalid face description, expected [,][+]"; auto bg_it = find(facedesc, ','); auto attr_it = find(facedesc, '+'); if (bg_it != facedesc.end() and (attr_it < bg_it or (bg_it + 1) == facedesc.end())) - throw runtime_error(invalid_face_error); + throw runtime_error(invalid_face_error.str()); if (attr_it != facedesc.end() and (attr_it + 1) == facedesc.end()) - throw runtime_error(invalid_face_error); + throw runtime_error(invalid_face_error.str()); Face res; res.fg = attr_it != facedesc.begin() ? str_to_color({facedesc.begin(), std::min(attr_it, bg_it)}) : Color::Default; -- cgit v1.2.3