如何在 C++11 中使用 tinyutf8 在另一个utf8_string中找到utf8_string?

How to find utf8_string in another utf8_string using tinyutf8 in C++11?

本文关键字:utf8 string tinyutf8 C++11 另一个      更新时间:2023-10-16

我正在使用tinyutf8 C++UTF-8字符串库 https://github.com/DuffsDevice/tinyutf8

我正在尝试调用utf8_string::find_first_of传递utf8_string作为第一个参数。

这将生成以下错误:

error: no matching function for call to ‘utf8_string::find_first_of(utf8_string&, int&)’
int found_pos = haystack.find_first_of(needle, at_pos);
^
In file included from Phonemizer.cpp:8:0:
tinyutf8.h:1728:12: note: candidate: utf8_string::size_type utf8_string::find_first_of(const value_type*, utf8_string::size_type) const
size_type find_first_of( const value_type* str , size_type start_codepoint = 0 ) const ;
^~~~~~~~~~~~~
tinyutf8.h:1728:12: note: no known conversion for argument 1 from ‘utf8_string’ to ‘const value_type* {aka const char32_t*}’

如何从utf8_string获得char32_t*? 或者,还有什么其他机制可以在另一个utf8_string中找到utf8_string

谢谢! 肖恩

Shawn,目前tiny_utf8不支持find_first_ofutf8_string作为参数。但是,要回答您的第二个问题:您可以使用utf8_string::to_wide_literal( &char32_buffer )utf8_string转换为char32_t[]

我希望这至少有一点帮助(即使您说您自己已经解决了问题,我很高兴听到:D(。

万事如意, 雅 各 布