From ea9591baea2e661829a7509ad51c681dc4925dff Mon Sep 17 00:00:00 2001 From: Skirmantas Kligys Date: Sun, 2 Feb 2020 14:35:07 -0800 Subject: [PATCH] Switch from utfcpp to Glib::ustring for UTF-8 string mangling. --- meson.build | 4 +--- src/modules/clock.cpp | 28 +++++++--------------------- subprojects/utfcpp.wrap | 9 --------- 3 files changed, 8 insertions(+), 33 deletions(-) delete mode 100644 subprojects/utfcpp.wrap diff --git a/meson.build b/meson.build index 812cc42..69439ac 100644 --- a/meson.build +++ b/meson.build @@ -67,7 +67,6 @@ gtk_layer_shell = dependency('gtk-layer-shell-0', fallback : ['gtk-layer-shell', 'gtk_layer_shell_dep']) systemd = dependency('systemd', required: get_option('systemd')) tz_dep = dependency('date', default_options : [ 'use_system_tzdb=true' ], fallback: [ 'date', 'tz_dep' ]) -utfcpp = dependency('utfcpp', fallback: [ 'utfcpp', 'utfcpp_dep' ]) prefix = get_option('prefix') conf_data = configuration_data() @@ -169,8 +168,7 @@ executable( libudev, libmpdclient, gtk_layer_shell, - tz_dep, - utfcpp + tz_dep ], include_directories: [include_directories('include')], install: true, diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index f918137..5efca40 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -1,6 +1,5 @@ #include "modules/clock.hpp" #include -#include using zoned_time = date::zoned_time; @@ -11,31 +10,18 @@ struct waybar_time { namespace { -size_t utf8_strlen(const std::string& s) { - return utf8::distance(s.begin(), s.end()); -} - -std::string utf8_substr(const std::string s, size_t len) { - utf8::iterator it(s.begin(), s.begin(), s.end()); - for (size_t i = 0; i < len; ++i) { - ++it; - } - int byte_count = it.base() - s.begin(); - return s.substr(0, byte_count); -} - void weekdays_header(const std::locale& locale, const date::weekday& first_dow, std::ostream& os) { auto wd = first_dow; do { if (wd != first_dow) os << ' '; - auto wd_string = date::format(locale, "%a", wd); - auto wd_string_len = utf8_strlen(wd_string); - if (wd_string_len > 2) { - wd_string = utf8_substr(wd_string, 2); - wd_string_len = 2; + Glib::ustring wd_ustring(date::format(locale, "%a", wd)); + auto wd_len = wd_ustring.length(); + if (wd_len > 2) { + wd_ustring = wd_ustring.substr(0, 2); + wd_len = 2; } - const std::string pad(2 - wd_string_len, ' '); - os << pad << wd_string; + const std::string pad(2 - wd_len, ' '); + os << pad << wd_ustring; } while (++wd != first_dow); os << "\n"; } diff --git a/subprojects/utfcpp.wrap b/subprojects/utfcpp.wrap deleted file mode 100644 index 51cf131..0000000 --- a/subprojects/utfcpp.wrap +++ /dev/null @@ -1,9 +0,0 @@ -[wrap-file] -directory = utfcpp-2.3.5 -source_url = https://github.com/nemtrif/utfcpp/archive/v2.3.5.zip -source_filename = utfcpp-2.3.5.zip -source_hash = 1d5cb7d908202d734ec35b84087400013f352ffb4612e978ffb948986b76df14 - -patch_url = https://github.com/mesonbuild/utfcpp/releases/download/2.3.5-1/utfcpp.zip -patch_filename = utfcpp-2.3.5-1-wrap.zip -patch_hash = 5f504de947b34bb5995fcdb66a1ea1392288076a9400ead829da79e73441a13f