Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functions for parsing and validating configuration options #9953

Open
dbaston opened this issue May 16, 2024 · 2 comments
Open

Add functions for parsing and validating configuration options #9953

dbaston opened this issue May 16, 2024 · 2 comments
Assignees
Labels
code enhancements Code enhancements (generally developer-only visible) enhancement

Comments

@dbaston
Copy link
Member

dbaston commented May 16, 2024

Feature description

It would be helpful to have functions to validate numeric and boolean configuration options passed as strings. Boolean parsing with CPLTestBool is interprets unexpected values to mean "false" (such as an enthusiastic "YESSS"). Similarly, atoi and atofare used for integer/floating point values but there may be cases where want to fail rather than overflow or accept a default value of zero.

Possible signature patterns:

std::optional<T> read(std::string_view)
bool read(const char*, T*)
int CPLGetIntegerConfigOption(const char* pszOptName, int nDefaultValue, bool* pbValid, bool* pbHasBeenUserSpecified = nullptr, int nMin = INT_MIN, int nMax = INT_MAX)

std::from_chars is a nice way to do implement this but it does not support floating point types even in many recent compiler versions (https://en.cppreference.com/w/cpp/compiler_support/17#C.2B.2B17_library_features)

Some previous discussion: #9924 (comment)

Additional context

No response

@dbaston dbaston added enhancement code enhancements Code enhancements (generally developer-only visible) labels May 16, 2024
@rouault
Copy link
Member

rouault commented May 16, 2024

cf CPLGetValueType() : https://gdal.org/api/cpl.html#_CPPv415CPLGetValueTypePKc

@dbaston
Copy link
Member Author

dbaston commented May 16, 2024

I see that from_chars is also available from the vendored fast_float.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code enhancements Code enhancements (generally developer-only visible) enhancement
Projects
None yet
Development

No branches or pull requests

2 participants