Arduino DLNA Server
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
tiny_dlna::StrView Class Reference

A simple wrapper to provide string functions on char*. If the underlying char* is a const we do not allow any updates; The ownership of the chr* must be managed externally! More...

#include <StrView.h>

Inheritance diagram for tiny_dlna::StrView:
Inheritance graph
[legend]

Public Member Functions

 StrView ()=default
 
 StrView (const char *chars)
 Creates a StrView for string constant. More...
 
 StrView (char chars[], int maxlen, int len=0)
 Creates a StrView with the indicated buffer. More...
 
 StrView (const StrView &)=default
 
 StrView (StrView &&)=default
 
StrViewoperator= (const StrView &)=default
 
StrViewoperator= (StrView &&)=default
 
virtual void set (const char *alt)
 assigs a value More...
 
virtual void set (const StrView &alt)
 assigs from another StrView value More...
 
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 More...
 
virtual void add (int value)
 adds a int value More...
 
virtual void add (double value, int precision=2, int withd=0)
 adds a double value More...
 
virtual void add (const char *append)
 adds a string More...
 
virtual void add (const char c)
 adds a character More...
 
virtual bool equals (const char *str)
 checks if the string equals indicated parameter string More...
 
virtual bool startsWith (const char *str)
 checks if the string starts with the indicated substring More...
 
virtual bool endsWith (const char *str)
 checks if the string ends with the indicated substring More...
 
virtual bool endsWithIgnoreCase (const char *str)
 checks if the string ends with the indicated substring More...
 
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 More...
 
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 More...
 
virtual void operator= (const char *str)
 we can assign a const char* More...
 
virtual void operator= (char *str)
 we can assign a char* More...
 
virtual void operator= (char c)
 we can assign a char More...
 
virtual void operator= (double val)
 we can assign a double More...
 
virtual void operator= (int value)
 we can assign an int More...
 
virtual void operator<< (int n)
 shift characters to the right -> we just move the pointer More...
 
virtual char operator[] (int index)
 
virtual void operator+= (const char *str)
 adds a substring at the end of the string More...
 
virtual void operator+= (int value)
 adds a int at the end of the string More...
 
virtual void operator+= (double value)
 adds a double at the end of the string More...
 
virtual void operator+= (const char value)
 adds a character More...
 
virtual bool operator== (const StrView &alt) const
 checks if the indicated string is equal to the current string More...
 
virtual bool operator== (const char *alt) const
 checks if the indicated string is equal to the current string More...
 
virtual bool operator!= (const StrView &alt) const
 checks if the indicated string is different from the current string More...
 
virtual bool operator!= (const char *alt) const
 checks if the indicated string is different from the current string More...
 
virtual const char * c_str ()
 provides the string value as const char* More...
 
virtual int length ()
 
virtual bool isEmpty ()
 checks if the string is empty More...
 
virtual bool isNewLine ()
 
virtual int maxLength ()
 provides the maximum length of the string More...
 
virtual bool replace (const char *toReplace, const int replaced)
 Replaces the first instance of toReplace with replaced. More...
 
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. More...
 
virtual bool replaceAll (const char *toReplace, const char *replaced)
 Replaces all instances of toReplace with replaced. More...
 
virtual void remove (const char *toRemove)
 removes the indicated substring from the string More...
 
virtual void removeAll (const char *toRemove)
 removes the indicated substring from the string More...
 
virtual void setLength (int len, bool addZero=true)
 limits the length of the string (by adding a delimiting 0) More...
 
virtual void setLengthUndo ()
 undo the last setLength call More...
 
virtual void substring (StrView &from, int start, int end)
 copies a substring into the current string More...
 
virtual void substring (const char *from, int start, int end)
 copies a substring into the current string More...
 
virtual void trim ()
 remove leading and traling spaces More...
 
virtual int count (char c, int startPos)
 count number of indicated characters as position More...
 
virtual void ltrim ()
 remove leading spaces More...
 
virtual void rtrim ()
 remove trailing spaces More...
 
virtual void clear ()
 clears the string by setting the terminating 0 at the beginning More...
 
virtual void clearAll ()
 
virtual bool isOnHeap ()
 checks if the string is on the heap More...
 
virtual bool isConst ()
 checks if the string is a constant that must not be changed More...
 
virtual void insert (int pos, const char *str)
 inserts a substring into the string More...
 
virtual bool equalsIgnoreCase (const char *alt)
 Compares the string ignoring the case. More...
 
int toInt ()
 Converts the string to an int. More...
 
long toLong ()
 Converts the string to an long. More...
 
double toDouble ()
 Converts the string to a double. More...
 
float toFloat ()
 Converts the string to a double. More...
 
void toLowerCase ()
 Converts the string to lowercase letters. More...
 
void toUpperCase ()
 Converts the string to uppercase letters. More...
 
bool containsNumber ()
 
bool isInteger ()
 Returns true if the string is an integer. More...
 
int numberOfDecimals ()
 Determines the number of decimals in the number string. More...
 
bool isNumber ()
 
const char * buildPath (const char *start, const char *p1=nullptr, const char *p2=nullptr)
 

Static Public Member Functions

static const char * toBinary (void const *const ptr, size_t const size)
 provides a binary string represntation More...
 

Protected Member Functions

virtual bool grow (int newMaxLen)
 only supported in subclasses More...
 

Static Protected Member Functions

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)
 

Protected Attributes

char * chars = nullptr
 
bool is_const = false
 
int len = 0
 
int maxlen = 0
 
int savedLen = -1
 
char savedChar
 

Detailed Description

A simple wrapper to provide string functions on char*. If the underlying char* is a const we do not allow any updates; The ownership of the chr* must be managed externally!

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ StrView() [1/5]

tiny_dlna::StrView::StrView ( )
default

◆ StrView() [2/5]

tiny_dlna::StrView::StrView ( const char *  chars)
inline

Creates a StrView for string constant.

◆ StrView() [3/5]

tiny_dlna::StrView::StrView ( char  chars[],
int  maxlen,
int  len = 0 
)
inline

Creates a StrView with the indicated buffer.

◆ StrView() [4/5]

tiny_dlna::StrView::StrView ( const StrView )
default

◆ StrView() [5/5]

tiny_dlna::StrView::StrView ( StrView &&  )
default

Member Function Documentation

◆ add() [1/4]

virtual void tiny_dlna::StrView::add ( const char *  append)
inlinevirtual

adds a string

◆ add() [2/4]

virtual void tiny_dlna::StrView::add ( const char  c)
inlinevirtual

adds a character

◆ add() [3/4]

virtual void tiny_dlna::StrView::add ( double  value,
int  precision = 2,
int  withd = 0 
)
inlinevirtual

adds a double value

◆ add() [4/4]

virtual void tiny_dlna::StrView::add ( int  value)
inlinevirtual

adds a int value

◆ buildPath()

const char* tiny_dlna::StrView::buildPath ( const char *  start,
const char *  p1 = nullptr,
const char *  p2 = nullptr 
)
inline

◆ c_str()

virtual const char* tiny_dlna::StrView::c_str ( )
inlinevirtual

provides the string value as const char*

Reimplemented in tiny_dlna::Str.

◆ clear()

virtual void tiny_dlna::StrView::clear ( )
inlinevirtual

clears the string by setting the terminating 0 at the beginning

Reimplemented in tiny_dlna::Str.

◆ clearAll()

virtual void tiny_dlna::StrView::clearAll ( )
inlinevirtual

◆ contains()

virtual bool tiny_dlna::StrView::contains ( const char *  str)
inlinevirtual

checks if the string contains a substring

◆ containsNumber()

bool tiny_dlna::StrView::containsNumber ( )
inline

◆ count()

virtual int tiny_dlna::StrView::count ( char  c,
int  startPos 
)
inlinevirtual

count number of indicated characters as position

◆ endsWith()

virtual bool tiny_dlna::StrView::endsWith ( const char *  str)
inlinevirtual

checks if the string ends with the indicated substring

◆ endsWithIgnoreCase()

virtual bool tiny_dlna::StrView::endsWithIgnoreCase ( const char *  str)
inlinevirtual

checks if the string ends with the indicated substring

◆ equals()

virtual bool tiny_dlna::StrView::equals ( const char *  str)
inlinevirtual

checks if the string equals indicated parameter string

◆ equalsIgnoreCase()

virtual bool tiny_dlna::StrView::equalsIgnoreCase ( const char *  alt)
inlinevirtual

Compares the string ignoring the case.

◆ floatToString()

static char* tiny_dlna::StrView::floatToString ( char *  outstr,
double  val,
int  precision,
int  widthp 
)
inlinestaticprotected

compute the rounding factor and fractional multiplier

print the decimal point

generate space padding

◆ grow()

virtual bool tiny_dlna::StrView::grow ( int  newMaxLen)
inlineprotectedvirtual

only supported in subclasses

Reimplemented in tiny_dlna::Str.

◆ indexOf() [1/2]

virtual int tiny_dlna::StrView::indexOf ( const char *  cont,
int  start = 0 
)
inlinevirtual

provides the position of the the indicated substring after the indicated start position

◆ indexOf() [2/2]

virtual int tiny_dlna::StrView::indexOf ( const char  c,
int  start = 0 
)
inlinevirtual

provides the position of the the indicated character after the indicated start position

◆ insert()

virtual void tiny_dlna::StrView::insert ( int  pos,
const char *  str 
)
inlinevirtual

inserts a substring into the string

◆ isConst()

virtual bool tiny_dlna::StrView::isConst ( )
inlinevirtual

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

Reimplemented in tiny_dlna::Str.

◆ isEmpty()

virtual bool tiny_dlna::StrView::isEmpty ( )
inlinevirtual

checks if the string is empty

◆ isInteger()

bool tiny_dlna::StrView::isInteger ( )
inline

Returns true if the string is an integer.

◆ isNewLine()

virtual bool tiny_dlna::StrView::isNewLine ( )
inlinevirtual

◆ isNumber()

bool tiny_dlna::StrView::isNumber ( )
inline

◆ isOnHeap()

virtual bool tiny_dlna::StrView::isOnHeap ( )
inlinevirtual

checks if the string is on the heap

Reimplemented in tiny_dlna::Str.

◆ itoa()

static char* tiny_dlna::StrView::itoa ( int  n,
char  s[] 
)
inlinestaticprotected

◆ lastIndexOf()

virtual int tiny_dlna::StrView::lastIndexOf ( const char *  cont)
inlinevirtual

provides the position of the last occurrence of the indicated substring

◆ length()

virtual int tiny_dlna::StrView::length ( )
inlinevirtual

provides the current length (filled with characters) of the string - excluding the terminating 0

◆ ltrim()

virtual void tiny_dlna::StrView::ltrim ( )
inlinevirtual

remove leading spaces

◆ matches()

virtual bool tiny_dlna::StrView::matches ( const char *  pattern)
inlinevirtual

file matching supporting * and ? - replacing regex which is not supported in all environments

returns 1 (true) if there is a match returns 0 if the pattern is not whitin the line

the line is ended but char was expected

end of mask

if the line also ends here then the pattern match

try to restart the mask on the rest

◆ maxLength()

virtual int tiny_dlna::StrView::maxLength ( )
inlinevirtual

provides the maximum length of the string

◆ numberOfDecimals()

int tiny_dlna::StrView::numberOfDecimals ( )
inline

Determines the number of decimals in the number string.

◆ operator!=() [1/2]

virtual bool tiny_dlna::StrView::operator!= ( const char *  alt) const
inlinevirtual

checks if the indicated string is different from the current string

◆ operator!=() [2/2]

virtual bool tiny_dlna::StrView::operator!= ( const StrView alt) const
inlinevirtual

checks if the indicated string is different from the current string

◆ operator+=() [1/4]

virtual void tiny_dlna::StrView::operator+= ( const char *  str)
inlinevirtual

adds a substring at the end of the string

◆ operator+=() [2/4]

virtual void tiny_dlna::StrView::operator+= ( const char  value)
inlinevirtual

adds a character

◆ operator+=() [3/4]

virtual void tiny_dlna::StrView::operator+= ( double  value)
inlinevirtual

adds a double at the end of the string

◆ operator+=() [4/4]

virtual void tiny_dlna::StrView::operator+= ( int  value)
inlinevirtual

adds a int at the end of the string

◆ operator<<()

virtual void tiny_dlna::StrView::operator<< ( int  n)
inlinevirtual

shift characters to the right -> we just move the pointer

◆ operator=() [1/7]

virtual void tiny_dlna::StrView::operator= ( char *  str)
inlinevirtual

we can assign a char*

Reimplemented in tiny_dlna::Str.

◆ operator=() [2/7]

virtual void tiny_dlna::StrView::operator= ( char  c)
inlinevirtual

we can assign a char

◆ operator=() [3/7]

virtual void tiny_dlna::StrView::operator= ( const char *  str)
inlinevirtual

we can assign a const char*

Reimplemented in tiny_dlna::Str.

◆ operator=() [4/7]

StrView& tiny_dlna::StrView::operator= ( const StrView )
default

◆ operator=() [5/7]

virtual void tiny_dlna::StrView::operator= ( double  val)
inlinevirtual

we can assign a double

Reimplemented in tiny_dlna::Str.

◆ operator=() [6/7]

virtual void tiny_dlna::StrView::operator= ( int  value)
inlinevirtual

we can assign an int

Reimplemented in tiny_dlna::Str.

◆ operator=() [7/7]

StrView& tiny_dlna::StrView::operator= ( StrView &&  )
default

◆ operator==() [1/2]

virtual bool tiny_dlna::StrView::operator== ( const char *  alt) const
inlinevirtual

checks if the indicated string is equal to the current string

◆ operator==() [2/2]

virtual bool tiny_dlna::StrView::operator== ( const StrView alt) const
inlinevirtual

checks if the indicated string is equal to the current string

◆ operator[]()

virtual char tiny_dlna::StrView::operator[] ( int  index)
inlinevirtual

◆ remove()

virtual void tiny_dlna::StrView::remove ( const char *  toRemove)
inlinevirtual

removes the indicated substring from the string

◆ removeAll()

virtual void tiny_dlna::StrView::removeAll ( const char *  toRemove)
inlinevirtual

removes the indicated substring from the string

◆ replace() [1/3]

virtual bool tiny_dlna::StrView::replace ( const char *  toReplace,
const char *  replaced 
)
inlinevirtual

Replaces the first instance of toReplace with replaced.

◆ replace() [2/3]

virtual bool tiny_dlna::StrView::replace ( const char *  toReplace,
const float  replaced 
)
inlinevirtual

◆ replace() [3/3]

virtual bool tiny_dlna::StrView::replace ( const char *  toReplace,
const int  replaced 
)
inlinevirtual

Replaces the first instance of toReplace with replaced.

◆ replaceAll()

virtual bool tiny_dlna::StrView::replaceAll ( const char *  toReplace,
const char *  replaced 
)
inlinevirtual

Replaces all instances of toReplace with replaced.

◆ reverse()

static void tiny_dlna::StrView::reverse ( char  s[])
inlinestaticprotected

◆ rtrim()

virtual void tiny_dlna::StrView::rtrim ( )
inlinevirtual

remove trailing spaces

◆ set() [1/6]

virtual void tiny_dlna::StrView::set ( char  chars[],
int  maxlen,
int  len = 0,
bool  isConst = false 
)
inlinevirtual

assigns a memory buffer

◆ set() [2/6]

virtual void tiny_dlna::StrView::set ( const char *  alt)
inlinevirtual

assigs a value

if the StrView is a const we replace the pointer

if the StrView is an external buffer we need to copy

◆ set() [3/6]

virtual void tiny_dlna::StrView::set ( const char  c)
inlinevirtual

◆ set() [4/6]

virtual void tiny_dlna::StrView::set ( const StrView alt)
inlinevirtual

assigs from another StrView value

if the StrView is a const we replace the pointer

if the StrView is an external buffer we need to copy

◆ set() [5/6]

virtual void tiny_dlna::StrView::set ( double  value,
int  precision = 2,
int  withd = 0 
)
inlinevirtual

◆ set() [6/6]

virtual void tiny_dlna::StrView::set ( int  value)
inlinevirtual

◆ setLength()

virtual void tiny_dlna::StrView::setLength ( int  len,
bool  addZero = true 
)
inlinevirtual

limits the length of the string (by adding a delimiting 0)

◆ setLengthUndo()

virtual void tiny_dlna::StrView::setLengthUndo ( )
inlinevirtual

undo the last setLength call

◆ startsWith()

virtual bool tiny_dlna::StrView::startsWith ( const char *  str)
inlinevirtual

checks if the string starts with the indicated substring

◆ strncmp_i()

static int tiny_dlna::StrView::strncmp_i ( const char *  s1,
const char *  s2,
int  n 
)
inlinestaticprotected

◆ substring() [1/2]

virtual void tiny_dlna::StrView::substring ( const char *  from,
int  start,
int  end 
)
inlinevirtual

copies a substring into the current string

◆ substring() [2/2]

virtual void tiny_dlna::StrView::substring ( StrView from,
int  start,
int  end 
)
inlinevirtual

copies a substring into the current string

◆ swap()

virtual void tiny_dlna::StrView::swap ( StrView str)
inlinevirtual

◆ toBinary()

static const char* tiny_dlna::StrView::toBinary ( void const *const  ptr,
size_t const  size 
)
inlinestatic

provides a binary string represntation

◆ toDouble()

double tiny_dlna::StrView::toDouble ( )
inline

Converts the string to a double.

◆ toFloat()

float tiny_dlna::StrView::toFloat ( )
inline

Converts the string to a double.

◆ toInt()

int tiny_dlna::StrView::toInt ( )
inline

Converts the string to an int.

◆ toLong()

long tiny_dlna::StrView::toLong ( )
inline

Converts the string to an long.

◆ toLowerCase()

void tiny_dlna::StrView::toLowerCase ( )
inline

Converts the string to lowercase letters.

◆ toUpperCase()

void tiny_dlna::StrView::toUpperCase ( )
inline

Converts the string to uppercase letters.

◆ trim()

virtual void tiny_dlna::StrView::trim ( )
inlinevirtual

remove leading and traling spaces

Member Data Documentation

◆ chars

char* tiny_dlna::StrView::chars = nullptr
protected

◆ is_const

bool tiny_dlna::StrView::is_const = false
protected

◆ len

int tiny_dlna::StrView::len = 0
protected

◆ maxlen

int tiny_dlna::StrView::maxlen = 0
protected

◆ savedChar

char tiny_dlna::StrView::savedChar
protected

◆ savedLen

int tiny_dlna::StrView::savedLen = -1
protected

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