summaryrefslogtreecommitdiff
path: root/src/misc_gui.cpp
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2007-03-05 00:34:48 +0000
committerDarkvater <darkvater@openttd.org>2007-03-05 00:34:48 +0000
commitaea64adbb9ff755be303515bebb428d92e7bcc92 (patch)
tree42989af9a9c11fccbcbc9e6a9a9916bfbde95d8e /src/misc_gui.cpp
parentb3f59814de1a2dd94fcf97e63d33f85c621abe68 (diff)
downloadopenttd-aea64adbb9ff755be303515bebb428d92e7bcc92.tar.xz
(svn r9011) -Codechange (r9003): Rework Utf8PrevChar so that it returns a pointer to the previous UTF8 character's first byte instead of a byte-length offset
Diffstat (limited to 'src/misc_gui.cpp')
-rw-r--r--src/misc_gui.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index 306289eab..406cd72be 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -804,17 +804,21 @@ static void DelChar(Textbuf *tb, bool backspace)
WChar c;
uint width;
size_t len;
+ char *s = tb->buf + tb->caretpos;
- if (backspace) tb->caretpos -= Utf8PrevCharLen(tb->buf + tb->caretpos);
+ if (backspace) s = Utf8PrevChar(s);
- len = Utf8Decode(&c, tb->buf + tb->caretpos);
+ len = Utf8Decode(&c, s);
width = GetCharacterWidth(FS_NORMAL, c);
tb->width -= width;
- if (backspace) tb->caretxoffs -= width;
+ if (backspace) {
+ tb->caretpos -= len;
+ tb->caretxoffs -= width;
+ }
/* Move the remaining characters over the marker */
- memmove(tb->buf + tb->caretpos, tb->buf + tb->caretpos + len, tb->length - tb->caretpos - len + 1);
+ memmove(s, s + len, tb->length - (s - tb->buf) - len + 1);
tb->length -= len;
}
@@ -887,9 +891,9 @@ bool MoveTextBufferPos(Textbuf *tb, int navmode)
case WKC_LEFT:
if (tb->caretpos != 0) {
WChar c;
-
- tb->caretpos -= Utf8PrevCharLen(tb->buf + tb->caretpos);
- Utf8Decode(&c, tb->buf + tb->caretpos);
+ const char *s = Utf8PrevChar(tb->buf + tb->caretpos);
+ Utf8Decode(&c, s);
+ tb->caretpos = s - tb->buf; // -= (tb->buf + tb->caretpos - s)
tb->caretxoffs -= GetCharacterWidth(FS_NORMAL, c);
return true;