Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
sstr::SStringView Class Reference

String view. More...

#include <SString.h>

Inheritance diagram for sstr::SStringView:
sstr::SString

Classes

class  Iterator
 Unicode character iterator. More...
 

Public Member Functions

 SStringView () noexcept=default
 
 SStringView (const char *u8str) noexcept
 
virtual ~SStringView ()=default
 
Iterator begin ()
 
Iterator end ()
 
bool null () const
 
bool empty () const
 
size_t len () const
 
virtual size_t size () const
 
const char * data () const
 
int32_t find (const SStringView &str) const
 
int32_t find (const char *u8str) const
 
int32_t findByBytes (const char *bytes) const
 
SString trim () const
 
SString reverse () const
 
SString append (const SStringView &str) const
 
SString append (const char *u8str) const
 
std::vector< SStringsplit (const SStringView &str) const
 
std::vector< SStringsplit (const char *str) const
 
SString substring (size_t begin) const
 
SString substring (size_t begin, size_t len) const
 Extract substring [begin, begin + len - 1].
 
bool endsWith (const SStringView &suffix) const
 Check if the string ends with a given substring.
 
bool endsWith (const std::string_view &suffix) const
 Check if the string ends with a given substring.
 
bool startsWith (const SStringView &prefix) const
 Check if the string starts with a given substring.
 
bool startsWith (const std::string_view &prefix) const
 Check if the string starts with a given substring.
 
bool isLower () const
 Check if the letter is entirely lowercase.
 
bool isUpper () const
 Check if the letter is entirely uppercase.
 
SString toLower () const
 Create a copy with all letters converted to lowercase.
 
SString toUpper () const
 Create a copy with all letters converted to uppercase.
 
SChar at (size_t index) const
 
std::vector< SChartoChars () const
 
std::string toString () const
 
std::wstring toWString () const
 
std::unique_ptr< wchar_t[]> toCWString () const
 
SChar operator[] (size_t index) const
 
bool operator!= (const SStringView &str) const
 
bool operator!= (const char *u8str) const
 
bool operator== (const SStringView &str) const
 
bool operator== (const char *u8str) const
 
SString operator+ (const SStringView &str) const
 
SString operator+ (const char *u8str) const
 

Protected Attributes

char * _data = nullptr
 
size_t _size = 0
 

Detailed Description

String view.

Constructor & Destructor Documentation

◆ SStringView() [1/2]

sstr::SStringView::SStringView ( )
defaultnoexcept

◆ SStringView() [2/2]

SStringView::SStringView ( const char * u8str)
explicitnoexcept

◆ ~SStringView()

virtual sstr::SStringView::~SStringView ( )
virtualdefault

Member Function Documentation

◆ append() [1/2]

SString SStringView::append ( const char * u8str) const

Append string to the end

Parameters
u8strString to append
Returns
Resulting appended string
Deprecated
The appended string must also be UTF-8 encoded, otherwise use is not recommended

References sstr::SString::_capacity, _data, _size, BLOCK_SIZE, and len().

◆ append() [2/2]

SString SStringView::append ( const SStringView & str) const
nodiscard

Append string to the end

Parameters
strString to append
Returns
Resulting appended string

References sstr::SString::_capacity, _data, _size, and BLOCK_SIZE.

Referenced by operator+(), and operator+().

◆ at()

SChar SStringView::at ( size_t index) const
nodiscard

◆ begin()

SStringView::IteratorType SStringView::begin ( )

References _data, and _size.

Referenced by substring(), and substring().

◆ data()

const char * SStringView::data ( ) const
nodiscard

Get buffer pointer

Returns
Buffer pointer

References _data.

Referenced by find(), sese::text::AbstractStringBuffer::insertAt(), sstr::SString::operator+=(), and sese::io::OutputStream::write().

◆ empty()

bool SStringView::empty ( ) const
nodiscard

Check if the string is empty

Return values
trueString is empty
falseString is not empty

References _data.

◆ end()

SString::IteratorType SStringView::end ( )

References _data, and _size.

◆ endsWith() [1/2]

bool SStringView::endsWith ( const SStringView & suffix) const
nodiscard

Check if the string ends with a given substring.

Parameters
suffixMatching substring
Returns
Result

References _data, and _size.

◆ endsWith() [2/2]

bool SStringView::endsWith ( const std::string_view & suffix) const
nodiscard

Check if the string ends with a given substring.

Parameters
suffixMatching substring
Returns
Result

References _data, and _size.

◆ find() [1/2]

int32_t SStringView::find ( const char * u8str) const

Find substring, with index units in characters

Parameters
u8strSubstring
Returns
Substring position

References _data, sstr::BM(), count(), and sstr::getSizeFromUTF8Char().

◆ find() [2/2]

int32_t SStringView::find ( const SStringView & str) const
nodiscard

Find substring, with index units in characters

Parameters
strSubstring
Returns
Substring position

References data(), and find().

Referenced by find().

◆ findByBytes()

int32_t SStringView::findByBytes ( const char * bytes) const

Find byte string, with index units in bytes

Parameters
bytesSubstring
Returns
Substring position

References _data, and sstr::BM().

◆ isLower()

bool SStringView::isLower ( ) const
nodiscard

Check if the letter is entirely lowercase.

References _data, and _size.

◆ isUpper()

bool SStringView::isUpper ( ) const
nodiscard

Check if the letter is entirely uppercase.

References _data, and _size.

◆ len()

size_t SStringView::len ( ) const
nodiscard

◆ null()

bool SStringView::null ( ) const
nodiscard

Check if data is nullptr

Return values
true
false

References _data.

◆ operator!=() [1/2]

bool SStringView::operator!= ( const char * u8str) const

References _data.

◆ operator!=() [2/2]

bool SStringView::operator!= ( const SStringView & str) const

References _data.

◆ operator+() [1/2]

SString SStringView::operator+ ( const char * u8str) const

References append().

◆ operator+() [2/2]

SString SStringView::operator+ ( const SStringView & str) const

References append().

◆ operator==() [1/2]

bool SStringView::operator== ( const char * u8str) const

References _data.

◆ operator==() [2/2]

bool SStringView::operator== ( const SStringView & str) const

References _data.

◆ operator[]()

SChar SStringView::operator[] ( size_t index) const

References at().

◆ reverse()

SString SStringView::reverse ( ) const
nodiscard

Reverse the string

Returns
Reversed object

References _data, _size, BLOCK_SIZE, and sstr::getSizeFromUTF8Char().

◆ size()

size_t SStringView::size ( ) const
nodiscardvirtual

Get the number of bytes in the string

Returns
Number of bytes in the string

Reimplemented in sstr::SString.

References _data, and sstr::getByteLengthFromUTF8String().

Referenced by sstr::SString::operator+=(), split(), startsWith(), toCWString(), and sese::io::OutputStream::write().

◆ split() [1/2]

std::vector< SString > SStringView::split ( const char * str) const

Split the string

Parameters
strDelimiter
Returns
Split result

References _data, sstr::BM(), sstr::SString::fromUTF8(), sstr::getByteLengthFromUTF8String(), and size().

◆ split() [2/2]

std::vector< SString > SStringView::split ( const SStringView & str) const
nodiscard

Split the string

Parameters
strDelimiter
Returns
Split result

References _data, and split().

Referenced by split().

◆ startsWith() [1/2]

bool SStringView::startsWith ( const SStringView & prefix) const
nodiscard

Check if the string starts with a given substring.

Parameters
prefixMatching substring
Returns
Result

References _data, _size, and size().

◆ startsWith() [2/2]

bool SStringView::startsWith ( const std::string_view & prefix) const
nodiscard

Check if the string starts with a given substring.

Parameters
prefixMatching substring
Returns
Result

References _data, and _size.

◆ substring() [1/2]

SString SStringView::substring ( size_t begin) const
nodiscard

Extract substring [begin, len - 1]

Parameters
beginStarting index of the substring
Returns
Substring

References sstr::SString::_capacity, _data, _size, at(), begin(), and BLOCK_SIZE.

◆ substring() [2/2]

SString SStringView::substring ( size_t begin,
size_t len ) const
nodiscard

Extract substring [begin, begin + len - 1].

Parameters
beginStarting index of the substring
lenLength to extract
Returns
Substring

References sstr::SString::_capacity, _data, _size, at(), begin(), BLOCK_SIZE, count(), sstr::getSizeFromUTF8Char(), and len().

◆ toChars()

std::vector< SChar > SStringView::toChars ( ) const
nodiscard

◆ toCWString()

std::unique_ptr< wchar_t[]> SStringView::toCWString ( ) const
nodiscard

◆ toLower()

SString SStringView::toLower ( ) const
nodiscard

Create a copy with all letters converted to lowercase.

References _data, _size, and toLower().

Referenced by toLower().

◆ toString()

std::string SStringView::toString ( ) const
nodiscard

References _data.

◆ toUpper()

SString SStringView::toUpper ( ) const
nodiscard

Create a copy with all letters converted to uppercase.

References _data, _size, and toUpper().

Referenced by toUpper().

◆ toWString()

std::wstring SStringView::toWString ( ) const
nodiscard

References toCWString().

◆ trim()

SString SStringView::trim ( ) const
nodiscard

Trim whitespace from both ends of the string

Note
Note that it's whitespace
Returns
Processed object

References _data, _size, and BLOCK_SIZE.

Member Data Documentation

◆ _data

◆ _size


The documentation for this class was generated from the following files: