|
RAVENNAKIT
|
A handy utility class for parsing strings. More...
#include <string_parser.hpp>
Public Member Functions | |
| StringParser (const std::string_view str) | |
| Constructs a parser from given string view. | |
| StringParser (const std::optional< std::string_view > &str) | |
| Constructs a parser from given string view. | |
| StringParser (const char *str, const size_t size) | |
| Constructs a parser from given c-string and size. | |
| StringParser (const char *str) | |
| Constructs a parser from given c-string. | |
| StringParser (const std::string &str) | |
| Constructs a parser from given string. | |
| std::optional< std::string_view > | read_until (const char delimiter, const bool include_delimiter=false) |
| Reads until given delimiter. | |
| std::optional< std::string_view > | read_until (const char *delimiter, const bool include_delimiter=false) |
| Reads until given delimiter. | |
| std::optional< std::string_view > | split (const char delimiter, const bool include_delimiter=false) |
| Reads until the given delimiter or until the end of the string. | |
| std::optional< std::string_view > | split (const char *delimiter, const bool include_delimiter=false) |
| Reads until given delimiter or until the end of the string. | |
| std::optional< std::string_view > | read_line () |
| Reads a line from the string. | |
| std::optional< std::string_view > | read_until_newline () |
| Reads until a newline is found. | |
| std::optional< std::string_view > | read_until_end () |
| Reads the rest of the string. | |
| template<class T> | |
| std::optional< T > | read_int () |
| Tries to read an integer from the string. | |
| std::optional< float > | read_float () |
| Tries to read a float from the string. | |
| std::optional< double > | read_double () |
| Tries to read a float from the string. | |
| bool | skip (const char *chars) |
| Skips the given sequence of characters from the beginning of the string. | |
| bool | skip (const char chr) |
| Skips the given character from the beginning of the string. | |
| uint64_t | skip_n (const char chr, const size_t count) |
| Skips n amount of characters from the beginning of the string. | |
| bool | exhausted () const |
| size_t | size () const |
| bool | empty () const |
Static Public Attributes | |
| static constexpr auto | k_max_leading_spaces = 100'000 |
A handy utility class for parsing strings.
It works like a stream, where it maintains a position in the string and subsequent calls will read from that position.
Definition at line 42 of file string_parser.hpp.
|
inlineexplicit |
Constructs a parser from given string view.
Doesn't take ownership of the string, so make sure for the original string to outlive this parser instance.
| str | The string to parse. |
Definition at line 51 of file string_parser.hpp.
|
inlineexplicit |
Constructs a parser from given string view.
Doesn't take ownership of the string, so make sure for the original string to outlive this parser instance.
| str | The string to parse. |
Definition at line 58 of file string_parser.hpp.
|
inline |
Constructs a parser from given c-string and size.
Doesn't take ownership of the string, so make sure for the original string to outlive this parser instance.
| str | The string to parse. |
| size | The size of the string (without terminating null character). |
Definition at line 70 of file string_parser.hpp.
|
inlineexplicit |
Constructs a parser from given c-string.
String must be null-terminated. Doesn't take ownership of the string, so make sure for the original string to outlive this parser instance.
| str | The string to parse. |
Definition at line 77 of file string_parser.hpp.
|
inlineexplicit |
Constructs a parser from given string.
Doesn't take ownership of the string, so make sure for the original string to outlive this parser instance.
| str | The string to parse. |
Definition at line 84 of file string_parser.hpp.
|
inlinenodiscard |
Definition at line 355 of file string_parser.hpp.
|
inlinenodiscard |
Definition at line 341 of file string_parser.hpp.
|
inline |
Tries to read a float from the string.
If successful, the float is returned, otherwise an empty optional is returned.
Definition at line 277 of file string_parser.hpp.
|
inline |
Tries to read a float from the string.
If successful, the float is returned, otherwise an empty optional is returned.
Definition at line 256 of file string_parser.hpp.
|
inline |
Tries to read an integer from the string.
If successful, the integer is returned; otherwise an empty optional is returned. Leading whitespace characters are automatically ignored when parsing the number
| T | The type of the integer to read. |
Definition at line 238 of file string_parser.hpp.
|
inline |
Reads a line from the string.
A line is considered to be terminated by a newline character or by the end of the string.
Definition at line 181 of file string_parser.hpp.
|
inline |
Reads until given delimiter.
| delimiter | The character sequence to read until. |
| include_delimiter | Whether to include the delimiter in the returned string. |
Definition at line 113 of file string_parser.hpp.
|
inline |
Reads until given delimiter.
| delimiter | The character sequence to read until. |
| include_delimiter | Whether to include the delimiter in the returned string. |
Definition at line 92 of file string_parser.hpp.
|
inline |
Reads the rest of the string.
Definition at line 222 of file string_parser.hpp.
|
inline |
Reads until a newline is found.
Newline can be \r
or
.
Definition at line 200 of file string_parser.hpp.
|
inlinenodiscard |
Definition at line 348 of file string_parser.hpp.
|
inline |
Skips the given sequence of characters from the beginning of the string.
| chars | The characters to skip. |
Definition at line 298 of file string_parser.hpp.
|
inline |
Skips the given character from the beginning of the string.
| chr | The character to skip. |
Definition at line 312 of file string_parser.hpp.
|
inline |
Skips n amount of characters from the beginning of the string.
| chr | The character to skip. |
| count | The number of characters to skip. |
Definition at line 327 of file string_parser.hpp.
|
inline |
Reads until given delimiter or until the end of the string.
It's like splitting string, but only returning the first part.
| delimiter | The character sequence to read until. |
| include_delimiter | Whether to include the delimiter in the returned string. |
Definition at line 159 of file string_parser.hpp.
|
inline |
Reads until the given delimiter or until the end of the string.
It's like splitting string but only returning (and consuming) the first part.
| delimiter | The character sequence to read until. |
| include_delimiter | Whether to include the delimiter in the returned string. |
Definition at line 135 of file string_parser.hpp.
|
staticconstexpr |
Definition at line 44 of file string_parser.hpp.