PrevUpHomeNext

utx::split_view


utx::split_view

utx::split_view is a template class alias, used to split a string into several parts by a delimiter.

Constructors

Construct utx::split_view with string and delimiter

Calling Sig:

utx::split_view view{a_string, a_delim};

Construct utx::split_view with string and default delimiter: a space

Calling Sig:

utx::split_view view{a_string};

The holding string can be only assigned on constructor, and can not be changed after constructed.

Method: .split

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.

Calling Sig:

view.split(new_delimiter);	// split again

Method: .split_camel

This member function is used to split the string by camel case. For example, It splits "HelloWorld" to "Hello", "World" .

Default split: split by camel case

Calling Sig:

view.split_camel();

Split by camel case, but keep brand name

Calling Sig:

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" .

Method: .operator[]

Access the specified splitted part by an index.

If the index is out of range, an exception std::runtime_error will be thrown.

Calling Sig:

auto sub_str = view[inde_value];

Methods: .begin(), .end()

Access the splitted parts as range.

these two methods let it accessible by range-based for loop.

Calling Sig:

auto part_itr = view.begin();
auto end = view.end();

Method: .split_size()

Return the number of parts that the string is splitted into.

Calling Sig:

auto count = view.split_size();

Method: .str_size()

Return the string size of holding string.

Calling Sig:

auto str_length = view.str_size();

.operator<<

Print every parts of the splitted string.

Calling Sig:

std::cout << view << std::endl;

Removed Methods

These member functions are removed:

cpp example

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"}
}

See Also

utx::print

utx::wsplit_view


PrevUpHomeNext

utx::print

esv::print