OpenTTD Source 20260206-master-g4d4e37dbf1
string_consumer.hpp File Reference

Parse strings. More...

#include <charconv>
#include "format.hpp"

Go to the source code of this file.

Data Structures

class  StringConsumer
 Parse data from a string / buffer. More...

Functions

template<class T = uint32_t>
static std::optional< T > ParseInteger (std::string_view arg, int base=10, bool clamp=false)
 Change a string into its number representation.

Detailed Description

Parse strings.

Definition in file string_consumer.hpp.

Function Documentation

◆ ParseInteger()

template<class T = uint32_t>
std::optional< T > ParseInteger ( std::string_view arg,
int base = 10,
bool clamp = false )
inlinestatic

Change a string into its number representation.

Supports decimal and hexadecimal numbers. Accepts leading and trailing whitespace. Trailing junk is an error.

Parameters
argThe string to be converted.
baseThe base for parsing the number, defaults to only decimal numbers. Use 0 to also allow hexadecimal.
clampIf 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.
Returns
The number, or std::nullopt if it could not be parsed.

Definition at line 919 of file string_consumer.hpp.

References StringConsumer::AnyBytesLeft(), StringConsumer::SkipUntilCharNotIn(), StringConsumer::TryReadIntegerBase(), and StringConsumer::WHITESPACE_NO_NEWLINE.

Referenced by TarScanner::AddFile(), ScriptInfo::AddLabels(), ConScrollToTile(), ConZoomToLevel(), GetDriverParamInt(), GetSavegameFormat(), GraphicsSetLoadConfig(), CheatWindow::OnQueryTextFinished(), CompanyWindow::OnQueryTextFinished(), CreateScenarioWindow::OnQueryTextFinished(), CustomCurrencyWindow::OnQueryTextFinished(), FoundTownWindow::OnQueryTextFinished(), GameOptionsWindow::OnQueryTextFinished(), GenerateLandscapeWindow::OnQueryTextFinished(), GSConfigWindow::OnQueryTextFinished(), IndustryViewWindow::OnQueryTextFinished(), NetworkStartServerWindow::OnQueryTextFinished(), NewGRFInspectWindow::OnQueryTextFinished(), NewGRFParametersWindow::OnQueryTextFinished(), OrdersWindow::OnQueryTextFinished(), ScenarioEditorToolbarWindow::OnQueryTextFinished(), ScriptSettingsWindow::OnQueryTextFinished(), SpriteAlignerWindow::OnQueryTextFinished(), TimetableWindow::OnQueryTextFinished(), openttd_main(), ParseCompanyManagerFaceCode(), ParseType(), and SelectGameWindow::ReadIntroGameViewportCommand().