mirror of
https://github.com/sametersoylu/argument-parser.git
synced 2026-04-13 03:41:18 +00:00
feat: Introduce core argument parsing framework with platform-specific parsers, conventions, and type-based value parsing.
This commit is contained in:
28
src/source/parser/parsing_traits/traits.cpp
Normal file
28
src/source/parser/parsing_traits/traits.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "traits.hpp"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace argument_parser::parsing_traits {
|
||||
std::string parser_trait<std::string>::parse(const std::string &input) {
|
||||
return input;
|
||||
}
|
||||
|
||||
bool parser_trait<bool>::parse(const std::string &input) {
|
||||
if (input == "t" || input == "true" || input == "1")
|
||||
return true;
|
||||
if (input == "f" || input == "false" || input == "0")
|
||||
return false;
|
||||
throw std::runtime_error("Invalid boolean value: " + input);
|
||||
}
|
||||
|
||||
int parser_trait<int>::parse(const std::string &input) {
|
||||
return std::stoi(input);
|
||||
}
|
||||
|
||||
float parser_trait<float>::parse(const std::string &input) {
|
||||
return std::stof(input);
|
||||
}
|
||||
|
||||
double parser_trait<double>::parse(const std::string &input) {
|
||||
return std::stod(input);
|
||||
}
|
||||
} // namespace argument_parser::parsing_traits
|
||||
Reference in New Issue
Block a user