|
|
| 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.
|
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.
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
-
- Parameters
-
| [out] | v | conversion result |
| base | Base of the number (0, 2..36) |
- Return values
-
| >0 | Success. Position of first character after the number. |
| 0 | The string does not contain a number. |
| -L4_EINVAL | Invalid base parameter |
| -L4_ERANGE | Parsed number too large to be stored in v |
Definition at line 309 of file string.
References eof(), L4_EINVAL, L4_ERANGE, and start().