Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-07-09 10:21:45 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-07-09 10:21:45 +0400
commitd4ff53b760f51d791860b25385f2f9716740d586 (patch)
tree6849d8fe81f9352b10d3e113d64e5057040cf7ea /source/blender/blenlib/intern/string_utf8.c
parent750b30c7dda4b46eb41f0ad611bae0a739b34610 (diff)
fix [#36066] crash when Tab out text object
the way Curve.len is used at the moment is really stupid, calculate string size on save for now, but should really store the length in bytes and total number of characters.
Diffstat (limited to 'source/blender/blenlib/intern/string_utf8.c')
-rw-r--r--source/blender/blenlib/intern/string_utf8.c48
1 files changed, 26 insertions, 22 deletions
diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c
index b8dca95ae33..ab0073a7585 100644
--- a/source/blender/blenlib/intern/string_utf8.c
+++ b/source/blender/blenlib/intern/string_utf8.c
@@ -245,24 +245,16 @@ size_t BLI_wstrlen_utf8(const wchar_t *src)
return len;
}
-/* this is very close to 'BLI_str_utf8_size' functionality, perhaps we should de-duplicate */
-/* size of UTF-8 character in bytes */
-static size_t strlen_utf8_char(const char *strc)
+size_t BLI_strlen_utf8_ex(const char *strc, int *r_len_bytes)
{
- if ((*strc & 0xe0) == 0xc0) {
- if ((strc[1] & 0x80) && (strc[1] & 0x40) == 0x00)
- return 2;
- }
- else if ((*strc & 0xf0) == 0xe0) {
- if ((strc[1] & strc[2] & 0x80) && ((strc[1] | strc[2]) & 0x40) == 0x00)
- return 3;
- }
- else if ((*strc & 0xf8) == 0xf0) {
- if ((strc[1] & strc[2] & strc[3] & 0x80) && ((strc[1] | strc[2] | strc[3]) & 0x40) == 0x00)
- return 4;
- }
+ size_t len;
+ const char *strc_orig = strc;
- return 1;
+ for (len = 0; *strc; len++)
+ strc += BLI_str_utf8_size_safe(strc);
+
+ *r_len_bytes = (strc - strc_orig);
+ return len;
}
size_t BLI_strlen_utf8(const char *strc)
@@ -270,25 +262,37 @@ size_t BLI_strlen_utf8(const char *strc)
size_t len;
for (len = 0; *strc; len++)
- strc += strlen_utf8_char(strc);
+ strc += BLI_str_utf8_size_safe(strc);
return len;
}
+size_t BLI_strnlen_utf8_ex(const char *strc, const size_t maxlen, int *r_len_bytes)
+{
+ size_t len;
+ const char *strc_orig = strc;
+ const char *strc_end = strc + maxlen;
+
+ for (len = 0; *strc && strc < strc_end; len++) {
+ strc += BLI_str_utf8_size_safe(strc);
+ }
+
+ *r_len_bytes = (strc - strc_orig);
+ return len;
+}
+
/**
* \param start the string to measure the length.
* \param maxlen the string length (in bytes)
* \return the unicode length (not in bytes!)
*/
-size_t BLI_strnlen_utf8(const char *start, const size_t maxlen)
+size_t BLI_strnlen_utf8(const char *strc, const size_t maxlen)
{
- const char *strc = start;
- const char *strc_end = start + maxlen;
-
size_t len;
+ const char *strc_end = strc + maxlen;
for (len = 0; *strc && strc < strc_end; len++) {
- strc += strlen_utf8_char(strc);
+ strc += BLI_str_utf8_size_safe(strc);
}
return len;