当前位置: 首页>>代码示例>>C++>>正文


C++ utf8_string::find方法代码示例

本文整理汇总了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;
}
开发者ID:lukas-ke,项目名称:faint-graphics-editor,代码行数:43,代码来源:split-string.cpp

示例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));
  }
}
开发者ID:lukas-ke,项目名称:faint-graphics-editor,代码行数:40,代码来源:split-string.cpp


注:本文中的utf8_string::find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。