arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
audio_tools::Str 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 <Str.h>

Inheritance diagram for audio_tools::Str:
audio_tools::StrExt

Public Member Functions

 Str (char chars[], int maxlen, int len=0)
 Creates a Str with the indicated buffer.
 
 Str (const char *chars)
 Creates a Str for string constant.
 
 Str (const Str &)=default
 
 Str (Str &&)=default
 
virtual void add (const char *append)
 adds a string
 
virtual void add (const char c)
 adds a character
 
virtual void add (double value, int precision=2, int withd=0)
 adds a double value
 
virtual void add (int value)
 adds a int value
 
virtual const char * c_str ()
 provides the string value as const char*
 
virtual void clear ()
 clears the string by setting the terminating 0 at the beginning
 
virtual bool contains (const char *str)
 checks if the string contains a substring
 
bool containsNumber ()
 
virtual int count (char c, int startPos)
 count number of indicated characters as position
 
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 equals (const char *str)
 checks if the string equals indicated parameter string
 
virtual bool equalsIgnoreCase (const char *alt)
 Compares the string ignoring the case.
 
virtual int indexOf (const char *cont, int start=0)
 provides the position of the the indicated substring after the indicated start position
 
virtual int indexOf (const char c, int start=0)
 provides the position of the the indicated character after the indicated start position
 
virtual void insert (int pos, const char *str)
 inserts a substring into the string
 
virtual bool isConst ()
 checks if the string is a constant that must not be changed More...
 
virtual bool isEmpty ()
 checks if the string is empty
 
bool isInteger ()
 Returns true if the string is an integer.
 
bool isNumber ()
 
virtual bool isOnHeap ()
 checks if the string is on the heap More...
 
virtual int lastIndexOf (const char *cont)
 provides the position of the last occurrence of the indicated substring
 
virtual int length ()
 provides the current length (filled with characters) of the string - excluding the terminating 0
 
virtual void ltrim ()
 remove leading spaces
 
virtual bool matches (const char *pattern)
 file matching supporting * and ? - replacing regex which is not supported in all environments More...
 
virtual int maxLength ()
 provides the maximum length of the string
 
int numberOfDecimals ()
 Determines the number of decimals in the number string.
 
virtual bool operator!= (const char *alt) const
 checks if the indicated string is different from the current string
 
virtual bool operator!= (const Str &alt) const
 checks if the indicated string is different from the current string
 
virtual void operator+= (const char *str)
 adds a substring at the end of the string
 
virtual void operator+= (const char value)
 adds a character
 
virtual void operator+= (double value)
 adds a double at the end of the string
 
virtual void operator+= (int value)
 adds a int at the end of the string
 
virtual void operator<< (int n)
 shift characters to the right -> we just move the pointer
 
virtual void operator= (char *str)
 we can assign a char* More...
 
virtual void operator= (char c)
 we can assign a char
 
virtual void operator= (const char *str)
 we can assign a const char* More...
 
Stroperator= (const Str &)=default
 
virtual void operator= (double val)
 we can assign a double More...
 
virtual void operator= (int value)
 we can assign an int More...
 
Stroperator= (Str &&)=default
 
virtual bool operator== (const char *alt) const
 checks if the indicated string is equal to the current string
 
virtual bool operator== (const Str &alt) const
 checks if the indicated string is equal to the current string
 
virtual char operator[] (int index)
 
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 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 rtrim ()
 remove trailing spaces
 
virtual void set (char chars[], int maxlen, int len=0, bool isConst=false)
 assigns a memory buffer
 
virtual void set (const char *alt)
 assigs a value More...
 
virtual void set (const char c)
 
virtual void set (const Str &alt)
 assigs from another Str value More...
 
virtual void set (double value, int precision=2, int withd=0)
 
virtual void set (int value)
 
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 bool startsWith (const char *str)
 checks if the string starts with the indicated substring
 
virtual void substring (const char *from, int start, int end)
 copies a substring into the current string
 
virtual void substring (Str &from, int start, int end)
 copies a substring into the current string
 
virtual void swap (Str &str)
 
double toDouble ()
 Converts the string to a double.
 
int toInt ()
 Converts the string to an int.
 
long toLong ()
 Converts the string to an long.
 
void toLowerCase ()
 Converts the string to lowercase letters.
 
void toUpperCase ()
 Converts the string to uppercase letters.
 
virtual void trim ()
 remove leading and traling spaces
 

Static Public Member Functions

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

Protected Member Functions

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

Static Protected Member Functions

static char * floatToString (char *outstr, double val, int precision, int widthp)
 
static char * itoa (int n, char s[])
 
static void reverse (char s[])
 
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
 
char savedChar
 
int savedLen = -1
 

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

Member Function Documentation

◆ floatToString()

static char * audio_tools::Str::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 audio_tools::Str::grow ( int  newMaxLen)
inlineprotectedvirtual

only supported in subclasses

Reimplemented in audio_tools::StrExt.

◆ isConst()

virtual bool audio_tools::Str::isConst ( )
inlinevirtual

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

Reimplemented in audio_tools::StrExt.

◆ isOnHeap()

virtual bool audio_tools::Str::isOnHeap ( )
inlinevirtual

checks if the string is on the heap

Reimplemented in audio_tools::StrExt.

◆ matches()

virtual bool audio_tools::Str::matches ( const char *  pattern)
inlinevirtual

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

virtual bool matches(const char* match){ int m_size = strlen(match); if (length() < m_size) return false; if (strncmp(this->chars,match,m_size-1)!=0) return false; if (match[m_size-1]=='*' || match[m_size-1]==this->chars[m_size-1] ){ return true; } return false; }

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

◆ operator=() [1/4]

virtual void audio_tools::Str::operator= ( char *  str)
inlinevirtual

we can assign a char*

Reimplemented in audio_tools::StrExt.

◆ operator=() [2/4]

virtual void audio_tools::Str::operator= ( const char *  str)
inlinevirtual

we can assign a const char*

Reimplemented in audio_tools::StrExt.

◆ operator=() [3/4]

virtual void audio_tools::Str::operator= ( double  val)
inlinevirtual

we can assign a double

Reimplemented in audio_tools::StrExt.

◆ operator=() [4/4]

virtual void audio_tools::Str::operator= ( int  value)
inlinevirtual

we can assign an int

Reimplemented in audio_tools::StrExt.

◆ set() [1/2]

virtual void audio_tools::Str::set ( const char *  alt)
inlinevirtual

assigs a value

if the Str is a const we replace the pointer

if the Str is an external buffer we need to copy

◆ set() [2/2]

virtual void audio_tools::Str::set ( const Str alt)
inlinevirtual

assigs from another Str value

if the Str is a const we replace the pointer

if the Str is an external buffer we need to copy


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