Switch from utfcpp to Glib::ustring for UTF-8 string mangling.

This commit is contained in:
Skirmantas Kligys 2020-02-02 14:35:07 -08:00
parent af2528952b
commit ea9591baea
3 changed files with 8 additions and 33 deletions

View File

@ -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,

View File

@ -1,6 +1,5 @@
#include "modules/clock.hpp"
#include <sstream>
#include <utf8.h>
using zoned_time = date::zoned_time<std::chrono::system_clock::duration>;
@ -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";
}

View File

@ -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