Get number of characters in a string with size limit. * * @param str NULL-terminated string. * @param size Maximum number of bytes to consider. * * @return Number of characters in string. * */
| 414 | * |
| 415 | */ |
| 416 | size_t wstr_nlength(const char32_t *str, size_t size) |
| 417 | { |
| 418 | size_t len = 0; |
| 419 | size_t limit = ALIGN_DOWN(size, sizeof(char32_t)); |
| 420 | size_t offset = 0; |
| 421 | |
| 422 | while ((offset < limit) && (*str++ != 0)) { |
| 423 | len++; |
| 424 | offset += sizeof(char32_t); |
| 425 | } |
| 426 | |
| 427 | return len; |
| 428 | } |
| 429 | |
| 430 | /** Check whether character is plain ASCII. |
| 431 | * |