mirror of
https://github.com/clangen/musikcube.git
synced 2024-11-19 20:13:36 +00:00
Merge pull request #126 from stephanwilliams/master
Truncate should use display width instead of # characters
This commit is contained in:
commit
05ef79494d
@ -48,11 +48,14 @@ namespace cursespp {
|
||||
/* not a simple substr anymore, gotta deal with multi-byte
|
||||
characters... */
|
||||
if (u8cols(str) > len) {
|
||||
auto prev = str.begin();
|
||||
auto it = str.begin();
|
||||
auto end = str.end();
|
||||
|
||||
size_t c = 0;
|
||||
while (c < len && it != str.end()) {
|
||||
size_t cols = 0;
|
||||
while (cols <= len && it != str.end()) {
|
||||
prev = it;
|
||||
|
||||
try {
|
||||
utf8::next(it, end);
|
||||
}
|
||||
@ -61,10 +64,10 @@ namespace cursespp {
|
||||
++it;
|
||||
}
|
||||
|
||||
++c;
|
||||
cols += u8cols(std::string(prev, it));
|
||||
}
|
||||
|
||||
return std::string(str.begin(), it);
|
||||
return std::string(str.begin(), prev);
|
||||
}
|
||||
|
||||
return str;
|
||||
@ -72,7 +75,14 @@ namespace cursespp {
|
||||
|
||||
std::string Ellipsize(const std::string& str, size_t len) {
|
||||
if (u8cols(str) > len) {
|
||||
return Truncate(str, len - 2) + "..";
|
||||
std::string trunc = Truncate(str, len - 2);
|
||||
|
||||
size_t tlen = u8cols(trunc);
|
||||
for (size_t i = tlen; i < len; i++) {
|
||||
trunc += ".";
|
||||
}
|
||||
|
||||
return trunc;
|
||||
}
|
||||
|
||||
return str;
|
||||
|
Loading…
Reference in New Issue
Block a user