Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++11 char16_t strlen-equivalent function

I have a simple question: Is there a way to do a strlen()-like count of characters in zero-terminated char16_t array?

like image 621
NoSenseEtAl Avatar asked Apr 28 '11 12:04

NoSenseEtAl


2 Answers

use

char_traits<char16_t>::length(your_pointer)

see 21.2.3.2 struct char_traits<char16_t> and table 62 of the C++11-Std.

like image 193
towi Avatar answered Oct 24 '22 23:10

towi


Use pointers :), create a duplicate pointer to the start, then loop through it while (*endptr++);, then the length is given by endptr - startptr. You can actually template this, however, its possible the the compile won't generate the same intrinsic code it does for strlen(for different sizes ofc).

like image 27
Necrolis Avatar answered Oct 24 '22 23:10

Necrolis