本文整理汇总了C++中STR::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ STR::empty方法的具体用法?C++ STR::empty怎么用?C++ STR::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类STR
的用法示例。
在下文中一共展示了STR::empty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TrimStringT
TrimPositions TrimStringT(const STR& input,
const STR& trim_chars,
TrimPositions positions,
STR* output) {
// Find the edges of leading/trailing whitespace as desired.
const size_t last_char = input.length() - 1;
const size_t first_good_char = (positions & TRIM_LEADING) ?
input.find_first_not_of(trim_chars) : 0;
const size_t last_good_char = (positions & TRIM_TRAILING) ?
input.find_last_not_of(trim_chars) : last_char;
// When the string was all whitespace, report that we stripped off whitespace
// from whichever position the caller was interested in. For empty input, we
// stripped no whitespace, but we still need to clear |output|.
if (input.empty() ||
(first_good_char == STR::npos) || (last_good_char == STR::npos)) {
bool input_was_empty = input.empty(); // in case output == &input
output->clear();
return input_was_empty ? TRIM_NONE : positions;
}
// Trim the whitespace.
*output =
input.substr(first_good_char, last_good_char - first_good_char + 1);
// Return where we trimmed from.
return static_cast<TrimPositions>(
((first_good_char == 0) ? TRIM_NONE : TRIM_LEADING) |
((last_good_char == last_char) ? TRIM_NONE : TRIM_TRAILING));
}
示例2: TrimStringT
TrimPositions TrimStringT(const STR& input,
const typename STR::value_type trim_chars[],
TrimPositions positions,
STR* output)
{
// 根据移除选项positions查找两端边界.
const typename STR::size_type last_char = input.length() - 1;
const typename STR::size_type first_good_char = (positions&TRIM_LEADING) ?
input.find_first_not_of(trim_chars) : 0;
const typename STR::size_type last_good_char = (positions&TRIM_TRAILING) ?
input.find_last_not_of(trim_chars) : last_char;
// 当字符串所有字符都是空白, 根据调用传入的positions返回TrimPositions.
// 对于空输入没有去除任何空白, 但仍需要对output串调用clear.
if(input.empty() || (first_good_char==STR::npos) || (last_good_char==STR::npos))
{
bool input_was_empty = input.empty();
output->clear();
return input_was_empty ? TRIM_NONE : positions;
}
// 移除空白.
*output = input.substr(first_good_char, last_good_char-first_good_char+1);
// 返回两端哪边移除过.
return static_cast<TrimPositions>(
((first_good_char==0)?TRIM_NONE:TRIM_LEADING) |
((last_good_char==last_char)?TRIM_NONE:TRIM_TRAILING));
}