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


C++ string_view::size方法代码示例

本文整理汇总了C++中std::experimental::string_view::size方法的典型用法代码示例。如果您正苦于以下问题:C++ string_view::size方法的具体用法?C++ string_view::size怎么用?C++ string_view::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::experimental::string_view的用法示例。


在下文中一共展示了string_view::size方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main () {
    test ( "ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
    test ( "ABCDE");
    test ( "a" );
    test ( "" );

    test ( L"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
    test ( L"ABCDE" );
    test ( L"a" );
    test ( L"" );

#if __cplusplus >= 201103L
    test ( u"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
    test ( u"ABCDE" );
    test ( u"a" );
    test ( u"" );

    test ( U"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
    test ( U"ABCDE" );
    test ( U"a" );
    test ( U"" );
#endif
    
#if _LIBCPP_STD_VER > 11
    {
    constexpr std::experimental::string_view sv1 { "ABCDE", 5 };

    {
    constexpr std::experimental::string_view sv2 = sv1.substr ( 0, 3 );
    static_assert ( sv2.size() == 3, "" );
    static_assert ( sv2[0] == 'A', "" );
    static_assert ( sv2[1] == 'B', "" );
    static_assert ( sv2[2] == 'C', "" );
    }
    
    {
    constexpr std::experimental::string_view sv2 = sv1.substr ( 3, 0 );
    static_assert ( sv2.size() == 0, "" );
    }

    {
    constexpr std::experimental::string_view sv2 = sv1.substr ( 3, 3 );
    static_assert ( sv2.size() == 2, "" );
    static_assert ( sv2[0] == 'D', "" );
    static_assert ( sv2[1] == 'E', "" );
    }
    }
#endif
}
开发者ID:32bitmicro,项目名称:riscv-libcxx,代码行数:49,代码来源:substr.pass.cpp

示例2: main

int main () {
    test ( "ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
    test ( "ABCDE");
    test ( "a" );
    test ( "" );

    test ( L"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
    test ( L"ABCDE" );
    test ( L"a" );
    test ( L"" );

    test ( u"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
    test ( u"ABCDE" );
    test ( u"a" );
    test ( u"" );

    test ( U"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
    test ( U"ABCDE" );
    test ( U"a" );
    test ( U"" );
    
    {
    constexpr std::experimental::string_view sv1 { "ABCDE", 5 };

    {
    constexpr std::experimental::string_view sv2 = sv1.substr ( 0, 3 );
    static_assert ( sv2.size() == 3, "" );
    static_assert ( sv2[0] == 'A', "" );
    static_assert ( sv2[1] == 'B', "" );
    static_assert ( sv2[2] == 'C', "" );
    }
    
    {
    constexpr std::experimental::string_view sv2 = sv1.substr ( 3, 0 );
    static_assert ( sv2.size() == 0, "" );
    }

    {
    constexpr std::experimental::string_view sv2 = sv1.substr ( 3, 3 );
    static_assert ( sv2.size() == 2, "" );
    static_assert ( sv2[0] == 'D', "" );
    static_assert ( sv2[1] == 'E', "" );
    }
    }
    
}
开发者ID:massa,项目名称:string_view,代码行数:46,代码来源:substr.pass.cpp

示例3: splitted

		static OutputContainer splitted(const std::experimental::string_view &collection, const Element &element) {
			OutputContainer output;
			if(!collection.empty()) {
				unsigned int start = 0, i = 0;
				for(; i != collection.size();) {
					if(collection[i] == element) {
						output.push_back(collection.substr(start, i-start));
						++i;
						start = i;
					} else
						++i;
				}
				output.push_back(collection.substr(start, i));
			}
			return output;
		}
开发者ID:mplucinski,项目名称:Tial,代码行数:16,代码来源:Algorithm.hpp

示例4: encode

std::string uri::encode(const std::experimental::string_view input) {
  static const std::array<char,16> hex =
    {{ '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' }};

  std::string res;
  res.reserve(input.size());

  for (const auto chr : input)
    if (is_unreserved(chr)) {
      res += chr;
    } else {
      res += '%';
      res += hex[ chr >> 4 ];
      res += hex[ chr & 0xf ];
    }

  return res;
}
开发者ID:includeos,项目名称:uri,代码行数:18,代码来源:percent_encoding.cpp

示例5: decode

std::string uri::decode(const std::experimental::string_view input) {
  std::string res;
  res.reserve(input.size());
  for (auto it = input.cbegin(), e = input.cend(); it not_eq e; ++it) {
    if (*it == '%') {

      if (++it >= e) return decode_error(std::move(res));
      const uint8_t nibble1 = (*it);

      if (++it >= e) return decode_error(std::move(res));
      const uint8_t nibble2 = (*it);

      res += static_cast<char>(from_hex(nibble1, nibble2));

    } else {
      if (is_reserved(*it) or is_unreserved(*it))
        res += *it;
      else
        return decode_error(std::move(res));
    }
  }
  return res;
}
开发者ID:includeos,项目名称:uri,代码行数:23,代码来源:percent_encoding.cpp


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