utx::split_view is a template class alias, used to split a string into several parts by a delimiter.
utx::split_view view{a_string, a_delim};
utx::split_view view{a_string};
The holding string can be only assigned on constructor, and can not be changed after constructed.
When constructed, the string will be splitted by a delimiter, the delimitter can be user-specified or default (a space).
But the string can be splitted again by a new delimiter with this member function.
view.split(new_delimiter); // split again
This member function is used to split the string by camel case. For example, It splits "HelloWorld" to "Hello", "World" .
view.split_camel();
view.split_camel({brand1, brand2, ...});
For example,
utx::split_view view{"ClassNameNVIDIANameNVLink"}; view.split_camel({"NVIDIA", "NV"}); // "Class", "Name", "NVIDIA", "Name", "NV", "Link"
It will split "ClassNameNVIDIANameNVLink" to "Class", "Name", "NVIDIA", "Name", "NV", "Link" .
Access the specified splitted part by an index.
If the index is out of range, an exception std::runtime_error will be thrown.
auto sub_str = view[inde_value];
Access the splitted parts as range.
these two methods let it accessible by range-based for loop.
auto part_itr = view.begin(); auto end = view.end();
Return the number of parts that the string is splitted into.
auto count = view.split_size();
Return the string size of holding string.
auto str_length = view.str_size();
Print every parts of the splitted string.
std::cout << view << std::endl;
These member functions are removed:
c++ example
#include <utxcpp/core.hpp> int main() { utx::split_view v1{"c++ boost"}; utx::print(v1[0]); // c++ utx::print(v1[1]); // boost v1.split("o"); utx::print(v1[0]); // c++ b utx::print(v1[1]); // st utx::print(v1); // {"c++ b", "st"} }