SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Sleak::String Class Reference

A dynamic string class, similar to std::string but STL-agnostic. More...

#include <String.hpp>

Public Member Functions

 String () noexcept
 String (const char *str)
 String (const char *str, size_t len)
 String (const String &other)
 String (String &&other) noexcept
 ~String ()
 Frees the backing buffer.
Stringappend (const char *str)
Stringappend (const char *str, size_t len)
Stringappend (const String &other)
const char * c_str () const
size_t capacity () const
void clear ()
int compare (const String &other) const
bool empty () const
size_t find (const String &str, size_t pos=0) const
size_t length () const
Stringoperator+= (char ch)
Stringoperator+= (const char *str)
Stringoperator+= (const String &other)
Stringoperator= (const String &other)
Stringoperator= (String &&other) noexcept
char & operator[] (size_t index)
const char & operator[] (size_t index) const
void reserve (size_t newCapacity)
void resize (size_t newSize, char ch='\0')
size_t size () const
String substr (size_t pos=0, size_t len=npos) const

Friends

bool operator!= (const String &lhs, const String &rhs)
String operator+ (const char *lhs, const String &rhs)
String operator+ (const String &lhs, const char *rhs)
String operator+ (const String &lhs, const String &rhs)
bool operator< (const String &lhs, const String &rhs)
std::ostream & operator<< (std::ostream &os, const String &str)
bool operator<= (const String &lhs, const String &rhs)
bool operator== (const String &lhs, const String &rhs)
bool operator> (const String &lhs, const String &rhs)
bool operator>= (const String &lhs, const String &rhs)

Detailed Description

A dynamic string class, similar to std::string but STL-agnostic.

This class provides a flexible and efficient way to manage strings of characters. It is designed to be independent of the Standard Template Library (STL) and can be used in environments where STL is not available or desired.

Example Use Cases:

  • Storing and manipulating text in game engines or embedded systems.
  • Implementing custom string processing algorithms.
  • Learning about string implementation internals.

Implementation Details:

  • Uses a dynamically allocated array to store characters.
  • Provides a wide range of methods for string manipulation, including concatenation, comparison, searching, and substring extraction.
  • Automatically manages memory allocation and resizing.

Definition at line 29 of file String.hpp.

Constructor & Destructor Documentation

◆ String() [1/5]

Sleak::String::String ( )
inlinenoexcept

Definition at line 32 of file String.hpp.

◆ String() [2/5]

Sleak::String::String ( const char * str)
inline

Definition at line 34 of file String.hpp.

◆ String() [3/5]

Sleak::String::String ( const char * str,
size_t len )
inline

Definition at line 36 of file String.hpp.

◆ String() [4/5]

Sleak::String::String ( const String & other)
inline

Definition at line 42 of file String.hpp.

◆ String() [5/5]

Sleak::String::String ( String && other)
inlinenoexcept

Definition at line 47 of file String.hpp.

◆ ~String()

Sleak::String::~String ( )
inline

Frees the backing buffer.

Definition at line 54 of file String.hpp.

Member Function Documentation

◆ append() [1/3]

String & Sleak::String::append ( const char * str)
inline

Definition at line 137 of file String.hpp.

◆ append() [2/3]

String & Sleak::String::append ( const char * str,
size_t len )
inline

Definition at line 141 of file String.hpp.

◆ append() [3/3]

String & Sleak::String::append ( const String & other)
inline

Definition at line 133 of file String.hpp.

◆ c_str()

const char * Sleak::String::c_str ( ) const
inline

Definition at line 152 of file String.hpp.

◆ capacity()

size_t Sleak::String::capacity ( ) const
inline

Definition at line 103 of file String.hpp.

◆ clear()

void Sleak::String::clear ( )
inline

Definition at line 107 of file String.hpp.

◆ compare()

int Sleak::String::compare ( const String & other) const
inline

Definition at line 154 of file String.hpp.

◆ empty()

bool Sleak::String::empty ( ) const
inline

Definition at line 104 of file String.hpp.

◆ find()

size_t Sleak::String::find ( const String & str,
size_t pos = 0 ) const
inline

Definition at line 158 of file String.hpp.

◆ length()

size_t Sleak::String::length ( ) const
inline

Definition at line 102 of file String.hpp.

◆ operator+=() [1/3]

String & Sleak::String::operator+= ( char ch)
inline

Definition at line 180 of file String.hpp.

◆ operator+=() [2/3]

String & Sleak::String::operator+= ( const char * str)
inline

Definition at line 176 of file String.hpp.

◆ operator+=() [3/3]

String & Sleak::String::operator+= ( const String & other)
inline

Definition at line 172 of file String.hpp.

◆ operator=() [1/2]

String & Sleak::String::operator= ( const String & other)
inline

Definition at line 59 of file String.hpp.

◆ operator=() [2/2]

String & Sleak::String::operator= ( String && other)
inlinenoexcept

Definition at line 72 of file String.hpp.

◆ operator[]() [1/2]

char & Sleak::String::operator[] ( size_t index)
inline

Definition at line 86 of file String.hpp.

◆ operator[]() [2/2]

const char & Sleak::String::operator[] ( size_t index) const
inline

Definition at line 93 of file String.hpp.

◆ reserve()

void Sleak::String::reserve ( size_t newCapacity)
inline

Definition at line 123 of file String.hpp.

◆ resize()

void Sleak::String::resize ( size_t newSize,
char ch = '\0' )
inline

Definition at line 112 of file String.hpp.

◆ size()

size_t Sleak::String::size ( ) const
inline

Definition at line 101 of file String.hpp.

◆ substr()

String Sleak::String::substr ( size_t pos = 0,
size_t len = npos ) const
inline

Definition at line 163 of file String.hpp.

◆ operator!=

bool operator!= ( const String & lhs,
const String & rhs )
friend

Definition at line 206 of file String.hpp.

◆ operator+ [1/3]

String operator+ ( const char * lhs,
const String & rhs )
friend

Definition at line 196 of file String.hpp.

◆ operator+ [2/3]

String operator+ ( const String & lhs,
const char * rhs )
friend

Definition at line 190 of file String.hpp.

◆ operator+ [3/3]

String operator+ ( const String & lhs,
const String & rhs )
friend

Definition at line 184 of file String.hpp.

◆ operator<

bool operator< ( const String & lhs,
const String & rhs )
friend

Definition at line 210 of file String.hpp.

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const String & str )
friend

Definition at line 226 of file String.hpp.

◆ operator<=

bool operator<= ( const String & lhs,
const String & rhs )
friend

Definition at line 214 of file String.hpp.

◆ operator==

bool operator== ( const String & lhs,
const String & rhs )
friend

Definition at line 202 of file String.hpp.

◆ operator>

bool operator> ( const String & lhs,
const String & rhs )
friend

Definition at line 218 of file String.hpp.

◆ operator>=

bool operator>= ( const String & lhs,
const String & rhs )
friend

Definition at line 222 of file String.hpp.