summaryrefslogtreecommitdiff
path: root/src/ui.cc
diff options
context:
space:
mode:
authorcorvid <corvid@lavabit.com>2009-05-17 12:04:13 -0400
committercorvid <corvid@lavabit.com>2009-05-17 12:04:13 -0400
commit5ff1a29d501f97a01c983ef62f4e6b76b7814785 (patch)
tree4fcf1ba4d94e1d76bc65ac7ea3addea0dfa2a129 /src/ui.cc
parentf15858539330c89f607d039fc51979c432c5192c (diff)
New utility function: a_Utf8_end_of_char()
Diffstat (limited to 'src/ui.cc')
-rw-r--r--src/ui.cc15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/ui.cc b/src/ui.cc
index 15007280..8b24d1b2 100644
--- a/src/ui.cc
+++ b/src/ui.cc
@@ -29,6 +29,7 @@
#include "ui.hh"
#include "msg.h"
#include "timeout.hh"
+#include "utf8.hh"
using namespace fltk;
@@ -1068,17 +1069,13 @@ void UI::set_tab_title(const char *label)
snprintf(title, 128, "Dillo: %s", label);
if (*label) {
// Make a label for this tab
- size_t tab_chars = 18;
+ size_t tab_chars = 18, label_len = strlen(label);
+
+ if (label_len > tab_chars)
+ tab_chars = a_Utf8_end_of_char(label, tab_chars - 1) + 1;
snprintf(title, tab_chars + 1, "%s", label);
- if (strlen(label) > tab_chars) {
- while (label[tab_chars] & 0x80 && !(label[tab_chars] & 0x40) &&
- tab_chars < 23) {
- // In the middle of a multibyte UTF-8 character.
- title[tab_chars] = label[tab_chars];
- tab_chars++;
- }
+ if (label_len > tab_chars)
snprintf(title + tab_chars, 4, "...");
- }
// Avoid unnecessary redraws
if (strcmp(this->label(), title)) {
this->copy_label(title);