Sane C++ Libraries
C++ Platform Abstraction Libraries
SC::String Struct Reference

A non-modifiable owning string with associated encoding. More...

#include <String.h>

Inheritance diagram for SC::String:
SC::SmallString< 30 > SC::SmallString< N >

Public Member Functions

 String (StringEncoding encoding=StringEncoding::Utf8)
 Builds an empty String with a given Encoding. More...
 
 String (StringView sv)
 Builds String from a StringView. More...
 
template<size_t N>
 String (const char(&text)[N])
 Builds String with a null terminated char string literal. More...
 
bool owns (StringView view) const
 Checks if the memory pointed by the StringView is owned by this String. More...
 
bool assign (StringView sv)
 Assigns a StringView to this String, replacing existing contents. More...
 
StringEncoding getEncoding () const
 Get StringView encoding. More...
 
size_t sizeInBytesIncludingTerminator () const
 Get length of the string in bytes (including null terminator bytes) More...
 
const char * bytesIncludingTerminator () const
 Access current string content as read-only null-terminated const char* More...
 
bool isEmpty () const
 Check if String is empty. More...
 
StringView view () const SC_LANGUAGE_LIFETIME_BOUND
 Obtain a null-terminated StringView from current String. More...
 
bool operator== (const String &other) const
 Check if current String is same as other String. More...
 
bool operator!= (const String &other) const
 Check if current String is different from other String. More...
 
bool operator== (const StringView other) const
 Check if current String is same as other StringView. More...
 
bool operator!= (const StringView other) const
 Check if current String is different from other StringView. More...
 
bool operator< (const StringView other) const
 Check if current String is smaller to another StringView (using StringView::compare) More...
 
template<size_t N>
bool operator== (const char(&other)[N]) const
 Check if current String is equal to the ascii string literal. More...
 
template<size_t N>
bool operator!= (const char(&other)[N]) const
 Check if current String is different from the ascii string literal. More...
 
template<size_t N>
Stringoperator= (const char(&text)[N])
 Assigns an ascii string literal to current String. More...
 

Protected Member Functions

auto nativeWritableBytesIncludingTerminator ()
 

Protected Attributes

StringEncoding encoding
 
Vector< char > data
 

Friends

struct SmallStringTest
 
struct StringBuilder
 
struct StringConverter
 
struct FileDescriptor
 
struct FileSystem
 
template<int >
struct SmallString
 
template<typename T >
struct Reflection::Reflect
 

Detailed Description

A non-modifiable owning string with associated encoding.

SC::String is (currently) implemented as a SC::Vector with the associated string encoding. A SC::StringView can be obtained from it calling SC::String::view method but it's up to the user making sure that the usage of such SC::StringView doesn't exceed lifetime of the SC::String it originated from (but thankfully Address Sanitizer will catch the issue if it goes un-noticed).

Constructor & Destructor Documentation

◆ String() [1/3]

SC::String::String ( StringEncoding  encoding = StringEncoding::Utf8)
inline

Builds an empty String with a given Encoding.

Parameters
encodingThe encoding of the String

◆ String() [2/3]

SC::String::String ( StringView  sv)
inline

Builds String from a StringView.

Parameters
svStringView to be assigned to this String
Warning
This function will assert if StringView::assign fails

◆ String() [3/3]

template<size_t N>
SC::String::String ( const char(&)  text[N])
inline

Builds String with a null terminated char string literal.

Template Parameters
NLength of the string literal (including null terminator)
Parameters
textPointer to string literal
Warning
This function will assert if StringView::assign fails

Member Function Documentation

◆ assign()

bool SC::String::assign ( StringView  sv)
inline

Assigns a StringView to this String, replacing existing contents.

Parameters
svStringView to be assigned to this string
Returns
true if StringView is assigned successfully
Note
This method will invalidate any StringView::view previously obtained

◆ bytesIncludingTerminator()

const char * SC::String::bytesIncludingTerminator ( ) const
inline

Access current string content as read-only null-terminated const char*

Returns
A null terminated const char*

◆ getEncoding()

StringEncoding SC::String::getEncoding ( ) const
inline

Get StringView encoding.

Returns
Current encoding for this String

◆ isEmpty()

bool SC::String::isEmpty ( ) const
inline

Check if String is empty.

Returns
true if String is empty

◆ operator!=() [1/3]

template<size_t N>
bool SC::String::operator!= ( const char(&)  other[N]) const
inline

Check if current String is different from the ascii string literal.

Template Parameters
NLength of string literal, including null terminator
Parameters
otherThe string literal
Returns
true if the String is different from other

◆ operator!=() [2/3]

bool SC::String::operator!= ( const String other) const
inline

Check if current String is different from other String.

Parameters
otherString to be checked
Returns
true if the two strings are different

◆ operator!=() [3/3]

bool SC::String::operator!= ( const StringView  other) const
inline

Check if current String is different from other StringView.

Parameters
otherStringView to be checked
Returns
true if the String and StringView are different

◆ operator<()

bool SC::String::operator< ( const StringView  other) const
inline

Check if current String is smaller to another StringView (using StringView::compare)

Parameters
otherStringView to be checked
Returns
true if the String is smaller than StringView (using StringView::compare)

◆ operator=()

template<size_t N>
String & SC::String::operator= ( const char(&)  text[N])
inline

Assigns an ascii string literal to current String.

Template Parameters
NLength of string literal, including null terminator
Parameters
textThe string literal
Returns
Reference to current String
Warning
Assignment operator will assert if String::assign fails

◆ operator==() [1/3]

template<size_t N>
bool SC::String::operator== ( const char(&)  other[N]) const
inline

Check if current String is equal to the ascii string literal.

Template Parameters
NLength of string literal, including null terminator
Parameters
otherThe string literal
Returns
true if the String is the same as other

◆ operator==() [2/3]

bool SC::String::operator== ( const String other) const
inline

Check if current String is same as other String.

Parameters
otherString to be checked
Returns
true if the two strings are equal

◆ operator==() [3/3]

bool SC::String::operator== ( const StringView  other) const
inline

Check if current String is same as other StringView.

Parameters
otherStringView to be checked
Returns
true if the String and StringView are equal

◆ owns()

bool SC::String::owns ( StringView  view) const
inline

Checks if the memory pointed by the StringView is owned by this String.

Parameters
viewStringView to be checked
Returns
true if StringView memory belongs to this String

◆ sizeInBytesIncludingTerminator()

size_t SC::String::sizeInBytesIncludingTerminator ( ) const
inline

Get length of the string in bytes (including null terminator bytes)

Returns
Size in bytes including null terminator

◆ view()

SC::StringView SC::String::view ( ) const
inline

Obtain a null-terminated StringView from current String.

Returns
a null-terminated StringView from current String

The documentation for this struct was generated from the following file: