OpenTTD Source: src/core/string_consumer.hpp File Reference

OpenTTD Source 15.0-RC2

Data Structures | Functions
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>

static 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

  arg | The string to be converted.
  base | The base for parsing the number, defaults to only decimal numbers. Use 0 to also allow hexadecimal.
  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.

Returns
  The number, or std::nullopt if it could not be parsed.

Definition at line 917 of file string_consumer.hpp.

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

Referenced by ConScrollToTile(), IndustryViewWindow::OnQueryTextFinished(), SpriteAlignerWindow::OnQueryTextFinished(), OrdersWindow::OnQueryTextFinished(), CustomCurrencyWindow::OnQueryTextFinished(), ScenarioEditorToolbarWindow::OnQueryTextFinished(), FoundTownWindow::OnQueryTextFinished(), openttd_main(), ParseCompanyManagerFaceCode(), and ParseType().