change utf8_len function
This commit is contained in:
parent
05e856f42d
commit
526530caf5
@ -6,8 +6,18 @@
|
||||
namespace hack::string
|
||||
{
|
||||
// подсчет кол-ва символов
|
||||
inline std::size_t utf8_len(const std::string& utf8)
|
||||
inline std::size_t utf8_len(const std::string& s)
|
||||
{
|
||||
return std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t>{}.from_bytes(utf8).size();
|
||||
std::size_t length = 0;
|
||||
std::size_t i = 0;
|
||||
|
||||
while (i < s.size())
|
||||
{
|
||||
auto c = s[i];
|
||||
if ((c & 0xC0) != 0x80)
|
||||
++length;
|
||||
++i;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user