PrevUpHomeNext

utx::split_view


class utx::split_view

class split_view: virtual protected std::vector<std::string_view>;

Destructor

virtual ~split_view() noexcept;

Constructor

The std::string_view str is used as the param of constructor,

however the data member is utx::string str_data, which has its own copy.

split_view(const std::string_view str, const utx::delim & delim) noexcept;

This is the only available constructor. When the object is created, the underlying string data is splitted with calling this->split();

Removed Constructors and Operators =

All other (copy) constructors, and operator= methods are removed: =delete;

So all copy actions are disabled.

Methods

split(delim)

Reset the str_delim value and call this->split(); to do string split again.

public:
	void split(const utx::delim & delim) noexcept;

split(void)

Every time calling this->split();, it will split the underlying string again.

protected:
	void split() noexcept;

operator[]

[] access. with boundary check (exception), and const_reference, (not assignable).

There is no assignable version of operator[].

parent_type::const_reference operator[](parent_type::size_type pos) const;

begin() and end()

These two methods let the utx::split_view object be used for range-based for loop, and iteratable.

parent_type::const_iterator begin() const noexcept;

parent_type::const_iterator end() const noexcept;

split_size()

Get the splitted count of the underlying string.

parent_type::size_type split_size() const noexcept;

all_data_size()

Get all string size of the underlying strings: str_data.size() + str_delim.size()

parent_type::size_type all_data_size() const noexcept;

Removed size()

Method size() is removed to prevent mistaking usage.

parent_type::size_type size() const noexcept = delete;

operator<<

This method will let the utx::split_view object be printable: std::cout << splitviewobj;

And be utx::kspt::printable: utx::print(splitviewobj);

template <utx::kspt::ostreamable OutStream>
friend OutStream & operator<<(OutStream & os, const utx::split_view & splitView);

data()

Just return the underlying string data. (has string copy).

utx::string data() const;

data_view()

Just return the view of the underlying data. (no string copy).

const std::string_view data_view() const;

Data Members

protected:
	const utx::string str_data;
	utx::delim str_delim;

A vector derived from std::vector<std::string_view> :

The vector stores splitted string_view of str_data, with str_delim.

Example

If you create a constant object of utx::split_view, you can not split it again:

const utx::split_view sv{"Boost Software", ' '};

sv.split('t'); // ERROR

// If you create a constant object of utx::split_view, you can not split it again:
//				const utx::split_view sv{"Boost Software", ' '};
//				sv.split('t'); // ERROR
#include <utxcpp/core.hpp>

int main() {
	utx::split_view sv1{"Boost Software", ' '};
	std::cout << sv1 << '\n'; // {"Boost"; "Software"; }

	sv1.split('o');
	utx::print(sv1); // {"B"; "st S"; "ftware"; }

	sv1.split("oo");
	utx::print(sv1); // {"B"; "st Software"; }

	const auto str2 = utx::string{"CPP Boost Software"};
	auto sv2 = utx::split_view{str2, " "};
	for (const std::string_view view: sv2)
		utx::print("=>", view);
			/*
=> CPP
=> Boost
=> Software
			*/
}

Last revised: November 24, 2022 at 11:26:05 GMT


PrevUpHomeNext