本文整理汇总了C++中wcstring_list_t::erase方法的典型用法代码示例。如果您正苦于以下问题:C++ wcstring_list_t::erase方法的具体用法?C++ wcstring_list_t::erase怎么用?C++ wcstring_list_t::erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wcstring_list_t
的用法示例。
在下文中一共展示了wcstring_list_t::erase方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: erase_values
/**
Erase from a list of wcstring values at specified indexes
*/
static void erase_values(wcstring_list_t &list, const std::vector<long> &indexes)
{
// Make a set of indexes.
// This both sorts them into ascending order and removes duplicates.
const std::set<long> indexes_set(indexes.begin(), indexes.end());
// Now walk the set backwards, so we encounter larger indexes first, and remove elements at the given (1-based) indexes.
std::set<long>::const_reverse_iterator iter;
for (iter = indexes_set.rbegin(); iter != indexes_set.rend(); iter++) {
long val = *iter;
if (val > 0 && val <= list.size()) {
// One-based indexing!
list.erase(list.begin() + val - 1);
}
}
}
示例2: join_completions
/**
Merge multiple completions with the same description to the same line
*/
static void join_completions( wcstring_list_t lst )
{
std::map<wcstring, long> desc_table;
for( size_t i=0; i<lst.size(); i++ )
{
const wchar_t *item = lst.at(i).c_str();
const wchar_t *desc = wcschr( item, COMPLETE_SEP );
long prev_idx;
if( !desc )
continue;
desc++;
prev_idx = desc_table[desc] - 1;
if( prev_idx == -1 )
{
desc_table[desc] = (long)(i+1);
}
else
{
const wchar_t *old = lst.at(i).c_str();
const wchar_t *old_end = wcschr( old, COMPLETE_SEP );
if( old_end )
{
wcstring foo;
foo.append(old, old_end - old);
foo.push_back(COMPLETE_ITEM_SEP);
foo.append(item);
lst.at(prev_idx) = foo;
lst.at(i).clear();
}
}
}
/* Remove empty strings */
lst.erase(remove(lst.begin(), lst.end(), wcstring()), lst.end());
}