29# pragma GCC diagnostic error "-Wsign-conversion"
61 if ((c & 0xe0) == 0xc0) {
64 if ((c & 0xf0) == 0xe0) {
67 if ((c & 0xf8) == 0xf0) {
70 if ((c & 0xfc) == 0xf8) {
73 if ((c & 0xfe) == 0xfc) {
85 if ((c & 0xe0) == 0xc0) {
88 if ((c & 0xf0) == 0xe0) {
91 if ((c & 0xf8) == 0xf0) {
94 if ((c & 0xfc) == 0xf8) {
97 if ((c & 0xfe) == 0xfc) {
110 if ((c & 0xe0) == 0xc0) {
114 if ((c & 0xf0) == 0xe0) {
118 if ((c & 0xf8) == 0xf0) {
122 if ((c & 0xfc) == 0xf8) {
126 if ((c & 0xfe) == 0xfc) {
141 if ((p[
count] & 0xc0) != 0x80) {
168 for (p = (
const uchar *)
str; p < pend; p++, str_len--) {
171 if (
ELEM(c, 0xfe, 0xff, 0x00)) {
178 if ((c & 0xc0) != 0xc0) {
186 if (str_len <=
size_t(ab)) {
193 if ((*p & 0xc0) != 0x80) {
201 if ((c & 0x3e) == 0) {
208 if (c == 0xe0 && (*p & 0x20) == 0) {
215 if (*p == 0xa0 && *(p + 1) == 0x80) {
218 if (*p == 0xad && *(p + 1) == 0xbf) {
221 if (*p == 0xae && *(p + 1) == 0x80) {
224 if (*p == 0xaf && *(p + 1) == 0xbf) {
227 if (*p == 0xb0 && *(p + 1) == 0x80) {
230 if (*p == 0xbe && *(p + 1) == 0x80) {
233 if (*p == 0xbf && *(p + 1) == 0xbf) {
239 if (*p == 0xbf && *(p + 1) == 0xbe) {
242 if (*p == 0xbf && *(p + 1) == 0xbf) {
250 if (c == 0xf0 && (*p & 0x30) == 0) {
257 if (c == 0xf8 && (*p & 0x38) == 0) {
264 if (c == 0xfc && (*p & 0x3c) == 0) {
274 if ((*p & 0xc0) != 0x80) {
284 return ((
const char *)perr - (
const char *)
str);
296 str_len -= size_t(bad_char + 1);
305 memmove(
str,
str + 1, str_len + 1);
321 str[bad_char] = substitute;
324 str_len -= size_t(bad_char);
332 const size_t str_len,
333 const char substitute,
335 const size_t buf_maxncpy)
339 if (
LIKELY(bad_char == -1)) {
346 if (
UNLIKELY(
size_t(bad_char) >= buf_maxncpy)) {
352 if (str_len < buf_maxncpy) {
353 memcpy(buf,
str, str_len + 1);
384 dst_maxncpy -= utf8_size;
394 case 1:
if (
UNLIKELY(!(*dst = *src++))) {
return dst; } dst++;
402char *
BLI_strncpy_utf8(
char *__restrict dst,
const char *__restrict src,
size_t dst_maxncpy)
421 return size_t(dst - r_dst);
425 const char *__restrict src,
433 return size_t(dst - r_dst);
440 const wchar_t *__restrict src,
441 const size_t dst_maxncpy)
447 while (*src &&
len < dst_maxncpy) {
472 const char *strc_orig = strc;
479 for (
int i = 1;
i <
step;
i++) {
490 *r_len_bytes = size_t(strc - strc_orig);
503 const char *strc_orig = strc;
504 const char *strc_end = strc + strc_maxlen;
508 if (strc +
step > strc_end) {
514 for (
int i = 1;
i <
step;
i++) {
524 *r_len_bytes = size_t(strc - strc_orig);
535 const char *__restrict src_c,
536 const size_t dst_w_maxncpy)
542 return wcslen(dst_w);
553 const char *__restrict
format,
563 const size_t n = size_t(vsnprintf(dst, dst_maxncpy,
format, arg));
564 if (n < dst_maxncpy) {
576 const char *__restrict
format,
585 size_t n = size_t(vsnprintf(dst, dst_maxncpy,
format, arg));
586 if (n < dst_maxncpy) {
597 const char *__restrict
format,
612 const char *__restrict
format,
628 if (ucs >= 0xf0000 || (ucs >= 0xe000 && ucs < 0xf8ff) || (ucs >= 0x1f300 && ucs < 0x1fbff)) {
631 return mk_wcwidth(ucs);
645 return mk_wcswidth(pwcs, n);
681 if ((wc <=
U'z' && wc >=
U'a') || (wc <=
U'\xF6' && wc >=
U'\xE0') ||
691 if ((wc <=
U'\x137' && wc >=
U'\x101') || (wc <=
U'\x1E95' && wc >=
U'\x1E01')) {
693 return (wc & 1) ? wc - 1 : wc;
695 if ((wc <=
U'\x586' && wc >=
U'\x561') || (wc <=
U'\x10F5' && wc >=
U'\x10D0')) {
699 if (wc <=
U'\x24E9' && wc >=
U'\x24D0') {
702 if (wc <=
U'\xFF5A' && wc >=
U'\xFF41') {
707 if (!(wc <=
U'\x0292' && wc >=
U'\x00FF') && !(wc <=
U'\x04F9' && wc >=
U'\x03AC') &&
708 !(wc <=
U'\x1FE1' && wc >=
U'\x1E01'))
713 static const char32_t from[] =
714 U"\x00FF\x013A\x013C\x013E\x0140\x0142\x0144\x0146\x0148\x014B\x014D\x014F\x0151\x0153\x0155"
715 U"\x0157\x0159\x015B\x015D\x015F\x0161\x0163\x0165\x0167\x0169\x016B\x016D\x016F\x0171\x0173"
716 U"\x0175\x0177\x017A\x017C\x017E\x0183\x0185\x0188\x018C\x0192\x0199\x01A1\x01A3\x01A5\x01A8"
717 U"\x01AD\x01B0\x01B4\x01B6\x01B9\x01BD\x01C6\x01C9\x01CC\x01CE\x01D0\x01D2\x01D4\x01D6\x01D8"
718 U"\x01DA\x01DC\x01DF\x01E1\x01E3\x01E5\x01E7\x01E9\x01EB\x01ED\x01EF\x01F3\x01F5\x01FB\x01FD"
719 U"\x01FF\x0201\x0203\x0205\x0207\x0209\x020B\x020D\x020F\x0211\x0213\x0215\x0217\x0253\x0254"
720 U"\x0257\x0258\x0259\x025B\x0260\x0263\x0268\x0269\x026F\x0272\x0275\x0283\x0288\x028A\x028B"
721 U"\x0292\x03AC\x03AD\x03AE\x03AF\x03B1\x03B2\x03B3\x03B4\x03B5\x03B6\x03B7\x03B8\x03B9\x03BA"
722 U"\x03BB\x03BC\x03BD\x03BE\x03BF\x03C0\x03C1\x03C3\x03C4\x03C5\x03C6\x03C7\x03C8\x03C9\x03CA"
723 U"\x03CB\x03CC\x03CD\x03CE\x03E3\x03E5\x03E7\x03E9\x03EB\x03ED\x03EF\x0430\x0431\x0432\x0433"
724 U"\x0434\x0435\x0436\x0437\x0438\x0439\x043A\x043B\x043C\x043D\x043E\x043F\x0440\x0441\x0442"
725 U"\x0443\x0444\x0445\x0446\x0447\x0448\x0449\x044A\x044B\x044C\x044D\x044E\x044F\x0451\x0452"
726 U"\x0453\x0454\x0455\x0456\x0457\x0458\x0459\x045A\x045B\x045C\x045E\x045F\x0461\x0463\x0465"
727 U"\x0467\x0469\x046B\x046D\x046F\x0471\x0473\x0475\x0477\x0479\x047B\x047D\x047F\x0481\x0491"
728 U"\x0493\x0495\x0497\x0499\x049B\x049D\x049F\x04A1\x04A3\x04A5\x04A7\x04A9\x04AB\x04AD\x04AF"
729 U"\x04B1\x04B3\x04B5\x04B7\x04B9\x04BB\x04BD\x04BF\x04C2\x04C4\x04C8\x04CC\x04D1\x04D3\x04D5"
730 U"\x04D7\x04D9\x04DB\x04DD\x04DF\x04E1\x04E3\x04E5\x04E7\x04E9\x04EB\x04EF\x04F1\x04F3\x04F5"
731 U"\x04F9\x1EA1\x1EA3\x1EA5\x1EA7\x1EA9\x1EAB\x1EAD\x1EAF\x1EB1\x1EB3\x1EB5\x1EB7\x1EB9\x1EBB"
732 U"\x1EBD\x1EBF\x1EC1\x1EC3\x1EC5\x1EC7\x1EC9\x1ECB\x1ECD\x1ECF\x1ED1\x1ED3\x1ED5\x1ED7\x1ED9"
733 U"\x1EDB\x1EDD\x1EDF\x1EE1\x1EE3\x1EE5\x1EE7\x1EE9\x1EEB\x1EED\x1EEF\x1EF1\x1EF3\x1EF5\x1EF7"
734 U"\x1EF9\x1F00\x1F01\x1F02\x1F03\x1F04\x1F05\x1F06\x1F07\x1F10\x1F11\x1F12\x1F13\x1F14\x1F15"
735 U"\x1F20\x1F21\x1F22\x1F23\x1F24\x1F25\x1F26\x1F27\x1F30\x1F31\x1F32\x1F33\x1F34\x1F35\x1F36"
736 U"\x1F37\x1F40\x1F41\x1F42\x1F43\x1F44\x1F45\x1F51\x1F53\x1F55\x1F57\x1F60\x1F61\x1F62\x1F63"
737 U"\x1F64\x1F65\x1F66\x1F67\x1F80\x1F81\x1F82\x1F83\x1F84\x1F85\x1F86\x1F87\x1F90\x1F91\x1F92"
738 U"\x1F93\x1F94\x1F95\x1F96\x1F97\x1FA0\x1FA1\x1FA2\x1FA3\x1FA4\x1FA5\x1FA6\x1FA7\x1FB0\x1FB1"
739 U"\x1FD0\x1FD1\x1FE0\x1FE1";
740 static const char32_t to[] =
741 U"\x0178\x0139\x013B\x013D\x013F\x0141\x0143\x0145\x0147\x014A\x014C\x014E\x0150\x0152\x0154"
742 U"\x0156\x0158\x015A\x015C\x015E\x0160\x0162\x0164\x0166\x0168\x016A\x016C\x016E\x0170\x0172"
743 U"\x0174\x0176\x0179\x017B\x017D\x0182\x0184\x0187\x018B\x0191\x0198\x01A0\x01A2\x01A4\x01A7"
744 U"\x01AC\x01AF\x01B3\x01B5\x01B8\x01BC\x01C4\x01C7\x01CA\x01CD\x01CF\x01D1\x01D3\x01D5\x01D7"
745 U"\x01D9\x01DB\x01DE\x01E0\x01E2\x01E4\x01E6\x01E8\x01EA\x01EC\x01EE\x01F1\x01F4\x01FA\x01FC"
746 U"\x01FE\x0200\x0202\x0204\x0206\x0208\x020A\x020C\x020E\x0210\x0212\x0214\x0216\x0181\x0186"
747 U"\x018A\x018E\x018F\x0190\x0193\x0194\x0197\x0196\x019C\x019D\x019F\x01A9\x01AE\x01B1\x01B2"
748 U"\x01B7\x0386\x0388\x0389\x038A\x0391\x0392\x0393\x0394\x0395\x0396\x0397\x0398\x0399\x039A"
749 U"\x039B\x039C\x039D\x039E\x039F\x03A0\x03A1\x03A3\x03A4\x03A5\x03A6\x03A7\x03A8\x03A9\x03AA"
750 U"\x03AB\x038C\x038E\x038F\x03E2\x03E4\x03E6\x03E8\x03EA\x03EC\x03EE\x0410\x0411\x0412\x0413"
751 U"\x0414\x0415\x0416\x0417\x0418\x0419\x041A\x041B\x041C\x041D\x041E\x041F\x0420\x0421\x0422"
752 U"\x0423\x0424\x0425\x0426\x0427\x0428\x0429\x042A\x042B\x042C\x042D\x042E\x042F\x0401\x0402"
753 U"\x0403\x0404\x0405\x0406\x0407\x0408\x0409\x040A\x040B\x040C\x040E\x040F\x0460\x0462\x0464"
754 U"\x0466\x0468\x046A\x046C\x046E\x0470\x0472\x0474\x0476\x0478\x047A\x047C\x047E\x0480\x0490"
755 U"\x0492\x0494\x0496\x0498\x049A\x049C\x049E\x04A0\x04A2\x04A4\x04A6\x04A8\x04AA\x04AC\x04AE"
756 U"\x04B0\x04B2\x04B4\x04B6\x04B8\x04BA\x04BC\x04BE\x04C1\x04C3\x04C7\x04CB\x04D0\x04D2\x04D4"
757 U"\x04D6\x04D8\x04DA\x04DC\x04DE\x04E0\x04E2\x04E4\x04E6\x04E8\x04EA\x04EE\x04F0\x04F2\x04F4"
758 U"\x04F8\x1EA0\x1EA2\x1EA4\x1EA6\x1EA8\x1EAA\x1EAC\x1EAE\x1EB0\x1EB2\x1EB4\x1EB6\x1EB8\x1EBA"
759 U"\x1EBC\x1EBE\x1EC0\x1EC2\x1EC4\x1EC6\x1EC8\x1ECA\x1ECC\x1ECE\x1ED0\x1ED2\x1ED4\x1ED6\x1ED8"
760 U"\x1EDA\x1EDC\x1EDE\x1EE0\x1EE2\x1EE4\x1EE6\x1EE8\x1EEA\x1EEC\x1EEE\x1EF0\x1EF2\x1EF4\x1EF6"
761 U"\x1EF8\x1F08\x1F09\x1F0A\x1F0B\x1F0C\x1F0D\x1F0E\x1F0F\x1F18\x1F19\x1F1A\x1F1B\x1F1C\x1F1D"
762 U"\x1F28\x1F29\x1F2A\x1F2B\x1F2C\x1F2D\x1F2E\x1F2F\x1F38\x1F39\x1F3A\x1F3B\x1F3C\x1F3D\x1F3E"
763 U"\x1F3F\x1F48\x1F49\x1F4A\x1F4B\x1F4C\x1F4D\x1F59\x1F5B\x1F5D\x1F5F\x1F68\x1F69\x1F6A\x1F6B"
764 U"\x1F6C\x1F6D\x1F6E\x1F6F\x1F88\x1F89\x1F8A\x1F8B\x1F8C\x1F8D\x1F8E\x1F8F\x1F98\x1F99\x1F9A"
765 U"\x1F9B\x1F9C\x1F9D\x1F9E\x1F9F\x1FA8\x1FA9\x1FAA\x1FAB\x1FAC\x1FAD\x1FAE\x1FAF\x1FB8\x1FB9"
766 U"\x1FD8\x1FD9\x1FE8\x1FE9";
768 if (wc >= from[0] && wc <= from[
ARRAY_SIZE(from) - 2]) {
773 const size_t mid = (
min +
max) / 2;
774 if (wc > from[mid]) {
777 else if (wc < from[mid]) {
792 if ((wc <=
U'Z' && wc >=
U'A') || (wc <=
U'\xD6' && wc >=
U'\xC0')) {
797 if ((wc <=
U'\x136' && wc >=
U'\x100') || (wc <=
U'\x1E94' && wc >=
U'\x1E00')) {
799 return (wc % 2 == 0) ? wc + 1 : wc;
801 if ((wc <=
U'\x556' && wc >=
U'\x531') || (wc <=
U'\x10C5' && wc >=
U'\x10A0')) {
805 if (wc <=
U'\x24CF' && wc >=
U'\x24B6') {
808 if (wc <=
U'\xFF3A' && wc >=
U'\xFF21') {
813 if (!(wc <=
U'\x0216' && wc >=
U'\x00D8') && !(wc <=
U'\x04F8' && wc >=
U'\x0386') &&
814 !(wc <=
U'\x1FE9' && wc >=
U'\x1E00'))
819 static const char32_t from[] =
820 U"\x00D8\x00D9\x00DA\x00DB\x00DC\x00DD\x00DE\x0139\x013B\x013D\x013F\x0141\x0143\x0145\x0147"
821 U"\x014A\x014C\x014E\x0150\x0152\x0154\x0156\x0158\x015A\x015C\x015E\x0160\x0162\x0164\x0166"
822 U"\x0168\x016A\x016C\x016E\x0170\x0172\x0174\x0176\x0178\x0179\x017B\x017D\x0181\x0182\x0184"
823 U"\x0186\x0187\x018A\x018B\x018E\x018F\x0190\x0191\x0193\x0194\x0196\x0197\x0198\x019C\x019D"
824 U"\x019F\x01A0\x01A2\x01A4\x01A7\x01A9\x01AC\x01AE\x01AF\x01B1\x01B2\x01B3\x01B5\x01B7\x01B8"
825 U"\x01BC\x01C4\x01C5\x01C7\x01C8\x01CA\x01CB\x01CD\x01CF\x01D1\x01D3\x01D5\x01D7\x01D9\x01DB"
826 U"\x01DE\x01E0\x01E2\x01E4\x01E6\x01E8\x01EA\x01EC\x01EE\x01F1\x01F4\x01FA\x01FC\x01FE\x0200"
827 U"\x0202\x0204\x0206\x0208\x020A\x020C\x020E\x0210\x0212\x0214\x0216\x0386\x0388\x0389\x038A"
828 U"\x038C\x038E\x038F\x0391\x0392\x0393\x0394\x0395\x0396\x0397\x0398\x0399\x039A\x039B\x039C"
829 U"\x039D\x039E\x039F\x03A0\x03A1\x03A3\x03A4\x03A5\x03A6\x03A7\x03A8\x03A9\x03AA\x03AB\x03E2"
830 U"\x03E4\x03E6\x03E8\x03EA\x03EC\x03EE\x0401\x0402\x0403\x0404\x0405\x0406\x0407\x0408\x0409"
831 U"\x040A\x040B\x040C\x040E\x040F\x0410\x0411\x0412\x0413\x0414\x0415\x0416\x0417\x0418\x0419"
832 U"\x041A\x041B\x041C\x041D\x041E\x041F\x0420\x0421\x0422\x0423\x0424\x0425\x0426\x0427\x0428"
833 U"\x0429\x042A\x042B\x042C\x042D\x042E\x042F\x0460\x0462\x0464\x0466\x0468\x046A\x046C\x046E"
834 U"\x0470\x0472\x0474\x0476\x0478\x047A\x047C\x047E\x0480\x0490\x0492\x0494\x0496\x0498\x049A"
835 U"\x049C\x049E\x04A0\x04A2\x04A4\x04A6\x04A8\x04AA\x04AC\x04AE\x04B0\x04B2\x04B4\x04B6\x04B8"
836 U"\x04BA\x04BC\x04BE\x04C1\x04C3\x04C7\x04CB\x04D0\x04D2\x04D4\x04D6\x04D8\x04DA\x04DC\x04DE"
837 U"\x04E0\x04E2\x04E4\x04E6\x04E8\x04EA\x04EE\x04F0\x04F2\x04F4\x04F8\x1EA0\x1EA2\x1EA4\x1EA6"
838 U"\x1EA8\x1EAA\x1EAC\x1EAE\x1EB0\x1EB2\x1EB4\x1EB6\x1EB8\x1EBA\x1EBC\x1EBE\x1EC0\x1EC2\x1EC4"
839 U"\x1EC6\x1EC8\x1ECA\x1ECC\x1ECE\x1ED0\x1ED2\x1ED4\x1ED6\x1ED8\x1EDA\x1EDC\x1EDE\x1EE0\x1EE2"
840 U"\x1EE4\x1EE6\x1EE8\x1EEA\x1EEC\x1EEE\x1EF0\x1EF2\x1EF4\x1EF6\x1EF8\x1F08\x1F09\x1F0A\x1F0B"
841 U"\x1F0C\x1F0D\x1F0E\x1F0F\x1F18\x1F19\x1F1A\x1F1B\x1F1C\x1F1D\x1F28\x1F29\x1F2A\x1F2B\x1F2C"
842 U"\x1F2D\x1F2E\x1F2F\x1F38\x1F39\x1F3A\x1F3B\x1F3C\x1F3D\x1F3E\x1F3F\x1F48\x1F49\x1F4A\x1F4B"
843 U"\x1F4C\x1F4D\x1F59\x1F5B\x1F5D\x1F5F\x1F68\x1F69\x1F6A\x1F6B\x1F6C\x1F6D\x1F6E\x1F6F\x1F88"
844 U"\x1F89\x1F8A\x1F8B\x1F8C\x1F8D\x1F8E\x1F8F\x1F98\x1F99\x1F9A\x1F9B\x1F9C\x1F9D\x1F9E\x1F9F"
845 U"\x1FA8\x1FA9\x1FAA\x1FAB\x1FAC\x1FAD\x1FAE\x1FAF\x1FB8\x1FB9\x1FD8\x1FD9\x1FE8\x1FE9";
846 static const char32_t to[] =
847 U"\x00F8\x00F9\x00FA\x00FB\x00FC\x00FD\x00FE\x013A\x013C\x013E\x0140\x0142\x0144\x0146\x0148"
848 U"\x014B\x014D\x014F\x0151\x0153\x0155\x0157\x0159\x015B\x015D\x015F\x0161\x0163\x0165\x0167"
849 U"\x0169\x016B\x016D\x016F\x0171\x0173\x0175\x0177\x00FF\x017A\x017C\x017E\x0253\x0183\x0185"
850 U"\x0254\x0188\x0257\x018C\x0258\x0259\x025B\x0192\x0260\x0263\x0269\x0268\x0199\x026f\x0272"
851 U"\x0275\x01A1\x01A3\x01A5\x01A8\x0283\x01AD\x0288\x01B0\x028A\x028B\x01B4\x01B6\x0292\x01B9"
852 U"\x01BD\x01C6\x01C6\x01C9\x01C9\x01CC\x01CC\x01CE\x01D0\x01D2\x01D4\x01D6\x01D8\x01DA\x01DC"
853 U"\x01DF\x01E1\x01E3\x01E5\x01E7\x01E9\x01EB\x01ED\x01EF\x01F3\x01F5\x01FB\x01FD\x01FF\x0201"
854 U"\x0203\x0205\x0207\x0209\x020B\x020D\x020F\x0211\x0213\x0215\x0217\x03AC\x03AD\x03AE\x03AF"
855 U"\x03CC\x03CD\x03CE\x03B1\x03B2\x03B3\x03B4\x03B5\x03B6\x03B7\x03B8\x03B9\x03BA\x03BB\x03BC"
856 U"\x03BD\x03BE\x03BF\x03C0\x03C1\x03C3\x03C4\x03C5\x03C6\x03C7\x03C8\x03C9\x03CA\x03CB\x03E3"
857 U"\x03E5\x03E7\x03E9\x03EB\x03ED\x03EF\x0451\x0452\x0453\x0454\x0455\x0456\x0457\x0458\x0459"
858 U"\x045A\x045B\x045C\x045E\x045F\x0430\x0431\x0432\x0433\x0434\x0435\x0436\x0437\x0438\x0439"
859 U"\x043A\x043B\x043C\x043D\x043E\x043F\x0440\x0441\x0442\x0443\x0444\x0445\x0446\x0447\x0448"
860 U"\x0449\x044A\x044B\x044C\x044D\x044E\x044F\x0461\x0463\x0465\x0467\x0469\x046B\x046D\x046F"
861 U"\x0471\x0473\x0475\x0477\x0479\x047B\x047D\x047F\x0481\x0491\x0493\x0495\x0497\x0499\x049B"
862 U"\x049D\x049F\x04A1\x04A3\x04A5\x04A7\x04A9\x04AB\x04AD\x04AF\x04B1\x04B3\x04B5\x04B7\x04B9"
863 U"\x04BB\x04BD\x04BF\x04C2\x04C4\x04C8\x04CC\x04D1\x04D3\x04D5\x04D7\x04D9\x04DB\x04DD\x04DF"
864 U"\x04E1\x04E3\x04E5\x04E7\x04E9\x04EB\x04EF\x04F1\x04F3\x04F5\x04F9\x1EA1\x1EA3\x1EA5\x1EA7"
865 U"\x1EA9\x1EAB\x1EAD\x1EAF\x1EB1\x1EB3\x1EB5\x1EB7\x1EB9\x1EBB\x1EBD\x1EBF\x1EC1\x1EC3\x1EC5"
866 U"\x1EC7\x1EC9\x1ECB\x1ECD\x1ECF\x1ED1\x1ED3\x1ED5\x1ED7\x1ED9\x1EDB\x1EDD\x1EDF\x1EE1\x1EE3"
867 U"\x1EE5\x1EE7\x1EE9\x1EEB\x1EED\x1EEF\x1EF1\x1EF3\x1EF5\x1EF7\x1EF9\x1F00\x1F01\x1F02\x1F03"
868 U"\x1F04\x1F05\x1F06\x1F07\x1F10\x1F11\x1F12\x1F13\x1F14\x1F15\x1F20\x1F21\x1F22\x1F23\x1F24"
869 U"\x1F25\x1F26\x1F27\x1F30\x1F31\x1F32\x1F33\x1F34\x1F35\x1F36\x1F37\x1F40\x1F41\x1F42\x1F43"
870 U"\x1F44\x1F45\x1F51\x1F53\x1F55\x1F57\x1F60\x1F61\x1F62\x1F63\x1F64\x1F65\x1F66\x1F67\x1F80"
871 U"\x1F81\x1F82\x1F83\x1F84\x1F85\x1F86\x1F87\x1F90\x1F91\x1F92\x1F93\x1F94\x1F95\x1F96\x1F97"
872 U"\x1FA0\x1FA1\x1FA2\x1FA3\x1FA4\x1FA5\x1FA6\x1FA7\x1FB0\x1FB1\x1FD0\x1FD1\x1FE0\x1FE1";
874 if (wc >= from[0] && wc <= from[
ARRAY_SIZE(from) - 2]) {
879 const size_t mid = (
min +
max) / 2;
880 if (wc > from[mid]) {
883 else if (wc < from[mid]) {
907 return ELEM(codepoint,
931 if (
ELEM(codepoint,
'\\',
'_')) {
936 if (codepoint ==
'/' && !(codepoint_prev >=
'0' && codepoint_prev <=
'9')) {
941 if (
ELEM(codepoint,
'-', 0x2010, 0x2014) &&
947 if ((codepoint >= 0x2E80 && codepoint <= 0x2FFF) ||
948 (codepoint >= 0x3040 && codepoint <= 0x309F) ||
949 (codepoint >= 0x30A2 && codepoint <= 0x30FA) ||
950 (codepoint >= 0x3400 && codepoint <= 0x4DBF) ||
951 (codepoint >= 0x4E00 && codepoint <= 0x9FFF) ||
952 (codepoint >= 0x3040 && codepoint <= 0x309F) ||
953 (codepoint >= 0x3130 && codepoint <= 0x318F))
958 if (
ELEM(codepoint, 0x0F0D, 0x0F0B)) {
973 if (
ELEM(codepoint_prev,
983 && !(codepoint >=
'0' && codepoint <=
'9'))
989 if (codepoint_prev ==
'.' && codepoint !=
'.' && !(codepoint >=
'0' && codepoint <=
'9')) {
994 if (
ELEM(codepoint_prev,
1011 if (
ELEM(codepoint_prev,
1067 size_t *__restrict index)
1084 *index += size_t(
len);
1091 size_t *__restrict index)
1104#define UTF8_VARS_FROM_CHAR32(Char, First, Len) \
1105 if (Char < 0x80) { \
1109 else if (Char < 0x800) { \
1113 else if (Char < 0x10000) { \
1117 else if (Char < 0x200000) { \
1121 else if (Char < 0x4000000) { \
1156 memset(dst, 0x0, dst_maxncpy);
1161 dst[
i] = char((c & 0x3f) | 0x80);
1164 dst[0] = char(c | first);
1170 const char *__restrict src_c,
1171 const size_t dst_w_maxncpy)
1176 const size_t maxlen = dst_w_maxncpy - 1;
1179 const size_t src_c_len = strlen(src_c);
1180 const char *src_c_end = src_c + src_c_len;
1182 while ((index < src_c_len) && (
len != maxlen)) {
1190 index = size_t(src_c_next - src_c);
1202 const char32_t *__restrict src,
1203 const size_t dst_maxncpy)
1209 while (*src &&
len < dst_maxncpy) {
1223 const char32_t *src_end = src + src_maxlen;
1225 while ((src < src_end) && *src) {
1248 if (str_start < p) {
1249 for (--p; p >= str_start; p--) {
1250 if ((*p & 0xc0) != 0x80) {
1263 if ((p < str_end) && (*p !=
'\0')) {
1264 for (++p; p < str_end && (*p & 0xc0) == 0x80; p++) {
1292 const bool from_right)
1294 const size_t str_len = end ? size_t(end -
str) : strlen(
str);
1295 if (end ==
nullptr) {
1296 end =
str + str_len;
1302 char *suf = (
char *)(
str + str_len);
1305 from_right ? (sep >
str) : ((sep < end) && (*sep !=
'\0'));
1309 size_t index_ofs = 0;
1316 for (
const uint *d = delim; *d !=
'\0'; d++) {
1320 *r_suf = from_right ? suf : (
char *)(
str + index);
1321 return size_t(sep -
str);
1328 *r_suf = *r_sep =
nullptr;
1339 size_t str_len_trim;
1341 str[str_len_trim] =
'\0';
1342 return str_len_trim;
1348 if (std::memchr(
str,
'\0', str_size)) {
1369 const size_t offset_target_as_size = size_t(offset_target);
1373 while ((offset < str_len) && (offset < offset_target_as_size)) {
1388 while ((offset < str_len) && (index < index_target)) {
1400 const size_t offset_target_clamp = std::min(
size_t(offset_target), str_len);
1403 while (offset < offset_target_clamp) {
1413 size_t offset = 0, offset_next = 0;
1415 while ((offset < str_len) && (column < column_target)) {
1418 if (column > column_target) {
1421 offset = offset_next;
1427 const size_t str_len,
1428 const int offset_target,
1429 const int tab_width)
1432 const size_t offset_target_clamp = std::min(
size_t(offset_target), str_len);
1435 while (offset < offset_target_clamp) {
1438 column += (code ==
'\t') ? (tab_width - (column % tab_width)) :
BLI_wcwidth_safe(code);
1445 const size_t str_len,
1446 const int column_target,
1447 const int tab_width)
1449 size_t offset = 0, offset_next = 0;
1451 while ((offset < str_len) && (column < column_target)) {
1454 column += (code ==
'\t') ? (tab_width - (column % tab_width)) :
BLI_wcwidth_safe(code);
1455 if (column > column_target) {
1458 offset = offset_next;
#define BLI_string_debug_size(str, str_maxncpy)
char char size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
BLI_INLINE int utf8_char_compute_skip_or_error(const char c)
bool BLI_str_utf32_char_is_breaking_space(char32_t codepoint)
uint BLI_str_utf8_as_unicode_or_error(const char *p)
bool BLI_str_utf8_truncate_at_size(char *str, const size_t str_size)
int BLI_wcswidth_or_error(const char32_t *pwcs, size_t n)
int BLI_str_utf8_offset_from_column(const char *str, const size_t str_len, const int column_target)
int BLI_str_utf8_char_width_or_error(const char *p)
BLI_INLINE int utf8_char_compute_skip_or_error_with_mask(const char c, char *r_mask)
size_t BLI_str_utf8_from_unicode_len(const uint c)
BLI_INLINE int utf8_char_compute_skip(const char c)
size_t BLI_str_partition_ex_utf8(const char *str, const char *end, const uint delim[], const char **r_sep, const char **r_suf, const bool from_right)
size_t BLI_strlen_utf8_ex(const char *strc, size_t *r_len_bytes)
bool BLI_str_utf32_char_is_optional_break_before(char32_t codepoint, char32_t codepoint_prev)
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy)
size_t BLI_strncpy_utf8_rlen_unterminated(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy)
size_t BLI_strlen_utf8(const char *strc)
int BLI_str_utf8_invalid_strip(char *str, size_t str_len)
char32_t BLI_str_utf32_char_to_lower(const char32_t wc)
#define UTF8_VARS_FROM_CHAR32(Char, First, Len)
size_t BLI_strnlen_utf8(const char *strc, const size_t strc_maxlen)
size_t BLI_str_utf32_as_utf8_len(const char32_t *src)
char32_t BLI_str_utf32_char_to_upper(const char32_t wc)
ptrdiff_t BLI_str_utf8_invalid_byte(const char *str, size_t str_len)
uint BLI_str_utf8_as_unicode_safe(const char *p)
BLI_INLINE uint utf8_char_decode(const char *p, const char mask, const int len, const uint err)
static size_t str_utf8_truncate_at_size_unchecked(char *str, const size_t str_size)
size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict src, const size_t dst_maxncpy)
size_t BLI_strncpy_wchar_from_utf8(wchar_t *__restrict dst_w, const char *__restrict src_c, const size_t dst_w_maxncpy)
size_t BLI_snprintf_utf8(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...)
const char * BLI_str_find_next_char_utf8(const char *p, const char *str_end)
size_t BLI_str_utf32_as_utf8_len_ex(const char32_t *src, const size_t src_maxlen)
size_t BLI_vsnprintf_utf8_rlen(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format, va_list arg)
const char * BLI_str_find_prev_char_utf8(const char *p, const char *str_start)
size_t BLI_wstrlen_utf8(const wchar_t *src)
int BLI_wcwidth_safe(char32_t ucs)
int BLI_str_utf8_offset_to_index(const char *str, const size_t str_len, const int offset_target)
int BLI_str_utf8_offset_to_column_with_tabs(const char *str, const size_t str_len, const int offset_target, const int tab_width)
size_t BLI_str_utf32_as_utf8(char *__restrict dst, const char32_t *__restrict src, const size_t dst_maxncpy)
int BLI_str_utf8_offset_to_column(const char *str, const size_t str_len, const int offset_target)
size_t BLI_vsnprintf_utf8(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format, va_list arg)
BLI_INLINE char * str_utf8_copy_max_bytes_impl(char *dst, const char *src, size_t dst_maxncpy)
uint BLI_str_utf8_as_unicode_step_safe(const char *__restrict p, const size_t p_len, size_t *__restrict index)
bool BLI_str_utf32_char_is_optional_break_after(char32_t codepoint, char32_t codepoint_prev)
size_t BLI_str_utf8_as_utf32(char32_t *__restrict dst_w, const char *__restrict src_c, const size_t dst_w_maxncpy)
size_t BLI_str_utf8_from_unicode(uint c, char *dst, const size_t dst_maxncpy)
const char * BLI_str_utf8_invalid_substitute_if_needed(const char *str, const size_t str_len, const char substitute, char *buf, const size_t buf_maxncpy)
int BLI_str_utf8_size_safe(const char *p)
int BLI_str_utf8_column_count(const char *str, size_t str_len)
size_t BLI_str_rpartition_utf8(const char *str, const uint delim[], const char **r_sep, const char **r_suf)
int BLI_wcwidth_or_error(char32_t ucs)
uint BLI_str_utf8_as_unicode_step_or_error(const char *__restrict p, const size_t p_len, size_t *__restrict index)
size_t BLI_strncpy_utf8_rlen(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy)
size_t BLI_str_partition_utf8(const char *str, const uint delim[], const char **r_sep, const char **r_suf)
int BLI_str_utf8_offset_from_index(const char *str, const size_t str_len, const int index_target)
int BLI_str_utf8_char_width_safe(const char *p)
size_t BLI_snprintf_utf8_rlen(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...)
int BLI_str_utf8_size_or_error(const char *p)
int BLI_str_utf8_offset_from_column_with_tabs(const char *str, const size_t str_len, const int column_target, const int tab_width)
size_t BLI_strnlen_utf8_ex(const char *strc, const size_t strc_maxlen, size_t *r_len_bytes)
int BLI_str_utf8_invalid_substitute(char *str, size_t str_len, const char substitute)
int conv_utf_8_to_16(const char *in8, wchar_t *out16, size_t size16)