Skip to content

Commit

Permalink
parseInteger
Browse files Browse the repository at this point in the history
  • Loading branch information
grunt-lucas committed Sep 8, 2023
1 parent fb5efab commit 469b48a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
6 changes: 4 additions & 2 deletions include/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
#include <string>
#include <unordered_map>

#define FMT_HEADER_ONLY
#include <fmt/color.h>

#include "errors_warnings.h"
#include "ptcontext.h"
#include "types.h"

namespace porytiles {

template <typename T> static T parseInteger(const char *integerString)
template <typename T> T parseInteger(const char *integerString)
{
// TODO : rewrite cli_parser::parseIntegralOption to use this function
try {
size_t pos;
T arg = std::stoi(integerString, &pos, 0);
Expand Down
7 changes: 1 addition & 6 deletions src/cli_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ template <typename T>
static T parseIntegralOption(const ErrorsAndWarnings &err, const std::string &optionName, const char *optarg)
{
try {
size_t pos;
T arg = std::stoi(optarg, &pos, 0);
if (std::string{optarg}.size() != pos) {
// throw here so it catches below and prints an error message
throw std::runtime_error{""};
}
T arg = parseInteger<T>(optarg);
return arg;
}
catch (const std::exception &e) {
Expand Down

0 comments on commit 469b48a

Please sign in to comment.