|
OpenTTD Source 20260218-master-g2123fca5ea
|
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 |
| The type of the size of our strings. | |
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. | |
| 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 whether 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 occurrence of 'str'. | |
| size_type | FindChar (char c) const |
| Find first occurrence of 8-bit char 'c'. | |
| size_type | FindUtf8 (char32_t c) const |
| Find first occurrence of UTF-8 char 'c'. | |
| size_type | FindCharIn (std::string_view chars) const |
| Find first occurrence of any 8-bit char in 'chars'. | |
| size_type | FindCharNotIn (std::string_view chars) const |
| Find first occurrence 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, bool clamp=false) const |
| Peek and parse an integer in number 'base'. | |
| template<class T> | |
| std::optional< T > | TryReadIntegerBase (int base, bool clamp=false) |
| 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, bool clamp=false) |
| 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) |
| Log an error in the processing (too small buffer, integer out of range, etc.). | |
| template<class T> | |
| static std::pair< size_type, T > | ParseIntegerBase (std::string_view src, int base, bool clamp, bool log_errors) |
| Parse an integer from the given string. | |
Private Attributes | |
| std::string_view | src |
| The string to parse. | |
| size_type | position = 0 |
| The current parsing position in the string. | |
Parse data from a string / buffer.
There are generally four operations for each data type:
Definition at line 25 of file string_consumer.hpp.
| using StringConsumer::size_type = std::string_view::size_type |
The type of the size of our strings.
Definition at line 28 of file string_consumer.hpp.
Treatment of separator characters.
Definition at line 743 of file string_consumer.hpp.
|
inlineexplicit |
Construct parser with data from string.
| src | The source string to read from.. |
Definition at line 57 of file string_consumer.hpp.
References src.
|
inlineexplicit |
Construct parser with data from string.
| src | The source string to read from.. |
Definition at line 62 of file string_consumer.hpp.
References src.
|
inlineexplicit |
Construct parser with data from span.
| src | The source string to read from.. |
Definition at line 67 of file string_consumer.hpp.
References src.
|
inlinenodiscardnoexcept |
Check whether any bytes left to read.
true iff there are any bytes to read. Definition at line 73 of file string_consumer.hpp.
Referenced by ConStartAI(), DecodeEncodedString(), DumpLine(), FileList::FindItem(), FixSCCEncoded(), FixSCCEncodedNegative(), GetDriverParam(), GetKeyboardLayout(), HandleNewGRFStringControlCodes(), HasStringInExtensionList(), IConsoleAliasExec(), IConsoleCmdExec(), NetworkAddress::IsInNetmask(), IniLoadFile::LoadFromDisk(), LookupManyOfMany(), ClientNetworkContentSocketHandler::OnReceiveData(), ParseCompanyManagerFaceCode(), ParseHotkeys(), ParseInteger(), ParseIntList(), ParseKeycode(), ParseResolution(), IntSettingDesc::ParseValue(), SelectGameWindow::ReadIntroGameViewportCommand(), EncodedString::ReplaceParam(), SetDebugString(), StrMakeValid(), StrValid(), and TranslateTTDPatchCodes().
|
inlinenodiscardnoexcept |
Check whether any bytes were already read.
true iff there were any bytes read. Definition at line 84 of file string_consumer.hpp.
|
nodiscard |
Find first occurrence of 'str'.
| str | The string to search for. |
Definition at line 113 of file string_consumer.cpp.
Referenced by FindChar(), FindUtf8(), and SkipUntil().
|
inlinenodiscard |
Find first occurrence of 8-bit char 'c'.
| c | The character to search for. |
Definition at line 590 of file string_consumer.hpp.
References Find().
Referenced by ParseCompanyManagerFaceCode().
|
nodiscard |
Find first occurrence of any 8-bit char in 'chars'.
| chars | The set of characters to find an occurrence for. |
Definition at line 126 of file string_consumer.cpp.
Referenced by PeekUntilCharIn(), ReadUntilCharIn(), and SkipUntilCharIn().
|
nodiscard |
Find first occurrence of any 8-bit char not in 'chars'.
| chars | The set of characters to not find an occurrence for. |
Definition at line 133 of file string_consumer.cpp.
Referenced by PeekUntilCharNotIn(), ReadUntilCharNotIn(), and SkipUntilCharNotIn().
|
nodiscard |
Find first occurrence of UTF-8 char 'c'.
| c | The character to search for. |
Definition at line 120 of file string_consumer.cpp.
References EncodeUtf8(), and Find().
|
inlinenodiscardnoexcept |
Get number of bytes left to read.
Definition at line 78 of file string_consumer.hpp.
Referenced by PeekUint16LE(), PeekUint32LE(), PeekUint64LE(), PeekUint8(), and Skip().
|
inlinenodiscardnoexcept |
Get number of already read bytes.
Definition at line 89 of file string_consumer.hpp.
|
inlinenodiscardnoexcept |
Get data left to read.
Definition at line 105 of file string_consumer.hpp.
Referenced by GetDriverParam(), IniLoadFile::LoadFromDisk(), and ClientNetworkContentSocketHandler::OnReceiveData().
|
inlinenodiscardnoexcept |
Get the original data, as passed to the constructor.
Definition at line 95 of file string_consumer.hpp.
Referenced by IniLoadFile::LoadFromDisk().
|
inlinenodiscardnoexcept |
Get already read data.
Definition at line 100 of file string_consumer.hpp.
|
staticprivate |
Log an error in the processing (too small buffer, integer out of range, etc.).
| msg | The message to log. |
Definition at line 33 of file string_consumer.cpp.
References DebugPrint(), and FatalErrorI().
Referenced by ParseIntegerBase(), Read(), and Skip().
|
inlinestaticnodiscardprivate |
Parse an integer from the given string.
| src | The source string to read from. |
| base | The base of the integer, or 0 to auto detect. |
| clamp | Whether to automatically clamp the number to be within the types range. |
| log_errors | Whether to log errors encountered during parsing. |
| T | The type of integer to parse. |
Definition at line 866 of file string_consumer.hpp.
References LogError(), ParseIntegerBase(), and src.
Referenced by ParseIntegerBase(), PeekIntegerBase(), and ReadIntegerBase().
|
nodiscard |
Peek the next 'len' bytes.
| len | Bytes to read, 'npos' to read all. |
Definition at line 90 of file string_consumer.cpp.
Referenced by PeekUntilCharIn(), PeekUntilCharNotIn(), and Read().
|
nodiscard |
Peek 8-bit character.
Definition at line 77 of file string_consumer.cpp.
References PeekUint8().
Referenced by PeekCharIfIn(), PeekCharIfNotIn(), ReadChar(), and TryReadChar().
|
inlinenodiscard |
Check whether the next 8-bit char matches 'c'.
| c | The character to match. |
true iff the next character is equal to the given character. Definition at line 497 of file string_consumer.hpp.
References PeekIf().
Referenced by StrMakeValid().
|
inlinenodiscard |
Check whether the next 8-bit char is in 'chars'.
| chars | The set of characters to find an occurrence for. |
Definition at line 619 of file string_consumer.hpp.
References PeekChar().
Referenced by IniLoadFile::LoadFromDisk(), ReadCharIfIn(), and SkipCharIfIn().
|
inlinenodiscard |
Check whether the next 8-bit char is not in 'chars'.
| chars | The set of characters to not find an occurrence for. |
Definition at line 652 of file string_consumer.hpp.
References PeekChar().
Referenced by ReadCharIfNotIn(), and SkipCharIfNotIn().
|
inlinenodiscard |
Check whether the next data matches 'str'.
| str | String to compare to. |
true iff the next data is equal to the string. Definition at line 468 of file string_consumer.hpp.
Referenced by PeekCharIf(), ReadIf(), and SkipIf().
|
inlinenodiscard |
Peek and parse an integer in number 'base'.
If 'base == 0', then a prefix '0x' decides between base 16 or base 10.
| base | The base to interpret the string as. |
| clamp | If the value is a valid number, but out of range for T, return the maximum representable value. Negative values for unsigned results are still treated as invalid. |
Definition at line 928 of file string_consumer.hpp.
References ParseIntegerBase().
Referenced by TryReadIntegerBase().
|
inlinenodiscard |
Peek binary int16 using little endian.
Definition at line 216 of file string_consumer.hpp.
References PeekUint16LE().
Referenced by ReadSint16LE(), and TryReadSint16LE().
|
inlinenodiscard |
Peek binary int32 using little endian.
Definition at line 287 of file string_consumer.hpp.
References PeekUint32LE().
Referenced by ReadSint32LE(), and TryReadSint32LE().
|
inlinenodiscard |
Peek binary int64 using little endian.
Definition at line 358 of file string_consumer.hpp.
References PeekUint64LE().
Referenced by ReadSint64LE(), and TryReadSint64LE().
|
inlinenodiscard |
Peek binary int8.
Definition at line 147 of file string_consumer.hpp.
References PeekUint8().
Referenced by ReadSint8(), and TryReadSint8().
|
nodiscard |
Peek binary uint16 using little endian.
Definition at line 48 of file string_consumer.cpp.
References GetBytesLeft(), position, and src.
Referenced by PeekSint16LE(), ReadUint16LE(), and TryReadUint16LE().
|
nodiscard |
Peek binary uint32 using little endian.
Definition at line 55 of file string_consumer.cpp.
References GetBytesLeft(), position, and src.
Referenced by ByteReader::PeekDWord(), PeekSint32LE(), ReadUint32LE(), and TryReadUint32LE().
|
nodiscard |
Peek binary uint64 using little endian.
Definition at line 64 of file string_consumer.cpp.
References GetBytesLeft(), position, and src.
Referenced by PeekSint64LE(), ReadUint64LE(), and TryReadUint64LE().
|
nodiscard |
Peek binary uint8.
Definition at line 42 of file string_consumer.cpp.
References GetBytesLeft(), position, and src.
Referenced by PeekChar(), PeekSint8(), ReadUint8(), and TryReadUint8().
|
nodiscard |
Peek data until the first occurrence of 'str'.
| str | Separator string. |
| sep | Whether to include/exclude 'str' from the result. |
Definition at line 140 of file string_consumer.cpp.
References position, READ_ALL_SEPARATORS, READ_ONE_SEPARATOR, and src.
Referenced by PeekUntilChar(), PeekUntilUtf8(), and ReadUntil().
|
inlinenodiscard |
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 810 of file string_consumer.hpp.
References PeekUntil().
|
inlinenodiscard |
Peek 8-bit chars, while they are not in 'chars', until they are.
| chars | The set of characters to find an occurrence for. |
Definition at line 685 of file string_consumer.hpp.
References FindCharIn(), and Peek().
|
inlinenodiscard |
Peek 8-bit chars, while they are in 'chars', until they are not.
| chars | The set of characters to not find an occurrence for. |
Definition at line 715 of file string_consumer.hpp.
References FindCharNotIn(), and Peek().
|
nodiscard |
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 160 of file string_consumer.cpp.
References EncodeUtf8(), and PeekUntil().
|
nodiscard |
Peek UTF-8 character.
Definition at line 84 of file string_consumer.cpp.
References DecodeUtf8(), position, and src.
Referenced by PeekUtf8If(), ReadUtf8(), ReadUtf8If(), SkipUtf8(), SkipUtf8If(), and TryReadUtf8().
|
inlinenodiscard |
Check whether the next UTF-8 char matches 'c'.
| c | The character to match. |
true iff the next character is equal to the given character. Definition at line 524 of file string_consumer.hpp.
References PeekUtf8().
Referenced by DecodeEncodedString().
|
inlinenodiscard |
Read the next 'len' bytes, and advance reader.
| len | Bytes to read, 'npos' to read all. |
Definition at line 564 of file string_consumer.hpp.
References LogError(), npos, Peek(), and Skip().
Referenced by DecodeEncodedString(), FormatString(), FileStringReader::HandlePragma(), ReadUntilCharIn(), ReadUntilCharNotIn(), and EncodedString::ReplaceParam().
|
inlinenodiscard |
Read 8-bit character, and advance reader.
| def | Default value to return, if not enough data. |
Definition at line 412 of file string_consumer.hpp.
References PeekChar(), and SkipChar().
Referenced by DumpLine().
|
inlinenodiscard |
Check whether the next 8-bit char matches 'c', and skip it.
| c | The character to match. |
true iff the next character is equal to the given character. Definition at line 506 of file string_consumer.hpp.
References ReadIf().
Referenced by BadgeClassLoadConfigFeature(), and IniLoadFile::LoadFromDisk().
|
inlinenodiscard |
Read next 8-bit char, check whether it is in 'chars', and advance reader.
| chars | The set of characters to find an occurrence for. |
Definition at line 631 of file string_consumer.hpp.
References PeekCharIfIn(), and Skip().
|
inlinenodiscard |
Read next 8-bit char, check whether it is not in 'chars', and advance reader.
| chars | The set of characters to not find an occurrence for. |
Definition at line 664 of file string_consumer.hpp.
References PeekCharIfNotIn(), and Skip().
|
inlinenodiscard |
Check whether the next data matches 'str', and skip it.
| str | String to compare to. |
true iff the next data is equal to the string. Definition at line 477 of file string_consumer.hpp.
References PeekIf(), and Skip().
Referenced by DumpLine(), GetDriverParam(), ClientNetworkContentSocketHandler::OnReceiveData(), ParseIntList(), ParseResolution(), ReadCharIf(), ReadUntil(), SkipIntegerBase(), and SkipUntil().
|
inlinenodiscard |
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.
| base | The base to interpret the string as. |
| def | The default when no valid integer could be parsed. |
| clamp | If the value is a valid number, but out of range for T, return the maximum representable value. Negative values for unsigned results are still treated as invalid. |
Definition at line 961 of file string_consumer.hpp.
References ParseIntegerBase(), and SkipIntegerBase().
Referenced by DecodeEncodedString(), FixSCCEncodedNegative(), FileStringReader::HandlePragma(), StringReader::HandlePragma(), NetworkAddress::IsInNetmask(), ClientNetworkContentSocketHandler::OnReceiveData(), SelectGameWindow::ReadIntroGameViewportCommand(), and EncodedString::ReplaceParam().
|
inlinenodiscard |
Read binary int16 using little endian, and advance reader.
| def | Default value to return, if not enough data. |
Definition at line 238 of file string_consumer.hpp.
References PeekSint16LE(), and SkipSint16LE().
|
inlinenodiscard |
Read binary int32 using little endian, and advance reader.
| def | Default value to return, if not enough data. |
Definition at line 309 of file string_consumer.hpp.
References PeekSint32LE(), and SkipSint32LE().
|
inlinenodiscard |
Read binary int64 using little endian, and advance reader.
| def | Default value to return, if not enough data. |
Definition at line 380 of file string_consumer.hpp.
References PeekSint64LE(), and SkipSint64LE().
|
inlinenodiscard |
Read binary int8, and advance reader.
| def | Default value to return, if not enough data. |
Definition at line 168 of file string_consumer.hpp.
References PeekSint8(), and SkipSint8().
|
inlinenodiscard |
Read binary uint16 using little endian, and advance reader.
| def | Default value to return, if not enough data. |
Definition at line 200 of file string_consumer.hpp.
References PeekUint16LE(), and SkipUint16LE().
Referenced by FormatString(), ProcessNewGRFStringControlCode(), and TranslateTTDPatchCodes().
|
inlinenodiscard |
Read binary uint32 using little endian, and advance reader.
| def | Default value to return, if not enough data. |
Definition at line 271 of file string_consumer.hpp.
References PeekUint32LE(), and SkipUint32LE().
|
inlinenodiscard |
Read binary uint64 using little endian, and advance reader.
| def | Default value to return, if not enough data. |
Definition at line 342 of file string_consumer.hpp.
References PeekUint64LE(), and SkipUint64LE().
|
inlinenodiscard |
Read binary uint8, and advance reader.
| def | Default value to return, if not enough data. |
Definition at line 132 of file string_consumer.hpp.
References PeekUint8(), and SkipUint8().
Referenced by FormatString(), ProcessNewGRFStringControlCode(), and TranslateTTDPatchCodes().
|
inlinenodiscard |
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 764 of file string_consumer.hpp.
References PeekUntil(), ReadIf(), Skip(), SKIP_ALL_SEPARATORS, SKIP_ONE_SEPARATOR, and SkipIf().
Referenced by HasStringInExtensionList(), ReadUntilChar(), and ReadUntilUtf8().
|
inlinenodiscard |
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 820 of file string_consumer.hpp.
References ReadUntil().
Referenced by ConStartAI(), FileStringReader::HandlePragma(), StringReader::HandlePragma(), NetworkAddress::IsInNetmask(), IniLoadFile::LoadFromDisk(), ClientNetworkContentSocketHandler::OnReceiveData(), ParseCompanyManagerFaceCode(), ParseHotkeys(), ParseKeycode(), and ByteReader::ReadString().
|
inlinenodiscard |
Read 8-bit chars, while they are not in 'chars', until they are; and advance reader.
| chars | The set of characters to find an occurrence for. |
Definition at line 695 of file string_consumer.hpp.
References FindCharIn(), and Read().
Referenced by IniLoadFile::LoadFromDisk(), and LookupManyOfMany().
|
inlinenodiscard |
Read 8-bit chars, while they are in 'chars', until they are not; and advance reader.
| chars | The set of characters to not find an occurrence for. |
Definition at line 725 of file string_consumer.hpp.
References FindCharNotIn(), and Read().
Referenced by DumpLine(), and SetDebugString().
|
nodiscard |
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 166 of file string_consumer.cpp.
References EncodeUtf8(), and ReadUntil().
Referenced by DecodeEncodedString(), FixSCCEncodedNegative(), and EncodedString::ReplaceParam().
|
inlinenodiscard |
Read UTF-8 character, and advance reader.
| def | Default value to return, if no valid data. |
Definition at line 444 of file string_consumer.hpp.
References PeekUtf8(), and Skip().
Referenced by DecodeEncodedString(), FormatString(), GetKeyboardLayout(), HandleNewGRFStringControlCodes(), IConsoleAliasExec(), ProcessNewGRFStringControlCode(), SelectGameWindow::ReadIntroGameViewportCommand(), and EncodedString::ReplaceParam().
|
inlinenodiscard |
Check whether the next UTF-8 char matches 'c', and skip it.
| c | The character to match. |
true iff the next character is equal to the given character. Definition at line 534 of file string_consumer.hpp.
References PeekUtf8(), and Skip().
Referenced by FixSCCEncodedNegative(), FormatString(), IConsoleCmdExec(), 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 101 of file string_consumer.cpp.
References GetBytesLeft(), LogError(), position, and src.
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 110 of file string_consumer.hpp.
Referenced by DecodeEncodedString().
|
inline |
Skip 8-bit character, and advance reader.
Definition at line 420 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.
| c | The character to match. |
Definition at line 514 of file string_consumer.hpp.
References SkipIf().
|
inline |
If the next 8-bit char is in 'chars', skip it.
| chars | The set of characters to find an occurrence for. |
Definition at line 641 of file string_consumer.hpp.
References PeekCharIfIn(), and Skip().
|
inline |
If the next 8-bit char is not in 'chars', skip it.
| chars | The set of characters to not find an occurrence for. |
Definition at line 674 of file string_consumer.hpp.
References PeekCharIfNotIn(), and Skip().
|
inline |
If the next data matches 'str', then skip it.
| str | String to compare to. |
Definition at line 487 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.
| base | The base to interpret the string as. |
Definition at line 178 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 248 of file string_consumer.hpp.
References Skip().
Referenced by ReadSint16LE(), and TryReadSint16LE().
|
inline |
Skip binary int32, and advance reader.
Definition at line 319 of file string_consumer.hpp.
References Skip().
Referenced by ReadSint32LE(), and TryReadSint32LE().
|
inline |
Skip binary int64, and advance reader.
Definition at line 390 of file string_consumer.hpp.
References Skip().
Referenced by ReadSint64LE(), and TryReadSint64LE().
|
inline |
Skip binary int8.
Definition at line 177 of file string_consumer.hpp.
References Skip().
Referenced by ReadSint8(), and TryReadSint8().
|
inline |
Skip binary uint16, and advance reader.
Definition at line 210 of file string_consumer.hpp.
References Skip().
Referenced by ProcessNewGRFStringControlCode(), ReadUint16LE(), and TryReadUint16LE().
|
inline |
Skip binary uint32, and advance reader.
Definition at line 281 of file string_consumer.hpp.
References Skip().
Referenced by ReadUint32LE(), and TryReadUint32LE().
|
inline |
Skip binary uint64, and advance reader.
Definition at line 352 of file string_consumer.hpp.
References Skip().
Referenced by ReadUint64LE(), and TryReadUint64LE().
|
inline |
Skip binary uint8.
Definition at line 141 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 786 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 829 of file string_consumer.hpp.
References SkipUntil().
Referenced by ClientNetworkContentSocketHandler::OnReceiveData().
|
inline |
Skip 8-bit chars, while they are not in 'chars', until they are.
| chars | The set of characters to find an occurrence for. |
Definition at line 704 of file string_consumer.hpp.
References FindCharIn(), and Skip().
Referenced by SetDebugString().
|
inline |
Skip 8-bit chars, while they are in 'chars', until they are not.
| chars | The set of characters to not find an occurrence for. |
Definition at line 734 of file string_consumer.hpp.
References FindCharNotIn(), and Skip().
Referenced by IniLoadFile::LoadFromDisk(), 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 172 of file string_consumer.cpp.
References EncodeUtf8(), and SkipUntil().
|
inline |
Skip UTF-8 character, and advance reader.
Definition at line 457 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.
| c | The character to match. |
Definition at line 545 of file string_consumer.hpp.
References PeekUtf8(), and Skip().
Referenced by DecodeEncodedString().
|
inlinenodiscard |
Try to read a 8-bit character, and then advance reader.
Definition at line 401 of file string_consumer.hpp.
References PeekChar(), and SkipChar().
|
inlinenodiscard |
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.
| base | The base to interpret the string as. |
| clamp | If the value is a valid number, but out of range for T, return the maximum representable value. Negative values for unsigned results are still treated as invalid. |
Definition at line 942 of file string_consumer.hpp.
References PeekIntegerBase(), and SkipIntegerBase().
Referenced by BadgeClassLoadConfigFeature(), ConNewGRFProfile(), ConStartAI(), FileList::FindItem(), FixSCCEncodedNegative(), ParseCompanyManagerFaceCode(), ParseInteger(), ParseIntList(), ParseResolution(), OneOfManySettingDesc::ParseSingleValue(), IntSettingDesc::ParseValue(), EncodedString::ReplaceParam(), and SetDebugString().
|
inlinenodiscard |
Try to read binary int16, and then advance reader.
Definition at line 226 of file string_consumer.hpp.
References PeekSint16LE(), and SkipSint16LE().
|
inlinenodiscard |
Try to read binary int32, and then advance reader.
Definition at line 297 of file string_consumer.hpp.
References PeekSint32LE(), and SkipSint32LE().
|
inlinenodiscard |
Try to read binary int64, and then advance reader.
Definition at line 368 of file string_consumer.hpp.
References PeekSint64LE(), and SkipSint64LE().
|
inlinenodiscard |
Try to read binary int8, and then advance reader.
Definition at line 157 of file string_consumer.hpp.
References PeekSint8(), and SkipSint8().
|
inlinenodiscard |
Try to read binary uint16, and then advance reader.
Definition at line 188 of file string_consumer.hpp.
References PeekUint16LE(), and SkipUint16LE().
Referenced by ByteReader::ReadWord().
|
inlinenodiscard |
Try to read binary uint32, and then advance reader.
Definition at line 259 of file string_consumer.hpp.
References PeekUint32LE(), and SkipUint32LE().
Referenced by ByteReader::ReadDWord().
|
inlinenodiscard |
Try to read binary uint64, and then advance reader.
Definition at line 330 of file string_consumer.hpp.
References PeekUint64LE(), and SkipUint64LE().
|
inlinenodiscard |
Try to read binary uint8, and then advance reader.
Definition at line 121 of file string_consumer.hpp.
References PeekUint8(), and SkipUint8().
Referenced by ByteReader::ReadByte().
|
inlinenodiscard |
Try to read a UTF-8 character, and then advance reader.
Definition at line 431 of file string_consumer.hpp.
References PeekUtf8(), and Skip().
Referenced by FixSCCEncoded(), IConsoleAliasExec(), IConsoleCmdExec(), StrMakeValid(), StrValid(), and TranslateTTDPatchCodes().
|
staticconstexpr |
Special value for "end of data".
Definition at line 33 of file string_consumer.hpp.
Referenced by DecodeEncodedString(), FileStringReader::HandlePragma(), ParseCompanyManagerFaceCode(), Read(), and EncodedString::ReplaceParam().
|
private |
The current parsing position in the string.
Definition at line 48 of file string_consumer.hpp.
Referenced by Find(), FindCharIn(), FindCharNotIn(), Peek(), PeekUint16LE(), PeekUint32LE(), PeekUint64LE(), PeekUint8(), PeekUntil(), PeekUtf8(), and Skip().
|
private |
The string to parse.
Definition at line 47 of file string_consumer.hpp.
Referenced by Find(), FindCharIn(), FindCharNotIn(), ParseIntegerBase(), Peek(), PeekUint16LE(), PeekUint32LE(), PeekUint64LE(), PeekUint8(), PeekUntil(), PeekUtf8(), Skip(), StringConsumer(), StringConsumer(), and StringConsumer().
|
static |
ASCII whitespace characters, excluding new-line.
Usable in FindChar(In|NotIn), (Peek|Read|Skip)(If|Until)Char(In|NotIn)
Definition at line 39 of file string_consumer.hpp.
Referenced by ConClientNickChange(), ConsoleAutoCompletion::GetSuggestions(), ParseCode(), ParseInteger(), ParseIntList(), and StrTrimInPlace().
|
static |
ASCII whitespace characters, including new-line.
Usable in FindChar(In|NotIn), (Peek|Read|Skip)(If|Until)Char(In|NotIn)
Definition at line 44 of file string_consumer.hpp.
Referenced by IniLoadFile::LoadFromDisk(), StringReader::ParseFile(), and ReadRawLanguageStrings().