本文整理汇总了C++中Phrase::valid方法的典型用法代码示例。如果您正苦于以下问题:C++ Phrase::valid方法的具体用法?C++ Phrase::valid怎么用?C++ Phrase::valid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phrase
的用法示例。
在下文中一共展示了Phrase::valid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Phrase
Phrase
PinyinPhraseLib::append (const WideString &phrase, const PinyinKeyVector &keys)
{
if (phrase.length () == 0 || !valid ())
return Phrase ();
Phrase tmp = m_phrase_lib.find (phrase);
if (tmp.valid () && tmp.is_enable ())
return tmp;
tmp = m_phrase_lib.append (phrase);
if (!tmp.valid ())
return Phrase ();
insert_phrase_into_index (tmp, keys);
return tmp;
}
示例2: PinyinKeyExactLessThan
bool
PinyinPhraseLib::insert_phrase_into_index (const Phrase &phrase, const PinyinKeyVector &keys)
{
if (!phrase.valid ()) return false;
// First find out all of the chars which have no valid key in keys.
WideString content = phrase.get_content ();
WideString nokey_content;
PinyinKeyVector final_keys;
std::vector<uint32> content_state;
std::vector<PinyinKeyVector> key_vv;
uint32 pinyin_offset = m_pinyin_lib.size ();
uint32 i,j,k;
for (i=0; i<content.length (); ++i) {
if (i < keys.size () &&
keys [i].get_initial () != SCIM_PINYIN_ZeroInitial &&
keys [i].get_final () != SCIM_PINYIN_ZeroFinal) {
//This key is valid, store it into final_key.
final_keys.push_back (keys [i]);
content_state.push_back (1);
} else {
//This key is invalid, put the content into nokey_content,
//and store a zero key into final_keys,
//and store the position into invalid_key_pos.
nokey_content.push_back (content [i]);
final_keys.push_back (PinyinKey ());
content_state.push_back (0);
}
}
if (nokey_content.length ())
m_pinyin_table->find_key_strings (key_vv, nokey_content);
else
key_vv.push_back (PinyinKeyVector ());
std::sort (m_phrases [content.length () -1].begin (),
m_phrases [content.length () -1].end (),
PinyinKeyExactLessThan ());
if (m_pinyin_lib.capacity () < m_pinyin_lib.size () + key_vv.size () * content.length ())
m_pinyin_lib.reserve (m_pinyin_lib.size () + key_vv.size () * content.length () + 1);
for (i=0; i<key_vv.size(); ++i) {
for (j=0, k=0; j<content.length (); ++j) {
if (content_state [j])
m_pinyin_lib.push_back (final_keys [j]);
else
m_pinyin_lib.push_back (key_vv [i][k++]);
}
insert_pinyin_phrase_into_index (phrase.get_phrase_offset (),
pinyin_offset);
pinyin_offset = m_pinyin_lib.size ();
}
std::sort (m_phrases [content.length () -1].begin (),
m_phrases [content.length () -1].end (), m_pinyin_key_less);
return true;
}