Skip to content

Commit

Permalink
Wide char aware string cropping
Browse files Browse the repository at this point in the history
  • Loading branch information
Code7R committed Oct 4, 2024
1 parent 386114b commit ec0ce79
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/fdomenu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include <utility> // For std::move
#include <vector>

#include <codecvt>

#include <functional>
#include <initializer_list>

Expand Down Expand Up @@ -670,11 +672,19 @@ struct AppEntry {
ret += p.after;
}
}
if (prog_name_cut > 0 && ret.size() > prog_name_cut) {
ret.erase(prog_name_cut);
trimBack(ret);
ret += ellipsis;
if (prog_name_cut > 0) {
auto u16_conv =
wstring_convert<codecvt_utf8_utf16<char16_t>, char16_t>{}
.from_bytes(ret);
if (u16_conv.size() > prog_name_cut) {
u16_conv.erase(prog_name_cut);
ret = wstring_convert<codecvt_utf8_utf16<char16_t>, char16_t>{}
.to_bytes(u16_conv);
trimBack(ret);
ret += ellipsis;
}
}

return ret;
}
};
Expand Down

0 comments on commit ec0ce79

Please sign in to comment.