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.
 
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.

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

Examples
tmpfs/lib/src/fs.cc.

Definition at line 41 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 59 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 202 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 239 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 268 of file string.

References eof(), 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 166 of file string.

References start().

+ Here is the call graph for this function:

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