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


C++ Word::Characters方法代码示例

本文整理汇总了C++中Word::Characters方法的典型用法代码示例。如果您正苦于以下问题:C++ Word::Characters方法的具体用法?C++ Word::Characters怎么用?C++ Word::Characters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Word的用法示例。


在下文中一共展示了Word::Characters方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: QueryMatchResult

Result Candidate::QueryMatchResult( const Word &query ) const {
  // Check if the query is a subsequence of the candidate and return a result
  // accordingly. This is done by simultaneously going through the characters of
  // the query and the candidate. If both characters match, we move to the next
  // character in the query and the candidate. Otherwise, we only move to the
  // next character in the candidate. The matching is a combination of smart
  // base matching and smart case matching. If there is no character left in the
  // query, the query is not a subsequence and we return an empty result. If
  // there is no character left in the candidate, the query is a subsequence and
  // we return a result with the query, the candidate, the sum of indexes of the
  // candidate where characters matched, and a boolean that is true if the query
  // is a prefix of the candidate.

  if ( query.IsEmpty() ) {
    return Result( this, &query, 0, false );
  }

  if ( Length() < query.Length() ) {
    return Result();
  }

  size_t query_index = 0;
  size_t candidate_index = 0;
  size_t index_sum = 0;

  const CharacterSequence &query_characters = query.Characters();
  const CharacterSequence &candidate_characters = Characters();

  auto query_character_pos = query_characters.begin();
  auto candidate_character_pos = candidate_characters.begin();

  for ( ; candidate_character_pos != candidate_characters.end();
          ++candidate_character_pos, ++candidate_index ) {

    const auto &candidate_character = *candidate_character_pos;
    const auto &query_character = *query_character_pos;

    if ( query_character->MatchesSmart( *candidate_character ) ) {
      index_sum += candidate_index;

      ++query_character_pos;
      if ( query_character_pos == query_characters.end() ) {
        return Result( this,
                       &query,
                       index_sum,
                       candidate_index == query_index );
      }

      ++query_index;
    }
  }

  return Result();
}
开发者ID:Valloric,项目名称:ycmd,代码行数:54,代码来源:Candidate.cpp


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