return true if utf8 string is valid
| 31 | |
| 32 | // return true if utf8 string is valid |
| 33 | bool str_utf8_validate |
| 34 | ( |
| 35 | const char *str |
| 36 | ) { |
| 37 | // hold current Unicode character |
| 38 | utf8proc_int32_t c; |
| 39 | |
| 40 | // while we didn't get to the end of the string |
| 41 | while(str[0] != 0) { |
| 42 | // increment current position by number of bytes in Unicode character |
| 43 | str += utf8proc_iterate((const utf8proc_uint8_t *)str, -1, &c); |
| 44 | if(c == -1) { |
| 45 | // string is not valid |
| 46 | return false; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | // string is valid |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | // determine the length of the string |
| 55 | // not in terms of the number of bytes in the string |