项目作者: yumetodo

项目描述 :
STLのstringをchain method風味にsplitする
高级语言: C++
项目地址: git://github.com/yumetodo/string_split.git
创建时间: 2016-07-05T17:57:49Z
项目社区:https://github.com/yumetodo/string_split

开源协议:Boost Software License 1.0

下载


string split like chain method

Run Status
Build Status
Coverage Status
Boost Software License

This is a C++ header only library to split string.

Usage

Just include include/string_split.hpp.

  1. #include "../include/string_split.hpp"
  2. #include <iostream>
  3. int main()
  4. {
  5. std::string s = "arikitari na world!";
  6. const auto s_1 = s | split(' ')[1];//"na"
  7. std::string s2 = "123,421,113";
  8. const auto s_2 = s2 | split(',') >> [](const std::string& s) {
  9. return std::stoi(s);
  10. };//[123,421,113]
  11. s2 | split(',') >> [](std::string&& s) {
  12. std::cout << s << std::endl;
  13. };
  14. /*stdout:
  15. 123
  16. 421
  17. 113
  18. */
  19. return 0;
  20. }

Temporary std::vector<std::string> will not be created becase the priority of operator[]/operator>> is higher than operator|

Compiler requirement

C++11 support is required(need C++14 support is required to compile testcase).

However, we support Visual Studio 2015 update2 or later.

std::string_view

We are supporting std::basic_string_view.

Enable C++17 mode and use below:

  • Visual Studio 2017
  • GCC 7.1 or later
  • clang 4 or later