PrevUpHomeNext

Strings

String container
String constant reference

#include <oglplus/string/def.hpp>

This header defines basic string-related class and functions.

The String class has the same interface as an std::basic_string<GLchar> except that the string stored inside must be UTF-8 encoded.

class String
 : public std::basic_string<GLchar>
{
public:
	using std::basic_string<GLchar>::basic_string; 1
};

const String& EmptyString(void); 2

bool ValidString(const char* begin, const char* end); 3

1

String has the same constructors as a std::basic_string. except that the input strings must be UTF-8 encoded, otherwise the behavior is undefined.

2

Returns a const reference to an empty String.

3

Checks if the character range between begin and end is a valid UTF-8 sequence.

#include <oglplus/string/ref.hpp>

The StrCRef class stores a reference to an UTF-8 encoded constant character string. It is used as an adaptor or a type erasure for other types storing strings, (like String, std::vector<GLchar>, const GLchar*, etc.) and is used as parameter type to limit the number of overloads of functions performing the same task on strings stored in different manner.

[Note] Note

The lifetime management of the memory block where the string is stored is outside the scope of this class. This means that the actual object storing the string must not be destroyed while an instance of StrCRef wrapping it is being used.

class StrCRef
{
public:
	StrCRef(void) noexcept; 1

	StrCRef(const GLchar* cstr) noexcept; 2
	StrCRef(const GLchar* cstr, size_t size) noexcept; 3

	template <size_t N>
	StrCRef(const GLchar (&cary)[N]) noexcept; 4

	StrCRef(const String& sstr) noexcept; 5

	StrCRef(const std::vector<GLchar>& cvec) noexcept; 6

	template <size_t N>
	StrCRef(const std::array<GLchar, N>& cvec) noexcept; 7

	size_t size(void) const noexcept; 8
	bool empty(void) const noexcept; 9

	typedef const GLchar* iterator; 10
	typedef iterator const_iterator;

	const_iterator begin(void) const noexcept;
	const_iterator end(void) const noexcept;

	bool is_nts(void) const noexcept; 11

	const GLchar* c_str(void) const noexcept; 12

	String str(void) const; 13

	friend bool operator == (const StrCRef& a, const StrCRef& b); 14
	friend bool operator == (const StrCRef& a, const Char* b);
	friend bool operator == (const Char* a, const StrCRef& b);
	friend bool operator != (const StrCRef& a, const StrCRef& b);
	friend bool operator != (const StrCRef& a, const Char* b);
	friend bool operator != (const Char* a, const StrCRef& b);
};

1

Constructs a reference to an empty string.

2

Constructs a reference to a C-string.

3

Constructs a reference to a C-string with a specific size.

4

Constructs a reference to a character array with a known size.

5

Constructs a reference to a string stored inside of a String.

6

Constructs a reference to a string stored inside of a std::vector.

7

Constructs a reference to a string stored inside of a std::array.

8

Returns the lenght of the string, not counting any terminating characters.

9

Returns true if the referenced string is empty.

10

Iterator types.

11

Returns true if the string is null-terminated

12

Returns a const pointer to the referenced character string. This function may be called only if the string stored inside is null-terminated.

13

Returns the referenced character string as a String.

14

Comparison operators.

#include <oglplus/string/ref_ios.hpp>

Output of StrCRef to std::ostream is implemented in a separate header file.

std::ostream& operator << (std::ostream& out, const StrCRef& str);

PrevUpHomeNext