determine the length of the string not in terms of the number of bytes in the string but in terms of the number of Unicode characters in the string
| 55 | // not in terms of the number of bytes in the string |
| 56 | // but in terms of the number of Unicode characters in the string |
| 57 | int str_length |
| 58 | ( |
| 59 | const char *str |
| 60 | ) { |
| 61 | // hold current Unicode character |
| 62 | utf8proc_int32_t c; |
| 63 | |
| 64 | int len = 0; |
| 65 | |
| 66 | // while we didn't get to the end of the string |
| 67 | while(str[0] != 0) { |
| 68 | // increment current position by number of bytes in Unicode character |
| 69 | str += utf8proc_iterate((const utf8proc_uint8_t *)str, -1, &c); |
| 70 | // increment length of the string in terms of Unicode characters |
| 71 | len++; |
| 72 | } |
| 73 | |
| 74 | // return the length of the string in terms of Unicode characters |
| 75 | return len; |
| 76 | } |
| 77 | |
| 78 | char *str_tolower |
| 79 | ( |