equal
deleted
inserted
replaced
1015 } |
1015 } |
1016 |
1016 |
1017 width = length = 0; |
1017 width = length = 0; |
1018 |
1018 |
1019 for (ptr = utf8_buf; (c = Utf8Consume(&ptr)) != '\0';) { |
1019 for (ptr = utf8_buf; (c = Utf8Consume(&ptr)) != '\0';) { |
1020 byte charwidth; |
|
1021 |
|
1022 if (!IsPrintable(c)) break; |
1020 if (!IsPrintable(c)) break; |
1023 if (tb->length + length >= tb->maxlength - 1) break; |
1021 |
1024 charwidth = GetCharacterWidth(FS_NORMAL, c); |
1022 size_t len = Utf8CharLen(c); |
1025 |
1023 if (tb->length + length >= tb->maxlength - (uint16)len) break; |
|
1024 |
|
1025 byte charwidth = GetCharacterWidth(FS_NORMAL, c); |
1026 if (tb->maxwidth != 0 && width + tb->width + charwidth > tb->maxwidth) break; |
1026 if (tb->maxwidth != 0 && width + tb->width + charwidth > tb->maxwidth) break; |
1027 |
1027 |
1028 width += charwidth; |
1028 width += charwidth; |
1029 length += Utf8CharLen(c); |
1029 length += len; |
1030 } |
1030 } |
1031 |
1031 |
1032 if (length == 0) return false; |
1032 if (length == 0) return false; |
1033 |
1033 |
1034 memmove(tb->buf + tb->caretpos + length, tb->buf + tb->caretpos, tb->length - tb->caretpos); |
1034 memmove(tb->buf + tb->caretpos + length, tb->buf + tb->caretpos, tb->length - tb->caretpos); |
1036 tb->width += width; |
1036 tb->width += width; |
1037 tb->caretxoffs += width; |
1037 tb->caretxoffs += width; |
1038 |
1038 |
1039 tb->length += length; |
1039 tb->length += length; |
1040 tb->caretpos += length; |
1040 tb->caretpos += length; |
|
1041 assert(tb->length < tb->maxlength); |
1041 tb->buf[tb->length] = '\0'; // terminating zero |
1042 tb->buf[tb->length] = '\0'; // terminating zero |
1042 |
1043 |
1043 return true; |
1044 return true; |
1044 } |
1045 } |
1045 |
1046 |