本文整理汇总了C++中utf8_string::find方法的典型用法代码示例。如果您正苦于以下问题:C++ utf8_string::find方法的具体用法?C++ utf8_string::find怎么用?C++ utf8_string::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utf8_string
的用法示例。
在下文中一共展示了utf8_string::find方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: split_string
text_lines_t split_string(const TextInfo& info,
const utf8_string& string,
const max_width_t& maxWidth)
{
size_t lineEnd = 0;
size_t lineStart = 0;
text_lines_t result;
do {
lineEnd = string.find(chars::eol, lineStart);
bool softBreak = lineEnd == std::string::npos;
if (softBreak){
lineEnd = string.size();
}
const coord width = info.GetWidth(slice(string, lineStart, lineEnd));
if (maxWidth.NotSet() || width < maxWidth.Get()){
if (softBreak){
result.push_back(TextLine::SoftBreak(width,
slice(string, lineStart, lineEnd) + chars::space));
lineStart = lineEnd + 1;
}
else{
result.push_back(TextLine::HardBreak(width,
slice(string, lineStart, lineEnd) + chars::space));
lineStart = lineEnd + 1;
}
}
else{
split_line(info, slice(string, lineStart, lineEnd),
maxWidth.Get(), result);
lineStart = lineEnd;
}
} while (lineEnd != string.size());
if (!result.empty()){
// Remove trailing space from last line
auto& last = result.back().text;
last = slice_up_to(last, -1);
}
return result;
}
示例2: split_line
// Split a line at suitable positions to make it shorter than
// maxWidth. The line should not contain embedded line breaks.
static void split_line(const TextInfo& info,
const utf8_string& string,
coord maxWidth, text_lines_t& result)
{
size_t wordStart = 0;
size_t wordEnd = 0;
utf8_string line;
do {
wordEnd = string.find(chars::space, wordStart);
if (wordEnd == std::string::npos){
wordEnd = string.size();
}
utf8_string word = slice(string, wordStart, wordEnd);
const coord width = info.GetWidth(line + chars::space + word);
if (!line.empty() && width > maxWidth){
result.push_back(TextLine::SoftBreak(width, line + chars::space));
line.clear();
}
if (info.GetWidth(word) > maxWidth){
word = split_word(info, word, result);
}
if (!line.empty()){
line += chars::space;
}
line += word;
wordStart = wordEnd + 1;
} while (wordEnd != string.size());
if (line.size() > 1){
const utf8_string last(line + chars::space);
const coord width = info.GetWidth(last);
result.push_back(TextLine::SoftBreak(width, last));
}
}