PrevUpHomeNext

esv::split_view


Protect animals from me.

esv::split_view

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

Constructors

Construct esv::split_view with string and delimiter

Calling Sig:

esv::split_view view{a_string, a_delim};

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

Calling Sig:

esv::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,

esv::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 <esvcpp/core.hpp>

int main()
{
	esv::split_view v1{"c++ boost"};
	esv::print(v1[0]);	// c++
	esv::print(v1[1]);	// boost

	v1.split("o");
	esv::print(v1[0]);	// c++ b
	esv::print(v1[1]);	// st

	esv::print(v1);	// {"c++ b", "st"}
}

See Also

esv::print

esv::wsplit_view


PrevUpHomeNext

esv::print