LEFT | RIGHT |
(no file at all) | |
1 /* | 1 /* |
2 * ***** BEGIN GPL LICENSE BLOCK ***** | 2 * ***** BEGIN GPL LICENSE BLOCK ***** |
3 * | 3 * |
4 * This program is free software; you can redistribute it and/or | 4 * This program is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU General Public License | 5 * modify it under the terms of the GNU General Public License |
6 * as published by the Free Software Foundation; either version 2 | 6 * as published by the Free Software Foundation; either version 2 |
7 * of the License, or (at your option) any later version. | 7 * of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 { | 224 { |
225 size_t len = 0; | 225 size_t len = 0; |
226 | 226 |
227 while (*src) { | 227 while (*src) { |
228 len += BLI_str_utf8_from_unicode(*src++, NULL); | 228 len += BLI_str_utf8_from_unicode(*src++, NULL); |
229 } | 229 } |
230 | 230 |
231 return len; | 231 return len; |
232 } | 232 } |
233 | 233 |
234 // utf8slen | 234 /* size of UTF-8 character in bytes */ |
| 235 size_t BLI_strlen_utf8_char(const char *strc) |
| 236 { |
| 237 » if ((*strc & 0xe0) == 0xc0) { |
| 238 » » if ((strc[1] & 0x80) && (strc[1] & 0x40) == 0x00) |
| 239 » » » return 2; |
| 240 » } |
| 241 » else if ((*strc & 0xf0) == 0xe0) { |
| 242 » » if ((strc[1] & strc[2] & 0x80) && ((strc[1] | strc[2]) & 0x40) =
= 0x00) |
| 243 » » » return 3; |
| 244 » } |
| 245 » else if ((*strc & 0xf8) == 0xf0) { |
| 246 » » if ((strc[1] & strc[2] & strc[3] & 0x80) && ((strc[1] | strc[2]
| strc[3]) & 0x40) == 0x00) |
| 247 » » » return 4; |
| 248 » } |
| 249 |
| 250 » return 1; |
| 251 } |
| 252 |
235 size_t BLI_strlen_utf8(const char *strc) | 253 size_t BLI_strlen_utf8(const char *strc) |
236 { | 254 { |
237 » int len = 0; | 255 » int len; |
238 | 256 |
239 » while (*strc) { | 257 » for (len = 0; *strc; len++) |
240 » » if ((*strc & 0xe0) == 0xc0) { | 258 » » strc += BLI_strlen_utf8_char(strc); |
241 » » » if ((strc[1] & 0x80) && (strc[1] & 0x40) == 0x00) | 259 |
242 » » » » strc++; | 260 » return len; |
243 » » } | 261 } |
244 » » else if ((*strc & 0xf0) == 0xe0) { | 262 |
245 » » » if ((strc[1] & strc[2] & 0x80) && ((strc[1] | strc[2]) &
0x40) == 0x00) | 263 size_t BLI_strlen_range_utf8(const char *start, const char *end) |
246 » » » » strc += 2; | 264 { |
247 » » } | 265 » const char *strc = start; |
248 » » else if ((*strc & 0xf8) == 0xf0) { | 266 » int len; |
249 » » » if ((strc[1] & strc[2] & strc[3] & 0x80) && ((strc[1] |
strc[2] | strc[3]) & 0x40) == 0x00) | 267 |
250 » » » » strc += 3; | 268 » for (len = 0; strc < end; len++) |
251 » » } | 269 » » strc += BLI_strlen_utf8_char(strc); |
252 | |
253 » » strc++; | |
254 » » len++; | |
255 » } | |
256 | 270 |
257 return len; | 271 return len; |
258 } | 272 } |
259 | 273 |
260 size_t BLI_strncpy_wchar_from_utf8(wchar_t *dst_w, const char *src_c, const size
_t maxcpy) | 274 size_t BLI_strncpy_wchar_from_utf8(wchar_t *dst_w, const char *src_c, const size
_t maxcpy) |
261 { | 275 { |
262 int len = 0; | 276 int len = 0; |
263 | 277 |
264 if (dst_w == NULL || src_c == NULL) { | 278 if (dst_w == NULL || src_c == NULL) { |
265 return 0; | 279 return 0; |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 char *BLI_str_prev_char_utf8(const char *p) | 577 char *BLI_str_prev_char_utf8(const char *p) |
564 { | 578 { |
565 while (1) { | 579 while (1) { |
566 p--; | 580 p--; |
567 if ((*p & 0xc0) != 0x80) { | 581 if ((*p & 0xc0) != 0x80) { |
568 return (char *)p; | 582 return (char *)p; |
569 } | 583 } |
570 } | 584 } |
571 } | 585 } |
572 /* end glib copy */ | 586 /* end glib copy */ |
LEFT | RIGHT |