refactor: extract utf8 truncation logic to utility

Move the UTF-8 visual-width measurement and truncation helper functions
from the mpris module to a common utility
(include/util/utf8_string.hpp and src/util/utf8_string.cpp).

This decouples string truncation and width measurement
from the mpris module, allowing other modules (like mpd) to reuse.
The helper function `utf8_truncate` (formerly `truncate` in mpris)
and `utf8_width` is exported under the `waybar::util` namespace,
while the low-level `measure_and_truncate` (formerly `utf8_truncate`)
is encapsulated in an anonymous namespace in src/util/utf8_string.cpp
to avoid unnecessary API exposure.

No functional changes were made to the mpris module's behavior.
This commit is contained in:
Siriusuna
2026-05-22 02:52:40 +08:00
parent 05945748dc
commit f8cc7173ca
4 changed files with 79 additions and 55 deletions
+2 -1
View File
@@ -186,7 +186,8 @@ src_files = files(
'src/util/icon_loader.cpp',
'src/util/regex_collection.cpp',
'src/util/css_reload_helper.cpp',
'src/util/transform_8bit_to_rgba.cpp'
'src/util/transform_8bit_to_rgba.cpp',
'src/util/utf8_string.cpp'
)
man_files = files(