L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
cxx::String Class Reference

Allocation free string class with explicit length field. More...

#include <string>

Inheritance diagram for cxx::String:
Collaboration diagram for cxx::String:

Public Types

typedef char const * Index
 Character index type.

Public Member Functions

 String (char const *s) noexcept
 Initialize from a zero-terminated string.
 String (char const *s, unsigned long len) noexcept
 Initialize from a pointer to first character and a length.
 String (char const *s, char const *e) noexcept
 Initialize with start and end pointer.
 String ()
 Zero-initialize. Create an invalid string.
Index start () const
 Pointer to first character.
Index end () const
 Pointer to first byte behind the string.
int len () const
 Length.
void start (char const *s)
 Set start.
void len (unsigned long len)
 Set length.
bool empty () const
 Check if the string has length zero.
String head (Index end) const
 Return prefix up to index.
String head (unsigned long end) const
 Prefix of length end.
String substr (unsigned long idx, unsigned long len=~0UL) const
 Substring of length len starting at idx.
String substr (char const *start, unsigned long len=0) const
 Substring of length len starting at start.
template<typename F>
char const * find_match (F &&match) const
 Find matching character. match should be a function such as isspace.
char const * find (char const *c) const
 Find character. Return end() if not found.
char const * find (int c) const
 Find character. Return end() if not found.
char const * rfind (char const *c) const
 Find right-most character. Return end() if not found.
Index starts_with (cxx::String const &c) const
 Check if c is a prefix of string.
char const * find (int c, char const *s) const
 Find character c starting at position s. Return end() if not found.
char const * find (char const *c, char const *s) const
 Find character set at position.
char const & operator[] (unsigned long idx) const
 Get character at idx.
char const & operator[] (int idx) const
 Get character at idx.
char const & operator[] (Index idx) const
 Get character at idx.
bool eof (char const *s) const
 Check if pointer s points behind string.
template<typename INT>
int from_dec (INT *v) const
 Convert decimal string to integer.
template<typename INT>
int from_hex (INT *v) const
 Convert hex string to integer.
template<typename INT>
int from_number (INT *v, unsigned base=0) const
 Convert a number string to an integer.
bool operator== (String const &o) const
 Equality.
bool operator!= (String const &o) const
 Inequality.

Detailed Description

Allocation free string class with explicit length field.

This class is used to group characters of a string which belong to one syntactical token types number, identifier, string, whitespace or another single character.

Strings in this class can contain null bytes and may denote parts of other strings.

Examples
tmpfs/lib/src/fs.cc.

Definition at line 32 of file string.

Constructor & Destructor Documentation

◆ String()

cxx::String::String ( char const * s,
char const * e )
inlinenoexcept

Initialize with start and end pointer.

Parameters
sfirst character of the string
epointer to first byte behind the string

Definition at line 50 of file string.

Member Function Documentation

◆ find()

char const * cxx::String::find ( char const * c,
char const * s ) const
inline

Find character set at position.

Parameters
czero-terminated string of characters to search for
sstart position of search in string
Return values
end()if no char in c is contained in string at or behind s.
positionin string of some character in c.

Definition at line 193 of file string.

References end(), and eof().

Here is the call graph for this function:

◆ from_dec()

template<typename INT>
int cxx::String::from_dec ( INT * v) const
inline

Convert decimal string to integer.

Template Parameters
INTresult integer type
Parameters
[out]vconversion result
Returns
position of first character not converted.

Definition at line 230 of file string.

References eof(), and start().

Here is the call graph for this function:

◆ from_hex()

template<typename INT>
int cxx::String::from_hex ( INT * v) const
inline

Convert hex string to integer.

Template Parameters
INTresult integer type
Parameters
[out]vconversion result
Return values
-1if the maximal amount of digits fitting into INT have been read,
positionof first character not converted otherwise.

Definition at line 259 of file string.

References eof(), and start().

Here is the call graph for this function:

◆ from_number()

template<typename INT>
int cxx::String::from_number ( INT * v,
unsigned base = 0 ) const
inline

Convert a number string to an integer.

Converts the initial part of the string to a number, according to the given base. The string may start with an arbitrary amount of white space followed by a single optional + or - sign. If base is zero or 16, the string may then include a "0x" or "0X" prefix, and the number will be read in base 16; otherwise, a zero base is taken as 10 (decimal) unless the next character is '0', in which case it is taken as 8 (octal).

Conversion stops at the first character that is not a valid digit for the chosen base. If the string does not contain any digit at all, zero is returned and v is left unmodified.

Template Parameters
INTresult integer type
Parameters
[out]vconversion result
baseBase of the number (0, 2..36)
Return values
>0Success. Position of first character after the number.
0The string does not contain a number.
-L4_EINVALInvalid base parameter
-L4_ERANGEParsed number too large to be stored in v

Definition at line 309 of file string.

References eof(), L4_EINVAL, L4_ERANGE, and start().

Here is the call graph for this function:

◆ starts_with()

Index cxx::String::starts_with ( cxx::String const & c) const
inline

Check if c is a prefix of string.

Returns
0 if c is not a prefix, if it is a prefix, return first position not in c (which might be end()).

Definition at line 157 of file string.

References start().

Here is the call graph for this function:

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