Arduino DLNA Server
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tiny_dlna::Str Class Reference

String implementation which keeps the data on the heap. We grow the allocated memory only if the copy source is not fitting. More...

#include <Str.h>

Inheritance diagram for tiny_dlna::Str:
Inheritance graph
[legend]
Collaboration diagram for tiny_dlna::Str:
Collaboration graph
[legend]

Public Member Functions

 Str (int initialAllocatedLength=0)
 
 Str (const char *str)
 
 Str (StrView &source)
 Convert StrView to Str.
 
 Str (Str &source)
 Copy constructor.
 
 Str (Str &&obj)
 Move constructor.
 
 ~Str ()
 Destructor.
 
Stroperator= (Str &&obj)
 Move assignment.
 
Stroperator= (Str &obj)
 Copy assingment.
 
bool isOnHeap () override
 checks if the string is on the heap
 
bool isConst () override
 checks if the string is a constant that must not be changed
 
void operator= (const char *str) override
 we can assign a const char*
 
void operator= (char *str) override
 we can assign a char*
 
void operator= (int v) override
 we can assign an int
 
void operator= (double v) override
 we can assign a double
 
size_t capacity ()
 
void setCapacity (size_t newLen)
 
void allocate (int len=-1)
 
void copyFrom (const char *source, int len, int maxlen=0)
 assigns a memory buffer
 
void setChars (char c, int len)
 Fills the string with len chars.
 
void urlEncode ()
 url encode the string
 
void urlDecode ()
 decodes a url encoded string
 
void clear () override
 clears the string by setting the terminating 0 at the beginning
 
void resize (int size)
 
void swap (Str &other)
 
const char * c_str ()
 provides the string value as const char*
 
void reset ()
 
Str substring (int start, int end)
 copies a substring into the current string
 
void remove (int n)
 removes the first n characters
 
- Public Member Functions inherited from tiny_dlna::StrView
 StrView ()=default
 
 StrView (const char *chars)
 Creates a StrView for string constant.
 
 StrView (char chars[], int maxlen, int len=0)
 Creates a StrView with the indicated buffer.
 
 StrView (const StrView &)=default
 
 StrView (StrView &&)=default
 
StrViewoperator= (const StrView &)=default
 
StrViewoperator= (StrView &&)=default
 
virtual void set (const char *alt)
 assigs a value
 
virtual void set (const StrView &alt)
 assigs from another StrView value
 
virtual void set (const char c)
 
virtual void set (int value)
 
virtual void set (double value, int precision=2, int withd=0)
 
virtual void swap (StrView &str)
 
virtual void set (char chars[], int maxlen, int len=0, bool isConst=false)
 assigns a memory buffer
 
virtual void add (int value)
 adds a int value
 
virtual void add (double value, int precision=2, int withd=0)
 adds a double value
 
virtual void add (const char *append)
 adds a string
 
virtual void add (const uint8_t *append, int len)
 
virtual void add (const char c)
 adds a character
 
virtual bool equals (const char *str)
 checks if the string equals indicated parameter string
 
virtual bool startsWith (const char *str)
 checks if the string starts with the indicated substring
 
virtual bool endsWith (const char *str)
 checks if the string ends with the indicated substring
 
virtual bool endsWithIgnoreCase (const char *str)
 checks if the string ends with the indicated substring
 
virtual bool matches (const char *pattern)
 
virtual int indexOf (const char c, int start=0)
 
virtual bool contains (const char *str)
 checks if the string contains a substring
 
virtual int indexOf (const char *cont, int start=0)
 
virtual int lastIndexOf (const char *cont)
 provides the position of the last occurrence of the indicated substring
 
virtual void operator= (const char *str)
 we can assign a const char*
 
virtual void operator= (char *str)
 we can assign a char*
 
virtual void operator= (char c)
 we can assign a char
 
virtual void operator= (double val)
 we can assign a double
 
virtual void operator= (int value)
 we can assign an int
 
virtual void operator<< (int n)
 shift characters to the right -> we just move the pointer
 
virtual char operator[] (int index)
 
virtual void operator+= (const char *str)
 adds a substring at the end of the string
 
virtual void operator+= (int value)
 adds a int at the end of the string
 
virtual void operator+= (double value)
 adds a double at the end of the string
 
virtual void operator+= (const char value)
 adds a character
 
virtual bool operator== (const StrView &alt) const
 checks if the indicated string is equal to the current string
 
virtual bool operator== (const char *alt) const
 checks if the indicated string is equal to the current string
 
virtual bool operator!= (const StrView &alt) const
 checks if the indicated string is different from the current string
 
virtual bool operator!= (const char *alt) const
 checks if the indicated string is different from the current string
 
virtual const char * c_str ()
 provides the string value as const char*
 
virtual int length ()
 
virtual bool isEmpty ()
 checks if the string is empty
 
virtual bool isNewLine ()
 
virtual int maxLength ()
 provides the maximum length of the string
 
virtual bool replace (const char *toReplace, const int replaced)
 Replaces the first instance of toReplace with replaced.
 
virtual bool replace (const char *toReplace, const float replaced)
 
virtual bool replace (const char *toReplace, const char *replaced)
 Replaces the first instance of toReplace with replaced.
 
virtual bool replaceAll (const char *toReplace, const char *replaced)
 Replaces all instances of toReplace with replaced.
 
virtual void remove (const char *toRemove)
 removes the indicated substring from the string
 
virtual void removeAll (const char *toRemove)
 removes the indicated substring from the string
 
virtual void setLength (int len, bool addZero=true)
 limits the length of the string (by adding a delimiting 0)
 
virtual void setLengthUndo ()
 undo the last setLength call
 
virtual void substrView (StrView &from, int start, int end)
 copies a substring into the current string
 
virtual void substrView (const char *from, int start, int end)
 copies a substring into the current string
 
virtual void trim ()
 remove leading and traling spaces
 
virtual int count (char c, int startPos)
 count number of indicated characters as position
 
virtual void ltrim ()
 remove leading spaces
 
virtual void rtrim ()
 remove trailing spaces
 
virtual void clear ()
 clears the string by setting the terminating 0 at the beginning
 
virtual void clearAll ()
 
virtual bool isOnHeap ()
 checks if the string is on the heap
 
virtual bool isConst ()
 checks if the string is a constant that must not be changed
 
virtual void insert (int pos, const char *str)
 inserts a substring into the string
 
virtual bool equalsIgnoreCase (const char *alt)
 Compares the string ignoring the case.
 
int toInt ()
 Converts the string to an int.
 
long toLong ()
 Converts the string to an long.
 
double toDouble ()
 Converts the string to a double.
 
float toFloat ()
 Converts the string to a double.
 
void toLowerCase ()
 Converts the string to lowercase letters.
 
void toUpperCase ()
 Converts the string to uppercase letters.
 
bool containsNumber ()
 
bool isInteger ()
 Returns true if the string is an integer.
 
int numberOfDecimals ()
 Determines the number of decimals in the number string.
 
bool isNumber ()
 
const char * buildPath (const char *start, const char *p1=nullptr, const char *p2=nullptr)
 

Protected Member Functions

Strmove (Str &other)
 
bool grow (int newMaxLen) override
 only supported in subclasses
 
void urlEncodeChar (char c, char *result, int maxLen)
 
char charToInt (char ch)
 
char strToBin (char *pString)
 
virtual bool grow (int newMaxLen)
 only supported in subclasses
 

Protected Attributes

Vector< char > vector {0}
 
- Protected Attributes inherited from tiny_dlna::StrView
char * chars = nullptr
 
bool is_const = true
 
int len = 0
 
int maxlen = 0
 
int savedLen = -1
 
char savedChar
 

Additional Inherited Members

- Static Public Member Functions inherited from tiny_dlna::StrView
static const char * toBinary (void const *const ptr, size_t const size)
 provides a binary string represntation
 
- Static Protected Member Functions inherited from tiny_dlna::StrView
static char * itoa (int n, char s[])
 
static void reverse (char s[])
 
static char * floatToString (char *outstr, double val, int precision, int widthp)
 
static int strncmp_i (const char *s1, const char *s2, int n)
 

Detailed Description

String implementation which keeps the data on the heap. We grow the allocated memory only if the copy source is not fitting.

While it should be avoided to use a lot of heap allocatioins in embedded devices it is sometimes more convinent to allocate a string once on the heap and have the insurance that it might grow if we need to process an unexpected size.

We also need to use this if we want to manage a vecor of strings.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ Str() [1/5]

tiny_dlna::Str::Str ( int  initialAllocatedLength = 0)
inline

◆ Str() [2/5]

tiny_dlna::Str::Str ( const char *  str)
inline

◆ Str() [3/5]

tiny_dlna::Str::Str ( StrView source)
inline

Convert StrView to Str.

◆ Str() [4/5]

tiny_dlna::Str::Str ( Str source)
inline

Copy constructor.

◆ Str() [5/5]

tiny_dlna::Str::Str ( Str &&  obj)
inline

Move constructor.

◆ ~Str()

tiny_dlna::Str::~Str ( )
inline

Destructor.

Member Function Documentation

◆ allocate()

void tiny_dlna::Str::allocate ( int  len = -1)
inline

◆ c_str()

const char * tiny_dlna::Str::c_str ( )
inlinevirtual

provides the string value as const char*

Reimplemented from tiny_dlna::StrView.

◆ capacity()

size_t tiny_dlna::Str::capacity ( )
inline

◆ charToInt()

char tiny_dlna::Str::charToInt ( char  ch)
inlineprotected

◆ clear()

void tiny_dlna::Str::clear ( )
inlineoverridevirtual

clears the string by setting the terminating 0 at the beginning

Reimplemented from tiny_dlna::StrView.

◆ copyFrom()

void tiny_dlna::Str::copyFrom ( const char *  source,
int  len,
int  maxlen = 0 
)
inline

assigns a memory buffer

◆ grow()

bool tiny_dlna::Str::grow ( int  newMaxLen)
inlineoverrideprotectedvirtual

only supported in subclasses

Reimplemented from tiny_dlna::StrView.

◆ isConst()

bool tiny_dlna::Str::isConst ( )
inlineoverridevirtual

checks if the string is a constant that must not be changed

Reimplemented from tiny_dlna::StrView.

◆ isOnHeap()

bool tiny_dlna::Str::isOnHeap ( )
inlineoverridevirtual

checks if the string is on the heap

Reimplemented from tiny_dlna::StrView.

◆ move()

Str & tiny_dlna::Str::move ( Str other)
inlineprotected

◆ operator=() [1/6]

void tiny_dlna::Str::operator= ( char *  str)
inlineoverridevirtual

we can assign a char*

Reimplemented from tiny_dlna::StrView.

◆ operator=() [2/6]

void tiny_dlna::Str::operator= ( const char *  str)
inlineoverridevirtual

we can assign a const char*

Reimplemented from tiny_dlna::StrView.

◆ operator=() [3/6]

void tiny_dlna::Str::operator= ( double  val)
inlineoverridevirtual

we can assign a double

Reimplemented from tiny_dlna::StrView.

◆ operator=() [4/6]

void tiny_dlna::Str::operator= ( int  value)
inlineoverridevirtual

we can assign an int

Reimplemented from tiny_dlna::StrView.

◆ operator=() [5/6]

Str & tiny_dlna::Str::operator= ( Str &&  obj)
inline

Move assignment.

◆ operator=() [6/6]

Str & tiny_dlna::Str::operator= ( Str obj)
inline

Copy assingment.

◆ remove()

void tiny_dlna::Str::remove ( int  n)
inline

removes the first n characters

◆ reset()

void tiny_dlna::Str::reset ( )
inline

◆ resize()

void tiny_dlna::Str::resize ( int  size)
inline

◆ setCapacity()

void tiny_dlna::Str::setCapacity ( size_t  newLen)
inline

◆ setChars()

void tiny_dlna::Str::setChars ( char  c,
int  len 
)
inline

Fills the string with len chars.

◆ strToBin()

char tiny_dlna::Str::strToBin ( char *  pString)
inlineprotected

◆ substring()

Str tiny_dlna::Str::substring ( int  start,
int  end 
)
inline

copies a substring into the current string

◆ swap()

void tiny_dlna::Str::swap ( Str other)
inline

◆ urlDecode()

void tiny_dlna::Str::urlDecode ( )
inline

decodes a url encoded string

◆ urlEncode()

void tiny_dlna::Str::urlEncode ( )
inline

url encode the string

◆ urlEncodeChar()

void tiny_dlna::Str::urlEncodeChar ( char  c,
char *  result,
int  maxLen 
)
inlineprotected

Member Data Documentation

◆ vector

Vector<char> tiny_dlna::Str::vector {0}
protected

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