Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/intern/string_utf8.c
| Context not available. | |||||
| * \ingroup bli | * \ingroup bli | ||||
| */ | */ | ||||
| #ifdef WITH_PYTHON | |||||
| # include <Python.h> | |||||
| #endif | |||||
| #include <string.h> | #include <string.h> | ||||
| #include <wchar.h> | #include <wchar.h> | ||||
| #include <wctype.h> | #include <wctype.h> | ||||
| Context not available. | |||||
| return len; | return len; | ||||
| } | } | ||||
| #ifdef WITH_PYTHON | |||||
| unsigned int BLI_str_utf8_lower_as_unicode_and_size(const char *__restrict p, size_t *__restrict index) | |||||
| { | |||||
| uint c_uni = BLI_str_utf8_as_unicode_and_size(p, index); | |||||
| if (LIKELY(c_uni != BLI_UTF8_ERR)) | |||||
| c_uni = Py_UNICODE_TOLOWER(c_uni); | |||||
| return c_uni; | |||||
| } | |||||
| int BLI_strncasecmp_utf8(const char *s1, const char *s2, size_t len) | |||||
| { | |||||
| register uint c1, c2; | |||||
| size_t i2, i1 = 0; | |||||
| i2 = 0; | |||||
| while ( i1 < len && i2 < len ) { | |||||
| c1 = BLI_str_utf8_lower_as_unicode_and_size(&s1[i1], &i1); | |||||
| c2 = BLI_str_utf8_lower_as_unicode_and_size(&s2[i2], &i2); | |||||
| if (c1 < c2) { | |||||
| return -1; | |||||
| } | |||||
| else if (c1 > c2) { | |||||
| return 1; | |||||
| } | |||||
| else if (c1 == 0) { | |||||
| break; | |||||
| } | |||||
| } | |||||
| return 0; | |||||
| } | |||||
| char *BLI_strcasestr_utf8(const char *s, const char *find) | |||||
| { | |||||
| register unsigned int c, sc; | |||||
| register size_t len; | |||||
| size_t off = (size_t) -1; | |||||
| c = BLI_str_utf8_lower_as_unicode_and_size(find, &off); | |||||
| if (c != 0 && c != BLI_UTF8_ERR) { | |||||
| find += off + 1; | |||||
| len = BLI_strlen_utf8(find); | |||||
| do { | |||||
| do { | |||||
| off = 0; | |||||
| sc = BLI_str_utf8_lower_as_unicode_and_size(s, &off); | |||||
| s += off; | |||||
| if (sc == 0 || sc == BLI_UTF8_ERR) | |||||
| return (NULL); | |||||
| } while (sc != c); | |||||
| } while (BLI_strncasecmp_utf8(s, find, len) != 0); | |||||
| s -= off; | |||||
| } | |||||
| return ((char*)s); | |||||
| } | |||||
| #endif | |||||
| /* end wchar_t / utf8 functions */ | /* end wchar_t / utf8 functions */ | ||||
| /* --------------------------------------------------------------------------*/ | /* --------------------------------------------------------------------------*/ | ||||
| Context not available. | |||||