From 617e5d96cb51b5c91a7b862e0a1e24289abb9fd9 Mon Sep 17 00:00:00 2001 From: eidheim Date: Thu, 5 Dec 2024 20:55:33 +0100 Subject: [PATCH] Minor improvement to space drawing code --- src/source.cpp | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/source.cpp b/src/source.cpp index 261c5cc..de31d72 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -463,28 +463,30 @@ void Source::View::configure() { std::set out; qi::phrase_parse(Config::get().source.show_whitespace_characters.begin(), Config::get().source.show_whitespace_characters.end(), (+(~qi::char_(','))) % ',', qi::space, out); - auto space_drawer = gtk_source_view_get_space_drawer(gobj()); int locations = GTK_SOURCE_SPACE_LOCATION_NONE; - if(out.count("leading") > 0) - locations |= GTK_SOURCE_SPACE_LOCATION_LEADING; - if(out.count("text") > 0) - locations |= GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT; - if(out.count("trailing") > 0) - locations |= GTK_SOURCE_SPACE_LOCATION_TRAILING; - if(out.count("all") > 0) - locations |= GTK_SOURCE_SPACE_LOCATION_ALL; int types = GTK_SOURCE_SPACE_TYPE_NONE; - if(out.count("space") > 0) - types |= GTK_SOURCE_SPACE_TYPE_SPACE; - if(out.count("tab") > 0) - types |= GTK_SOURCE_SPACE_TYPE_TAB; - if(out.count("newline") > 0) - types |= GTK_SOURCE_SPACE_TYPE_NEWLINE; - if(out.count("nbsp") > 0) - types |= GTK_SOURCE_SPACE_TYPE_NBSP; - if(out.count("all") > 0) - types |= GTK_SOURCE_SPACE_TYPE_ALL; + for(auto &e : out) { + if(e == "leading") + locations |= GTK_SOURCE_SPACE_LOCATION_LEADING; + else if(e == "text") + locations |= GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT; + else if(e == "trailing") + locations |= GTK_SOURCE_SPACE_LOCATION_TRAILING; + else if(e == "all") + locations |= GTK_SOURCE_SPACE_LOCATION_ALL; + else if(e == "space") + types |= GTK_SOURCE_SPACE_TYPE_SPACE; + else if(e == "tab") + types |= GTK_SOURCE_SPACE_TYPE_TAB; + else if(e == "newline") + types |= GTK_SOURCE_SPACE_TYPE_NEWLINE; + else if(e == "nbsp") + types |= GTK_SOURCE_SPACE_TYPE_NBSP; + else if(e == "all") + types |= GTK_SOURCE_SPACE_TYPE_ALL; + } + auto space_drawer = gtk_source_view_get_space_drawer(gobj()); if(locations != GTK_SOURCE_SPACE_LOCATION_NONE || types != GTK_SOURCE_SPACE_TYPE_NONE) { if(locations == GTK_SOURCE_SPACE_LOCATION_NONE) locations = GTK_SOURCE_SPACE_LOCATION_ALL;