OpenTTD Source 20250503-master-gf4f05dea33
|
Parse data from a string / buffer. More...
#include <string_consumer.hpp>
Public Types | |
enum | SeparatorUsage { READ_ALL_SEPARATORS , READ_ONE_SEPARATOR , KEEP_SEPARATOR , SKIP_ONE_SEPARATOR , SKIP_ALL_SEPARATORS } |
Treatment of separator characters. More... | |
using | size_type = std::string_view::size_type |
Public Member Functions | |
StringConsumer (std::string_view src) | |
Construct parser with data from string. | |
StringConsumer (const std::string &src) | |
Construct parser with data from string. | |
StringConsumer (std::span< const char > src) | |
Construct parser with data from span. | |
StringConsumer (const char *src, size_type len) | |
Construct parser with data from buffer. | |
bool | AnyBytesLeft () const noexcept |
Check whether any bytes left to read. | |
size_type | GetBytesLeft () const noexcept |
Get number of bytes left to read. | |
bool | AnyBytesRead () const noexcept |
Check wheter any bytes were already read. | |
size_type | GetBytesRead () const noexcept |
Get number of already read bytes. | |
std::string_view | GetOrigData () const noexcept |
Get the original data, as passed to the constructor. | |
std::string_view | GetReadData () const noexcept |
Get already read data. | |
std::string_view | GetLeftData () const noexcept |
Get data left to read. | |
void | SkipAll () |
Discard all remaining data. | |
std::optional< uint8_t > | PeekUint8 () const |
Peek binary uint8. | |
std::optional< uint8_t > | TryReadUint8 () |
Try to read binary uint8, and then advance reader. | |
uint8_t | ReadUint8 (uint8_t def=0) |
Read binary uint8, and advance reader. | |
void | SkipUint8 () |
Skip binary uint8. | |
std::optional< int8_t > | PeekSint8 () const |
Peek binary int8. | |
std::optional< int8_t > | TryReadSint8 () |
Try to read binary int8, and then advance reader. | |
int8_t | ReadSint8 (int8_t def=0) |
Read binary int8, and advance reader. | |
void | SkipSint8 () |
Skip binary int8. | |
std::optional< uint16_t > | PeekUint16LE () const |
Peek binary uint16 using little endian. | |
std::optional< uint16_t > | TryReadUint16LE () |
Try to read binary uint16, and then advance reader. | |
uint16_t | ReadUint16LE (uint16_t def=0) |
Read binary uint16 using little endian, and advance reader. | |
void | SkipUint16LE () |
Skip binary uint16, and advance reader. | |
std::optional< int16_t > | PeekSint16LE () const |
Peek binary int16 using little endian. | |
std::optional< int16_t > | TryReadSint16LE () |
Try to read binary int16, and then advance reader. | |
int16_t | ReadSint16LE (int16_t def=0) |
Read binary int16 using little endian, and advance reader. | |
void | SkipSint16LE () |
Skip binary int16, and advance reader. | |
std::optional< uint32_t > | PeekUint32LE () const |
Peek binary uint32 using little endian. | |
std::optional< uint32_t > | TryReadUint32LE () |
Try to read binary uint32, and then advance reader. | |
uint32_t | ReadUint32LE (uint32_t def=0) |
Read binary uint32 using little endian, and advance reader. | |
void | SkipUint32LE () |
Skip binary uint32, and advance reader. | |
std::optional< int32_t > | PeekSint32LE () const |
Peek binary int32 using little endian. | |
std::optional< int32_t > | TryReadSint32LE () |
Try to read binary int32, and then advance reader. | |
int32_t | ReadSint32LE (int32_t def=0) |
Read binary int32 using little endian, and advance reader. | |
void | SkipSint32LE () |
Skip binary int32, and advance reader. | |
std::optional< uint64_t > | PeekUint64LE () const |
Peek binary uint64 using little endian. | |
std::optional< uint64_t > | TryReadUint64LE () |
Try to read binary uint64, and then advance reader. | |
uint64_t | ReadUint64LE (uint64_t def=0) |
Read binary uint64 using little endian, and advance reader. | |
void | SkipUint64LE () |
Skip binary uint64, and advance reader. | |
std::optional< int64_t > | PeekSint64LE () const |
Peek binary int64 using little endian. | |
std::optional< int64_t > | TryReadSint64LE () |
Try to read binary int64, and then advance reader. | |
int64_t | ReadSint64LE (int64_t def=0) |
Read binary int64 using little endian, and advance reader. | |
void | SkipSint64LE () |
Skip binary int64, and advance reader. | |
std::optional< char > | PeekChar () const |
Peek 8-bit character. | |
std::optional< char > | TryReadChar () |
Try to read a 8-bit character, and then advance reader. | |
char | ReadChar (char def='?') |
Read 8-bit character, and advance reader. | |
void | SkipChar () |
Skip 8-bit character, and advance reader. | |
std::pair< size_type, char32_t > | PeekUtf8 () const |
Peek UTF-8 character. | |
std::optional< char32_t > | TryReadUtf8 () |
Try to read a UTF-8 character, and then advance reader. | |
char32_t | ReadUtf8 (char32_t def='?') |
Read UTF-8 character, and advance reader. | |
void | SkipUtf8 () |
Skip UTF-8 character, and advance reader. | |
bool | PeekIf (std::string_view str) const |
Check whether the next data matches 'str'. | |
bool | ReadIf (std::string_view str) |
Check whether the next data matches 'str', and skip it. | |
void | SkipIf (std::string_view str) |
If the next data matches 'str', then skip it. | |
bool | PeekCharIf (char c) const |
Check whether the next 8-bit char matches 'c'. | |
bool | ReadCharIf (char c) |
Check whether the next 8-bit char matches 'c', and skip it. | |
void | SkipCharIf (char c) |
If the next data matches the 8-bit char 'c', then skip it. | |
bool | PeekUtf8If (char32_t c) const |
Check whether the next UTF-8 char matches 'c'. | |
bool | ReadUtf8If (char32_t c) |
Check whether the next UTF-8 char matches 'c', and skip it. | |
void | SkipUtf8If (char32_t c) |
If the next data matches the UTF-8 char 'c', then skip it. | |
std::string_view | Peek (size_type len) const |
Peek the next 'len' bytes. | |
std::string_view | Read (size_type len) |
Read the next 'len' bytes, and advance reader. | |
void | Skip (size_type len) |
Discard some bytes. | |
size_type | Find (std::string_view str) const |
Find first occurence of 'str'. | |
size_type | FindChar (char c) const |
Find first occurence of 8-bit char 'c'. | |
size_type | FindUtf8 (char32_t c) const |
Find first occurence of UTF-8 char 'c'. | |
size_type | FindCharIn (std::string_view chars) const |
Find first occurence of any 8-bit char in 'chars'. | |
size_type | FindCharNotIn (std::string_view chars) const |
Find first occurence of any 8-bit char not in 'chars'. | |
std::optional< char > | PeekCharIfIn (std::string_view chars) const |
Check whether the next 8-bit char is in 'chars'. | |
std::optional< char > | ReadCharIfIn (std::string_view chars) |
Read next 8-bit char, check whether it is in 'chars', and advance reader. | |
void | SkipCharIfIn (std::string_view chars) |
If the next 8-bit char is in 'chars', skip it. | |
std::optional< char > | PeekCharIfNotIn (std::string_view chars) const |
Check whether the next 8-bit char is not in 'chars'. | |
std::optional< char > | ReadCharIfNotIn (std::string_view chars) |
Read next 8-bit char, check whether it is not in 'chars', and advance reader. | |
void | SkipCharIfNotIn (std::string_view chars) |
If the next 8-bit char is not in 'chars', skip it. | |
std::string_view | PeekUntilCharIn (std::string_view chars) const |
Peek 8-bit chars, while they are not in 'chars', until they are. | |
std::string_view | ReadUntilCharIn (std::string_view chars) |
Read 8-bit chars, while they are not in 'chars', until they are; and advance reader. | |
void | SkipUntilCharIn (std::string_view chars) |
Skip 8-bit chars, while they are not in 'chars', until they are. | |
std::string_view | PeekUntilCharNotIn (std::string_view chars) const |
Peek 8-bit chars, while they are in 'chars', until they are not. | |
std::string_view | ReadUntilCharNotIn (std::string_view chars) |
Read 8-bit chars, while they are in 'chars', until they are not; and advance reader. | |
void | SkipUntilCharNotIn (std::string_view chars) |
Skip 8-bit chars, while they are in 'chars', until they are not. | |
std::string_view | PeekUntil (std::string_view str, SeparatorUsage sep) const |
Peek data until the first occurrence of 'str'. | |
std::string_view | ReadUntil (std::string_view str, SeparatorUsage sep) |
Read data until the first occurrence of 'str', and advance reader. | |
void | SkipUntil (std::string_view str, SeparatorUsage sep) |
Skip data until the first occurrence of 'str'. | |
std::string_view | PeekUntilChar (char c, SeparatorUsage sep) const |
Peek data until the first occurrence of 8-bit char 'c'. | |
std::string_view | ReadUntilChar (char c, SeparatorUsage sep) |
Read data until the first occurrence of 8-bit char 'c', and advance reader. | |
void | SkipUntilChar (char c, SeparatorUsage sep) |
Skip data until the first occurrence of 8-bit char 'c'. | |
std::string_view | PeekUntilUtf8 (char32_t c, SeparatorUsage sep) const |
Peek data until the first occurrence of UTF-8 char 'c'. | |
std::string_view | ReadUntilUtf8 (char32_t c, SeparatorUsage sep) |
Read data until the first occurrence of UTF-8 char 'c', and advance reader. | |
void | SkipUntilUtf8 (char32_t c, SeparatorUsage sep) |
Skip data until the first occurrence of UTF-8 char 'c'. | |
template<class T > | |
std::pair< size_type, T > | PeekIntegerBase (int base) const |
Peek and parse an integer in number 'base'. | |
template<class T > | |
std::optional< T > | TryReadIntegerBase (int base) |
Try to read and parse an integer in number 'base', and then advance the reader. | |
template<class T > | |
T | ReadIntegerBase (int base, T def=0) |
Read and parse an integer in number 'base', and advance the reader. | |
void | SkipIntegerBase (int base) |
Skip an integer in number 'base'. | |
Static Public Attributes | |
static constexpr size_type | npos = std::string_view::npos |
Special value for "end of data". | |
static const std::string_view | WHITESPACE_NO_NEWLINE = "\t\v\f\r " |
ASCII whitespace characters, excluding new-line. | |
static const std::string_view | WHITESPACE_OR_NEWLINE = "\t\n\v\f\r " |
ASCII whitespace characters, including new-line. | |
Static Private Member Functions | |
static void | LogError (std::string &&msg) |
template<class T > | |
static std::pair< size_type, T > | ParseIntegerBase (std::string_view src, int base, bool log_errors) |
Private Attributes | |
std::string_view | src |
size_type | position = 0 |
Parse data from a string / buffer.
There are generally four operations for each data type:
Definition at line 27 of file string_consumer.hpp.
using StringConsumer::size_type = std::string_view::size_type |
Definition at line 29 of file string_consumer.hpp.
Treatment of separator characters.
Definition at line 696 of file string_consumer.hpp.
|
inlineexplicit |
Construct parser with data from string.
Definition at line 57 of file string_consumer.hpp.
|
inlineexplicit |
Construct parser with data from string.
Definition at line 61 of file string_consumer.hpp.
|
inlineexplicit |
Construct parser with data from span.
Definition at line 65 of file string_consumer.hpp.
|
inline |
Construct parser with data from buffer.
Definition at line 69 of file string_consumer.hpp.
|
inlinenoexcept |
Check whether any bytes left to read.
Definition at line 74 of file string_consumer.hpp.
Referenced by DecodeEncodedString(), FixSCCEncoded(), FixSCCEncodedNegative(), GetKeyboardLayout(), HandleNewGRFStringControlCodes(), ParseResolution(), EncodedString::ReplaceParam(), StrMakeValid(), StrValid(), and TranslateTTDPatchCodes().
|
inlinenoexcept |
Check wheter any bytes were already read.
Definition at line 83 of file string_consumer.hpp.
StringConsumer::size_type StringConsumer::Find | ( | std::string_view | str | ) | const |
Find first occurence of 'str'.
Definition at line 110 of file string_consumer.cpp.
Referenced by FindChar(), FindUtf8(), and SkipUntil().
|
inline |
Find first occurence of 8-bit char 'c'.
Definition at line 558 of file string_consumer.hpp.
References Find().
StringConsumer::size_type StringConsumer::FindCharIn | ( | std::string_view | chars | ) | const |
Find first occurence of any 8-bit char in 'chars'.
Definition at line 123 of file string_consumer.cpp.
Referenced by PeekUntilCharIn(), ReadUntilCharIn(), and SkipUntilCharIn().
StringConsumer::size_type StringConsumer::FindCharNotIn | ( | std::string_view | chars | ) | const |
Find first occurence of any 8-bit char not in 'chars'.
Definition at line 130 of file string_consumer.cpp.
Referenced by PeekUntilCharNotIn(), ReadUntilCharNotIn(), and SkipUntilCharNotIn().
StringConsumer::size_type StringConsumer::FindUtf8 | ( | char32_t | c | ) | const |
Find first occurence of UTF-8 char 'c'.
Definition at line 117 of file string_consumer.cpp.
References EncodeUtf8(), and Find().
|
inlinenoexcept |
Get number of bytes left to read.
Definition at line 78 of file string_consumer.hpp.
Referenced by PeekUint16LE(), PeekUint32LE(), PeekUint64LE(), PeekUint8(), and Skip().
|
inlinenoexcept |
Get number of already read bytes.
Definition at line 87 of file string_consumer.hpp.
|
inlinenoexcept |
Get data left to read.
Definition at line 100 of file string_consumer.hpp.
Referenced by GetDriverParam().
|
inlinenoexcept |
Get the original data, as passed to the constructor.
Definition at line 92 of file string_consumer.hpp.
|
inlinenoexcept |
Get already read data.
Definition at line 96 of file string_consumer.hpp.
|
staticprivate |
Definition at line 30 of file string_consumer.cpp.
|
inlinestaticprivate |
Definition at line 804 of file string_consumer.hpp.
std::string_view StringConsumer::Peek | ( | size_type | len | ) | const |
Peek the next 'len' bytes.
len | Bytes to read, 'npos' to read all. |
Definition at line 87 of file string_consumer.cpp.
Referenced by PeekUntilCharIn(), PeekUntilCharNotIn(), and Read().
std::optional< char > StringConsumer::PeekChar | ( | ) | const |
Peek 8-bit character.
Definition at line 74 of file string_consumer.cpp.
References PeekUint8().
Referenced by PeekCharIfIn(), PeekCharIfNotIn(), ReadChar(), and TryReadChar().
|
inline |
Check whether the next 8-bit char matches 'c'.
Definition at line 475 of file string_consumer.hpp.
References PeekIf().
Referenced by StrMakeValid().
|
inline |
Check whether the next 8-bit char is in 'chars'.
Definition at line 583 of file string_consumer.hpp.
References PeekChar().
Referenced by ReadCharIfIn(), and SkipCharIfIn().
|
inline |
Check whether the next 8-bit char is not in 'chars'.
Definition at line 613 of file string_consumer.hpp.
References PeekChar().
Referenced by ReadCharIfNotIn(), and SkipCharIfNotIn().
|
inline |
Check whether the next data matches 'str'.
Definition at line 451 of file string_consumer.hpp.
Referenced by PeekCharIf(), ReadIf(), and SkipIf().
|
inline |
Peek and parse an integer in number 'base'.
If 'base == 0', then a prefix '0x' decides between base 16 or base 10.
Definition at line 854 of file string_consumer.hpp.
|
inline |
Peek binary int16 using little endian.
Definition at line 208 of file string_consumer.hpp.
References PeekUint16LE().
Referenced by ReadSint16LE(), and TryReadSint16LE().
|
inline |
Peek binary int32 using little endian.
Definition at line 277 of file string_consumer.hpp.
References PeekUint32LE().
Referenced by ReadSint32LE(), and TryReadSint32LE().
|
inline |
Peek binary int64 using little endian.
Definition at line 346 of file string_consumer.hpp.
References PeekUint64LE().
Referenced by ReadSint64LE(), and TryReadSint64LE().
|
inline |
Peek binary int8.
Definition at line 141 of file string_consumer.hpp.
References PeekUint8().
Referenced by ReadSint8(), and TryReadSint8().
std::optional< uint16_t > StringConsumer::PeekUint16LE | ( | ) | const |
Peek binary uint16 using little endian.
Definition at line 45 of file string_consumer.cpp.
References GetBytesLeft().
Referenced by PeekSint16LE(), ReadUint16LE(), and TryReadUint16LE().
std::optional< uint32_t > StringConsumer::PeekUint32LE | ( | ) | const |
Peek binary uint32 using little endian.
Definition at line 52 of file string_consumer.cpp.
References GetBytesLeft().
Referenced by ByteReader::PeekDWord(), PeekSint32LE(), ReadUint32LE(), and TryReadUint32LE().
std::optional< uint64_t > StringConsumer::PeekUint64LE | ( | ) | const |
Peek binary uint64 using little endian.
Definition at line 61 of file string_consumer.cpp.
References GetBytesLeft().
Referenced by PeekSint64LE(), ReadUint64LE(), and TryReadUint64LE().
std::optional< uint8_t > StringConsumer::PeekUint8 | ( | ) | const |
Peek binary uint8.
Definition at line 39 of file string_consumer.cpp.
References GetBytesLeft().
Referenced by PeekChar(), PeekSint8(), ReadUint8(), and TryReadUint8().
std::string_view StringConsumer::PeekUntil | ( | std::string_view | str, |
SeparatorUsage | sep | ||
) | const |
Peek data until the first occurrence of 'str'.
str | Separator string. |
sep | Whether to include/exclude 'str' from the result. |
Definition at line 137 of file string_consumer.cpp.
References READ_ALL_SEPARATORS, and READ_ONE_SEPARATOR.
Referenced by PeekUntilChar(), PeekUntilUtf8(), and ReadUntil().
|
inline |
Peek data until the first occurrence of 8-bit char 'c'.
c | Separator char. |
sep | Whether to include/exclude 'c' from the result. |
Definition at line 760 of file string_consumer.hpp.
References PeekUntil().
|
inline |
Peek 8-bit chars, while they are not in 'chars', until they are.
Definition at line 643 of file string_consumer.hpp.
References FindCharIn(), and Peek().
|
inline |
Peek 8-bit chars, while they are in 'chars', until they are not.
Definition at line 670 of file string_consumer.hpp.
References FindCharNotIn(), and Peek().
std::string_view StringConsumer::PeekUntilUtf8 | ( | char32_t | c, |
SeparatorUsage | sep | ||
) | const |
Peek data until the first occurrence of UTF-8 char 'c'.
c | Separator char. |
sep | Whether to include/exclude 'c' from the result. |
Definition at line 157 of file string_consumer.cpp.
References EncodeUtf8(), and PeekUntil().
std::pair< StringConsumer::size_type, char32_t > StringConsumer::PeekUtf8 | ( | ) | const |
Peek UTF-8 character.
Definition at line 81 of file string_consumer.cpp.
References DecodeUtf8().
Referenced by PeekUtf8If(), ReadUtf8(), ReadUtf8If(), SkipUtf8(), SkipUtf8If(), and TryReadUtf8().
|
inline |
Check whether the next UTF-8 char matches 'c'.
Definition at line 497 of file string_consumer.hpp.
References PeekUtf8().
|
inline |
Read the next 'len' bytes, and advance reader.
len | Bytes to read, 'npos' to read all. |
Definition at line 534 of file string_consumer.hpp.
References npos, Peek(), and Skip().
Referenced by DecodeEncodedString(), FormatString(), FileStringReader::HandlePragma(), ReadUntilCharIn(), ReadUntilCharNotIn(), and EncodedString::ReplaceParam().
|
inline |
Read 8-bit character, and advance reader.
def | Default value to return, if not enough data. |
Definition at line 398 of file string_consumer.hpp.
References PeekChar(), and SkipChar().
|
inline |
Check whether the next 8-bit char matches 'c', and skip it.
Definition at line 482 of file string_consumer.hpp.
References ReadIf().
|
inline |
Read next 8-bit char, check whether it is in 'chars', and advance reader.
Definition at line 594 of file string_consumer.hpp.
References PeekCharIfIn(), and Skip().
|
inline |
Read next 8-bit char, check whether it is not in 'chars', and advance reader.
Definition at line 624 of file string_consumer.hpp.
References PeekCharIfNotIn(), and Skip().
|
inline |
Check whether the next data matches 'str', and skip it.
Definition at line 458 of file string_consumer.hpp.
References PeekIf(), and Skip().
Referenced by ParseResolution(), ReadCharIf(), ReadUntil(), SkipIntegerBase(), and SkipUntil().
|
inline |
Read and parse an integer in number 'base', and advance the reader.
If 'base == 0', then a prefix '0x' decides between base 16 or base 10.
Definition at line 880 of file string_consumer.hpp.
References SkipIntegerBase().
Referenced by DecodeEncodedString(), FixSCCEncodedNegative(), StringReader::HandlePragma(), FileStringReader::HandlePragma(), ClientNetworkContentSocketHandler::OnReceiveData(), and EncodedString::ReplaceParam().
|
inline |
Read binary int16 using little endian, and advance reader.
def | Default value to return, if not enough data. |
Definition at line 229 of file string_consumer.hpp.
References PeekSint16LE(), and SkipSint16LE().
|
inline |
Read binary int32 using little endian, and advance reader.
def | Default value to return, if not enough data. |
Definition at line 298 of file string_consumer.hpp.
References PeekSint32LE(), and SkipSint32LE().
|
inline |
Read binary int64 using little endian, and advance reader.
def | Default value to return, if not enough data. |
Definition at line 367 of file string_consumer.hpp.
References PeekSint64LE(), and SkipSint64LE().
|
inline |
Read binary int8, and advance reader.
def | Default value to return, if not enough data. |
Definition at line 161 of file string_consumer.hpp.
References PeekSint8(), and SkipSint8().
|
inline |
Read binary uint16 using little endian, and advance reader.
def | Default value to return, if not enough data. |
Definition at line 192 of file string_consumer.hpp.
References PeekUint16LE(), and SkipUint16LE().
Referenced by FormatString(), ProcessNewGRFStringControlCode(), and TranslateTTDPatchCodes().
|
inline |
Read binary uint32 using little endian, and advance reader.
def | Default value to return, if not enough data. |
Definition at line 261 of file string_consumer.hpp.
References PeekUint32LE(), and SkipUint32LE().
|
inline |
Read binary uint64 using little endian, and advance reader.
def | Default value to return, if not enough data. |
Definition at line 330 of file string_consumer.hpp.
References PeekUint64LE(), and SkipUint64LE().
|
inline |
Read binary uint8, and advance reader.
def | Default value to return, if not enough data. |
Definition at line 126 of file string_consumer.hpp.
References PeekUint8(), and SkipUint8().
Referenced by FormatString(), ProcessNewGRFStringControlCode(), and TranslateTTDPatchCodes().
|
inline |
Read data until the first occurrence of 'str', and advance reader.
str | Separator string. |
sep | Whether to include/exclude 'str' from the result, and/or skip it. |
Definition at line 715 of file string_consumer.hpp.
References PeekUntil(), ReadIf(), Skip(), SKIP_ALL_SEPARATORS, SKIP_ONE_SEPARATOR, and SkipIf().
Referenced by ReadUntilChar(), and ReadUntilUtf8().
|
inline |
Read data until the first occurrence of 8-bit char 'c', and advance reader.
c | Separator char. |
sep | Whether to include/exclude 'c' from the result, and/or skip it. |
Definition at line 769 of file string_consumer.hpp.
References ReadUntil().
Referenced by StringReader::HandlePragma(), FileStringReader::HandlePragma(), ParseHotkeys(), ParseKeycode(), and ByteReader::ReadString().
|
inline |
Read 8-bit chars, while they are not in 'chars', until they are; and advance reader.
Definition at line 652 of file string_consumer.hpp.
References FindCharIn(), and Read().
|
inline |
Read 8-bit chars, while they are in 'chars', until they are not; and advance reader.
Definition at line 679 of file string_consumer.hpp.
References FindCharNotIn(), and Read().
std::string_view StringConsumer::ReadUntilUtf8 | ( | char32_t | c, |
SeparatorUsage | sep | ||
) |
Read data until the first occurrence of UTF-8 char 'c', and advance reader.
c | Separator char. |
sep | Whether to include/exclude 'c' from the result, and/or skip it. |
Definition at line 163 of file string_consumer.cpp.
References EncodeUtf8(), and ReadUntil().
Referenced by DecodeEncodedString(), FixSCCEncodedNegative(), and EncodedString::ReplaceParam().
|
inline |
Read UTF-8 character, and advance reader.
def | Default value to return, if no valid data. |
Definition at line 429 of file string_consumer.hpp.
References PeekUtf8(), and Skip().
Referenced by DecodeEncodedString(), FormatString(), GetKeyboardLayout(), HandleNewGRFStringControlCodes(), ProcessNewGRFStringControlCode(), and EncodedString::ReplaceParam().
|
inline |
Check whether the next UTF-8 char matches 'c', and skip it.
Definition at line 505 of file string_consumer.hpp.
References PeekUtf8(), and Skip().
Referenced by DecodeEncodedString(), FixSCCEncodedNegative(), FormatString(), EncodedString::ReplaceParam(), and TranslateTTDPatchCodes().
void StringConsumer::Skip | ( | size_type | len | ) |
Discard some bytes.
len | Number of bytes to skip, 'npos' to skip all. |
Definition at line 98 of file string_consumer.cpp.
References GetBytesLeft().
Referenced by ProcessNewGRFStringControlCode(), Read(), ReadCharIfIn(), ReadCharIfNotIn(), ReadIf(), ReadUntil(), ReadUtf8(), ReadUtf8If(), SkipChar(), SkipCharIfIn(), SkipCharIfNotIn(), SkipIf(), SkipSint16LE(), SkipSint32LE(), SkipSint64LE(), SkipSint8(), SkipUint16LE(), SkipUint32LE(), SkipUint64LE(), SkipUint8(), SkipUntil(), SkipUntilCharIn(), SkipUntilCharNotIn(), SkipUtf8(), SkipUtf8If(), StrMakeValid(), and TryReadUtf8().
|
inline |
Discard all remaining data.
Definition at line 105 of file string_consumer.hpp.
Referenced by DecodeEncodedString().
|
inline |
Skip 8-bit character, and advance reader.
Definition at line 406 of file string_consumer.hpp.
References Skip().
Referenced by ReadChar(), and TryReadChar().
|
inline |
If the next data matches the 8-bit char 'c', then skip it.
Definition at line 489 of file string_consumer.hpp.
References SkipIf().
|
inline |
If the next 8-bit char is in 'chars', skip it.
Definition at line 603 of file string_consumer.hpp.
References PeekCharIfIn(), and Skip().
|
inline |
If the next 8-bit char is not in 'chars', skip it.
Definition at line 633 of file string_consumer.hpp.
References PeekCharIfNotIn(), and Skip().
|
inline |
If the next data matches 'str', then skip it.
Definition at line 467 of file string_consumer.hpp.
References PeekIf(), and Skip().
Referenced by ReadUntil(), SkipCharIf(), SkipIntegerBase(), and SkipUntil().
void StringConsumer::SkipIntegerBase | ( | int | base | ) |
Skip an integer in number 'base'.
If 'base == 0', then a prefix '0x' decides between base 16 or base 10.
Definition at line 175 of file string_consumer.cpp.
References ReadIf(), SkipIf(), and SkipUntilCharNotIn().
Referenced by ReadIntegerBase(), and TryReadIntegerBase().
|
inline |
Skip binary int16, and advance reader.
Definition at line 239 of file string_consumer.hpp.
References Skip().
Referenced by ReadSint16LE(), and TryReadSint16LE().
|
inline |
Skip binary int32, and advance reader.
Definition at line 308 of file string_consumer.hpp.
References Skip().
Referenced by ReadSint32LE(), and TryReadSint32LE().
|
inline |
Skip binary int64, and advance reader.
Definition at line 377 of file string_consumer.hpp.
References Skip().
Referenced by ReadSint64LE(), and TryReadSint64LE().
|
inline |
Skip binary int8.
Definition at line 170 of file string_consumer.hpp.
References Skip().
Referenced by ReadSint8(), and TryReadSint8().
|
inline |
Skip binary uint16, and advance reader.
Definition at line 202 of file string_consumer.hpp.
References Skip().
Referenced by ProcessNewGRFStringControlCode(), ReadUint16LE(), and TryReadUint16LE().
|
inline |
Skip binary uint32, and advance reader.
Definition at line 271 of file string_consumer.hpp.
References Skip().
Referenced by ReadUint32LE(), and TryReadUint32LE().
|
inline |
Skip binary uint64, and advance reader.
Definition at line 340 of file string_consumer.hpp.
References Skip().
Referenced by ReadUint64LE(), and TryReadUint64LE().
|
inline |
Skip binary uint8.
Definition at line 135 of file string_consumer.hpp.
References Skip().
Referenced by ProcessNewGRFStringControlCode(), ReadUint8(), TranslateTTDPatchCodes(), and TryReadUint8().
|
inline |
Skip data until the first occurrence of 'str'.
str | Separator string. |
sep | Whether to also skip 'str'. |
Definition at line 737 of file string_consumer.hpp.
References Find(), READ_ALL_SEPARATORS, READ_ONE_SEPARATOR, ReadIf(), Skip(), SKIP_ALL_SEPARATORS, SKIP_ONE_SEPARATOR, and SkipIf().
Referenced by SkipUntilChar(), and SkipUntilUtf8().
|
inline |
Skip data until the first occurrence of 8-bit char 'c'.
c | Separator char. |
sep | Whether to also skip 'c'. |
Definition at line 778 of file string_consumer.hpp.
References SkipUntil().
|
inline |
Skip 8-bit chars, while they are not in 'chars', until they are.
Definition at line 660 of file string_consumer.hpp.
References FindCharIn(), and Skip().
|
inline |
Skip 8-bit chars, while they are in 'chars', until they are not.
Definition at line 687 of file string_consumer.hpp.
References FindCharNotIn(), and Skip().
Referenced by LookupManyOfMany(), ParseInteger(), ParseIntList(), and SkipIntegerBase().
void StringConsumer::SkipUntilUtf8 | ( | char32_t | c, |
SeparatorUsage | sep | ||
) |
Skip data until the first occurrence of UTF-8 char 'c'.
c | Separator char. |
sep | Whether to also skip 'c'. |
Definition at line 169 of file string_consumer.cpp.
References EncodeUtf8(), and SkipUntil().
|
inline |
Skip UTF-8 character, and advance reader.
Definition at line 442 of file string_consumer.hpp.
References PeekUtf8(), and Skip().
Referenced by RemapNewGRFStringControlCode().
|
inline |
If the next data matches the UTF-8 char 'c', then skip it.
Definition at line 515 of file string_consumer.hpp.
References PeekUtf8(), and Skip().
Referenced by DecodeEncodedString().
|
inline |
Try to read a 8-bit character, and then advance reader.
Definition at line 387 of file string_consumer.hpp.
References PeekChar(), and SkipChar().
|
inline |
Try to read and parse an integer in number 'base', and then advance the reader.
If 'base == 0', then a prefix '0x' decides between base 16 or base 10.
Definition at line 865 of file string_consumer.hpp.
References SkipIntegerBase().
Referenced by FileList::FindItem(), FixSCCEncodedNegative(), ParseResolution(), OneOfManySettingDesc::ParseSingleValue(), IntSettingDesc::ParseValue(), EncodedString::ReplaceParam(), and SetDebugString().
|
inline |
Try to read binary int16, and then advance reader.
Definition at line 217 of file string_consumer.hpp.
References PeekSint16LE(), and SkipSint16LE().
|
inline |
Try to read binary int32, and then advance reader.
Definition at line 286 of file string_consumer.hpp.
References PeekSint32LE(), and SkipSint32LE().
|
inline |
Try to read binary int64, and then advance reader.
Definition at line 355 of file string_consumer.hpp.
References PeekSint64LE(), and SkipSint64LE().
|
inline |
Try to read binary int8, and then advance reader.
Definition at line 150 of file string_consumer.hpp.
References PeekSint8(), and SkipSint8().
|
inline |
Try to read binary uint16, and then advance reader.
Definition at line 180 of file string_consumer.hpp.
References PeekUint16LE(), and SkipUint16LE().
Referenced by ByteReader::ReadWord().
|
inline |
Try to read binary uint32, and then advance reader.
Definition at line 249 of file string_consumer.hpp.
References PeekUint32LE(), and SkipUint32LE().
Referenced by ByteReader::ReadDWord().
|
inline |
Try to read binary uint64, and then advance reader.
Definition at line 318 of file string_consumer.hpp.
References PeekUint64LE(), and SkipUint64LE().
|
inline |
Try to read binary uint8, and then advance reader.
Definition at line 115 of file string_consumer.hpp.
References PeekUint8(), and SkipUint8().
Referenced by ByteReader::ReadByte().
|
inline |
Try to read a UTF-8 character, and then advance reader.
Definition at line 416 of file string_consumer.hpp.
References PeekUtf8(), and Skip().
Referenced by FixSCCEncoded(), IConsoleCmdExec(), StrMakeValid(), StrValid(), and TranslateTTDPatchCodes().
|
staticconstexpr |
Special value for "end of data".
Definition at line 34 of file string_consumer.hpp.
Referenced by DecodeEncodedString(), FileStringReader::HandlePragma(), Read(), and EncodedString::ReplaceParam().
|
private |
Definition at line 49 of file string_consumer.hpp.
|
private |
Definition at line 48 of file string_consumer.hpp.
|
static |
ASCII whitespace characters, excluding new-line.
Usable in FindChar(In|NotIn), (Peek|Read|Skip)(If|Until)Char(In|NotIn)
Definition at line 40 of file string_consumer.hpp.
Referenced by ParseInteger(), and ParseIntList().
|
static |
ASCII whitespace characters, including new-line.
Usable in FindChar(In|NotIn), (Peek|Read|Skip)(If|Until)Char(In|NotIn)
Definition at line 45 of file string_consumer.hpp.