本文整理汇总了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();
}