aboutsummaryrefslogtreecommitdiff
path: root/src/plain.cc
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-11-29 21:40:02 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-11-29 21:40:02 +0100
commita3daa9910dfbfc0fc6b57ec37ad712fbc19b1e01 (patch)
tree1e2aa63886a04d08ba18fe37441bb55580365e4f /src/plain.cc
parentba9c7b7e9afdfcc01b5a35c4c387642925b1bf9a (diff)
respect UTF-8 when splitting long lines in plain.cc (noticed by corvid)
When splitting long lines in plain text to avoid X11 coordinate overflows we need to make sure that multibyte UTF-8 chars are not split. Additionally combining chars like accents should stay together with their base char.
Diffstat (limited to 'src/plain.cc')
-rw-r--r--src/plain.cc22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/plain.cc b/src/plain.cc
index a610e174..394c4ca5 100644
--- a/src/plain.cc
+++ b/src/plain.cc
@@ -135,20 +135,16 @@ bool DilloPlain::PlainLinkReceiver::press (Widget *widget, int, int, int, int,
void DilloPlain::addLine(char *Buf, uint_t BufSize)
{
- uint_t remaining;
- char *dp, *data;
- const uint_t maxWordLen = 128; // Limit word len to avoid X11 coordinate
- // overflow with extremely long lines.
- dp = data = a_Misc_expand_tabs(Buf, BufSize);
- remaining = strlen(data);
- while (remaining > maxWordLen) {
- DW2TB(dw)->addText(dp, maxWordLen, widgetStyle);
- remaining -= maxWordLen;
- dp += maxWordLen;
- }
- DW2TB(dw)->addText(dp, widgetStyle);
+ int len;
+ char buf[128];
+ char *end = Buf + BufSize;
+
+ // Limit word len to avoid X11 coordinate
+ // overflow with extremely long lines.
+ while ((len = a_Misc_expand_tabs(&Buf, end, buf, sizeof(buf))))
+ DW2TB(dw)->addText(buf, len, widgetStyle);
+
DW2TB(dw)->addParbreak(0, widgetStyle);
- dFree(data);
}
/*