{"id":15395106,"url":"https://github.com/goto-bus-stop/cpp-split-string","last_synced_at":"2025-07-15T03:39:43.835Z","repository":{"id":66054142,"uuid":"216796822","full_name":"goto-bus-stop/cpp-split-string","owner":"goto-bus-stop","description":"A simple C++17 class to iterate over pieces of a string using ranged for loops.","archived":false,"fork":false,"pushed_at":"2020-01-07T13:05:35.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"default","last_synced_at":"2025-03-27T23:44:31.385Z","etag":null,"topics":["cpp","lines","ranged-for","split","string"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/goto-bus-stop.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-Apache.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-22T11:27:15.000Z","updated_at":"2020-01-07T13:05:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"380f1040-96b5-4bdc-9bdf-883216f159c9","html_url":"https://github.com/goto-bus-stop/cpp-split-string","commit_stats":{"total_commits":8,"total_committers":1,"mean_commits":8.0,"dds":0.0,"last_synced_commit":"f52b8087b9d8525087a96e68e31d13c9dfd086d1"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/goto-bus-stop/cpp-split-string","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goto-bus-stop%2Fcpp-split-string","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goto-bus-stop%2Fcpp-split-string/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goto-bus-stop%2Fcpp-split-string/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goto-bus-stop%2Fcpp-split-string/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goto-bus-stop","download_url":"https://codeload.github.com/goto-bus-stop/cpp-split-string/tar.gz/refs/heads/default","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goto-bus-stop%2Fcpp-split-string/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265398195,"owners_count":23758467,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","lines","ranged-for","split","string"],"created_at":"2024-10-01T15:25:44.789Z","updated_at":"2025-07-15T03:39:43.764Z","avatar_url":"https://github.com/goto-bus-stop.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# split-string\nA simple C++17 class to iterate over pieces of a string using ranged for loops.\n\nIt iterates over `string_view` containers only. It could be more generic by accepting iterator pairs, but I don't need it to be, and I don't like dealing with iterator pairs. 🤷🏻\n\n```cpp\n#include \u003csplit_string.hpp\u003e\n\nint main () {\n  for (auto line : split_string(\"some\\nsource\\ntext\")) {\n    std::cout \u003c\u003c \"line: \" \u003c\u003c line \u003c\u003c '\\n';\n  }\n  // line: some\n  // line: source\n  // line: text\n\n  for (auto entry : split_string(L\"a, b, c\", L\", \")) {\n    std::wcout \u003c\u003c \"value: \" \u003c\u003c entry \u003c\u003c '\\n';\n  }\n  // value: a\n  // value: b\n  // value: c\n}\n```\n\n## Install\nCopy [`include/split_string.hpp`](./include/split_string.hpp) into your project or add the repository as a submodule and add `$THIS_REPO/include` to your include path.\n\nOr with CMake do:\n```cmake\nadd_subdirectory(path/to/cpp-split-string)\ntarget_link_directories(your-target PRIVATE split-string)\n```\n\n## API\n### `auto splitter = split_string(string_view input, string_view separator)`\nCreate an iterable value for the given input string. `separator` can be anything that `std::is_convertible\u003c\u003e` to a `string_view.`\n\nThis is a templated function that will accept any kind of `std::basic_string_view\u003cCharT\u003e`. The `separator` and `input` must use the same character type. Use `auto` to avoid naming the return type. The full signature is:\n\n```cpp\ntemplate\u003ctypename CharT\u003e\nsplit_string(std::basic_string_view\u003cCharT\u003e input, std::basic_string_view\u003cCharT\u003e separator);\n\ntemplate\u003ctypename CharT, typename SepT, typename = typename std::enable_if\u003c\n  std::is_convertible_v\u003cSepT, value_type\u003e\u003e::type\u003e\nsplit_string(std::basic_string_view\u003cCharT\u003e input, SepT separator);\n```\n\n### `split_string\u003cCharT\u003e::iterator begin = splitter.begin()`\nGet the iterator for the first character in the string.\n\n### `split_string\u003cCharT\u003e::iterator end = splitter.end()`\nGet the iterator for the end of the string.\n\n### `split_string\u003cCharT\u003e::reverse_iterator begin = splitter.rbegin()`\nGet the reverse iterator for the entire remaining string.\n\n### `split_string\u003cCharT\u003e::reverse_iterator end = splitter.rend()`\nGet the reverse iterator for the start of the string.\n\n### `auto reverse_splitter = rsplit_string(string_view input, string_view separator)`\nCreate an iterable value that proxies its `begin()` and `end()` calls to the reverse iterator of `split_string`.\n\nThis way you can do reverse iteration in a ranged for loop, and not fiddle around with `rbegin()` and `rend()`:\n```cpp\nfor (auto line : rsplit_string(\"some\\nsource\\ntext\")) {\n  std::cout \u003c\u003c \"line: \" \u003c\u003c line \u003c\u003c '\\n';\n}\n// line: text\n// line: source\n// line: some\n```\n\n### `split_string\u003cAnyT\u003e::reverse_iterator begin = reverse_splitter.begin()`\nGet the reverse iterator for the entire remaining string.\n\n### `split_string\u003cAnyT\u003e::reverse_iterator end = reverse_splitter.end()`\nGet the reverse iterator for the start of the string.\n\n## License\n[MIT](./LICENSE-MIT.md) or [Apache-2.0](./LICENSE-Apache.md) at your option.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoto-bus-stop%2Fcpp-split-string","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoto-bus-stop%2Fcpp-split-string","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoto-bus-stop%2Fcpp-split-string/lists"}