CoreComponents 3.0.0
A Modern C++ Toolkit
Loading...
Searching...
No Matches
String Processing

String processing, number parsing and number formatting More...

Collaboration diagram for String Processing:

Classes

class  Casefree< String >
 Case-insensitive string comparism. More...
 
class  Prefix
 String prefix More...
 
class  String
 String of characters More...
 
class  TextError
 Text error More...
 

Macros

#define CC_XSTR(x)   CC_STR(x)
 Translate a macro expression into a C string.
 

Functions

Format fout (const String &pattern="")
 Generate formatted text on the standard output stream.
 
Format ferr (const String &pattern="")
 Generate formatted text on the standard error stream.
 
template<class T >
commonPrefix (const T &a, const T &b)
 Determine the common prefix between a and b.
 

Character Functions

template<class T >
toLower (T ch)
 Convert character ch to the corresponding lower-case character.
 
template<class T >
toUpper (T ch)
 Convert character ch to the corresponding upper-case character.
 
template<class T >
bool isLower (T ch)
 Check if ch is a lower-case character.
 
template<class T >
bool isUpper (T ch)
 Check if ch is an upper-case character.
 
template<class T >
bool isSpace (T ch)
 Check if ch is a space character.
 

Text Input Functions

long scanToken (const String &text, Out< String > token, const char *lt=" \t\n", long i0=0, long i1=-1)
 Scan for a sub-string up to a lexical termination
 
bool offsetToLinePos (const String &text, long offset, Out< long > line=None{}, Out< long > pos=None{})
 Map byte offset to editor coordinates
 
bool linePosToOffset (const String &text, long line, long pos, Out< long > offset=None{})
 Map editor coordinates to byte offset
 
String escape (const String &text)
 Replace all non-printable and non-ASCII characters in text by escape sequences.
 
String normalize (const String &text, bool nameCase=true)
 Common user input normalization.
 
String xmlEscape (const String &text)
 Escape all XML tags an entities in text.
 
String xmlSanitize (const String &text)
 Remove all XML tags and entities in text.
 

Number Formatting Functions

template<class T >
String inum (T x, int base=10, int n=-1)
 Convert an integer value to string.
 
template<class T >
String dec (T x, int n=-1)
 Convert an integer to a decimal string.
 
template<class T >
String hex (T x, int n=-1)
 Convert an integer to a hexadecimal string.
 
String hex (const Bytes &data, char a='A')
 Convert data to hexadecimal.
 
Bytes readHex (const String &hex)
 Convert hexadecimal literal hex to a byte array.
 
String hex (const String &data, char a='A')
 Convert data to hexadecimal.
 
template<class T >
String oct (T x, int n=-1)
 Convert an integer to an octal string.
 
template<class T >
String bin (T x, int n=-1)
 Convert an integer to a binary string.
 
String fnum (double x, int precision=16, int base=10, int screen=6)
 Convert a floating-point number to string.
 
String fixed (double x, int nf)
 Convert a floating point number to a fixed point notation string.
 
String fixed (double x, int ni, int nf)
 Convert a floating point number to a fixed point notation string.
 
String sci (float x, int precision=8)
 Convert a floating point number to a exponential notation string.
 
String sci (double x, int precision=17)
 Convert a floating point number to a exponential notation string.
 
String dec (float x, int precision=8)
 Convert a floating point number to decimal string.
 
String dec (double x, int precision=17)
 Convert a floating point number to decimal string.
 

Default Stringification Functions

String str (const String &x)
 Convert x to string.
 
String str (const char *x)
 Convert x to string.
 
String str (char *x)
 Convert x to string.
 
String str (bool x)
 Convert x to string.
 
String str (const void *x)
 Convert x to string.
 
String str (char x)
 Convert x to string.
 
String str (char32_t ch)
 Convert an unicode character to a string.
 
String str (unsigned char x)
 Convert x to string.
 
String str (unsigned short x)
 Convert x to string.
 
String str (unsigned int x)
 Convert x to string.
 
String str (unsigned long x)
 Convert x to string.
 
String str (unsigned long long x)
 Convert x to string.
 
String str (short x)
 Convert x to string.
 
String str (int x)
 Convert x to string.
 
String str (long x)
 Convert x to string.
 
String str (long long x)
 Convert x to string.
 
String str (float x)
 Convert x to string.
 
String str (double x)
 Convert x to string.
 
template<class T >
String str (const List< T > &list)
 Convert list to string.
 
template<class K , class T , class O >
String str (const Map< K, T, O > &map)
 Convert map to string.
 
template<class K , class T , class O >
String str (const MultiMap< K, T, O > &map)
 Convert map to string.
 
template<class T , class O >
String str (const Set< T, O > &set)
 Convert set to string.
 
template<class T , class O >
String str (const MultiSet< T, O > &set)
 Convert set to string.
 
String str (const Range &range)
 Convert range to string.
 
template<class T , unsigned j, unsigned i = j>
String str (const Bit< T, j, i > &bit)
 

Detailed Description

String processing, number parsing and number formatting

Macro Definition Documentation

◆ CC_XSTR

#define CC_XSTR ( x)    CC_STR(x)

Translate a macro expression into a C string.

Function Documentation

◆ toLower()

template<class T >
T toLower ( T ch)

Convert character ch to the corresponding lower-case character.

Template Parameters
TCharacter type

◆ scanToken()

long scanToken ( const String & text,
Out< String > token,
const char * lt = " \t\n",
long i0 = 0,
long i1 = -1 )

Scan for a sub-string up to a lexical termination

Parameters
textInput text
tokenReturn the scanned sub-string
ltSet of lexical termination characters
i0Begin of range to scan (index of first character)
i1End of range to scan (index behind the last charater)
Returns
Final scan position

◆ fout()

Format fout ( const String & pattern = "")

Generate formatted text on the standard output stream.

◆ ferr()

Format ferr ( const String & pattern = "")

Generate formatted text on the standard error stream.

◆ inum()

template<class T >
String inum ( T x,
int base = 10,
int n = -1 )

Convert an integer value to string.

Template Parameters
TInteger type
Parameters
xInteger value
baseNumber base (2..62)
nMaximum number of digits
Returns
Text representation of x

◆ str() [1/24]

String str ( const String & x)

Convert x to string.

◆ commonPrefix()

template<class T >
T commonPrefix ( const T & a,
const T & b )

Determine the common prefix between a and b.

◆ toUpper()

template<class T >
T toUpper ( T ch)

Convert character ch to the corresponding upper-case character.

Template Parameters
TCharacter type

◆ isLower()

template<class T >
bool isLower ( T ch)

Check if ch is a lower-case character.

◆ isUpper()

template<class T >
bool isUpper ( T ch)

Check if ch is an upper-case character.

◆ isSpace()

template<class T >
bool isSpace ( T ch)

Check if ch is a space character.

◆ offsetToLinePos()

bool offsetToLinePos ( const String & text,
long offset,
Out< long > line = None{},
Out< long > pos = None{} )

Map byte offset to editor coordinates

Parameters
textText to scan
offsetGlobal byte offset
lineReturns the line number (starting with 1)
posReturns the byte offset on the target line (starting with 0)
Returns
True if offset is within range

◆ linePosToOffset()

bool linePosToOffset ( const String & text,
long line,
long pos,
Out< long > offset = None{} )

Map editor coordinates to byte offset

Parameters
textText to scan
lineLine number (starting with 1)
posCharacter offset on the line (starting with 0)
offsetRetunrs the global byte offset
Returns
True if successful

◆ escape()

String escape ( const String & text)

Replace all non-printable and non-ASCII characters in text by escape sequences.

◆ normalize()

String normalize ( const String & text,
bool nameCase = true )

Common user input normalization.

Parameters
textInput text
nameCaseMake sure the first character is upper case
Returns
Normalized input text

◆ xmlEscape()

String xmlEscape ( const String & text)

Escape all XML tags an entities in text.

◆ xmlSanitize()

String xmlSanitize ( const String & text)

Remove all XML tags and entities in text.

◆ dec() [1/3]

template<class T >
String dec ( T x,
int n = -1 )

Convert an integer to a decimal string.

Parameters
xInteger value
nNumber of digits
Returns
Text representation of x

◆ hex() [1/3]

template<class T >
String hex ( T x,
int n = -1 )

Convert an integer to a hexadecimal string.

Parameters
xInteger value
nNumber of digits
Returns
Text representation of x

◆ hex() [2/3]

String hex ( const Bytes & data,
char a = 'A' )

Convert data to hexadecimal.

Todo
Introduce Byte->Array<uint8_t> and move this function to Bytes::hex()

◆ readHex()

Bytes readHex ( const String & hex)

Convert hexadecimal literal hex to a byte array.

◆ hex() [3/3]

String hex ( const String & data,
char a = 'A' )

Convert data to hexadecimal.

◆ oct()

template<class T >
String oct ( T x,
int n = -1 )

Convert an integer to an octal string.

Parameters
xInteger value
nNumber of digits
Returns
Text representation of x

◆ bin()

template<class T >
String bin ( T x,
int n = -1 )

Convert an integer to a binary string.

Parameters
xInteger value
nNumber of digits
Returns
Text representation of x

◆ fnum()

String fnum ( double x,
int precision = 16,
int base = 10,
int screen = 6 )

Convert a floating-point number to string.

Parameters
xFloating-point value
precisionNumber of significiant digits
baseNumber base (2..62)
screenMaximum absolute exponent for choosing a non-exponential notation
Returns
Text representation of x
Todo
make use of frexp
Todo
make use of frexp

◆ fixed() [1/2]

String fixed ( double x,
int nf )

Convert a floating point number to a fixed point notation string.

Parameters
xFloating point value
nfNumber of fractional digits
Returns
Text representation of x

◆ fixed() [2/2]

String fixed ( double x,
int ni,
int nf )

Convert a floating point number to a fixed point notation string.

Parameters
xFloating point value
niNumber of integral digits
nfNumber of fractional digits
Returns
Text representation of x

◆ sci() [1/2]

String sci ( float x,
int precision = 8 )

Convert a floating point number to a exponential notation string.

Parameters
xInteger value
precisionNumber of significiant digits
Returns
Text representation of x

◆ sci() [2/2]

String sci ( double x,
int precision = 17 )

Convert a floating point number to a exponential notation string.

Parameters
xInteger value
precisionNumber of significiant digits
Returns
Text representation of x

◆ dec() [2/3]

String dec ( float x,
int precision = 8 )

Convert a floating point number to decimal string.

Parameters
xFloating point number
precisionNumber of significiant digits
Returns
Text representation of x

◆ dec() [3/3]

String dec ( double x,
int precision = 17 )

Convert a floating point number to decimal string.

Parameters
xFloating point number
precisionNumber of significiant digits
Returns
Text representation of x

◆ str() [2/24]

String str ( const char * x)

Convert x to string.

◆ str() [3/24]

String str ( char * x)

Convert x to string.

◆ str() [4/24]

String str ( bool x)

Convert x to string.

◆ str() [5/24]

String str ( const void * x)

Convert x to string.

◆ str() [6/24]

String str ( char x)

Convert x to string.

◆ str() [7/24]

String str ( char32_t ch)

Convert an unicode character to a string.

◆ str() [8/24]

String str ( unsigned char x)

Convert x to string.

◆ str() [9/24]

String str ( unsigned short x)

Convert x to string.

◆ str() [10/24]

String str ( unsigned int x)

Convert x to string.

◆ str() [11/24]

String str ( unsigned long x)

Convert x to string.

◆ str() [12/24]

String str ( unsigned long long x)

Convert x to string.

◆ str() [13/24]

String str ( short x)

Convert x to string.

◆ str() [14/24]

String str ( int x)

Convert x to string.

◆ str() [15/24]

String str ( long x)

Convert x to string.

◆ str() [16/24]

String str ( long long x)

Convert x to string.

◆ str() [17/24]

String str ( float x)

Convert x to string.

◆ str() [18/24]

String str ( double x)

Convert x to string.

◆ str() [19/24]

template<class T >
String str ( const List< T > & list)

Convert list to string.

◆ str() [20/24]

template<class K , class T , class O >
String str ( const Map< K, T, O > & map)

Convert map to string.

◆ str() [21/24]

template<class K , class T , class O >
String str ( const MultiMap< K, T, O > & map)

Convert map to string.

◆ str() [22/24]

template<class T , class O >
String str ( const Set< T, O > & set)

Convert set to string.

◆ str() [23/24]

template<class T , class O >
String str ( const MultiSet< T, O > & set)

Convert set to string.

◆ str() [24/24]

String str ( const Range & range)

Convert range to string.