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


C++ STR::empty方法代码示例

本文整理汇总了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));
	}
开发者ID:623442733,项目名称:cef,代码行数:30,代码来源:string_util.cpp

示例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));
}
开发者ID:Strongc,项目名称:Chrome_Library,代码行数:29,代码来源:string_util.cpp


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