aboutsummaryrefslogtreecommitdiff
path: root/src/conversion.hpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-02-25 18:16:40 +0100
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:53 +0200
commite233dc28491c33e8a7dc0a11576d3b8ce91cce2c (patch)
tree40551d581baf43690eda5e0c3a7d083998136031 /src/conversion.hpp
parentd36ec4670770022c0ec8337f6df4de292ca941db (diff)
refactor: delete exception usages & game options
Diffstat (limited to 'src/conversion.hpp')
-rw-r--r--src/conversion.hpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/conversion.hpp b/src/conversion.hpp
index 4ae5b7c..0bdf82d 100644
--- a/src/conversion.hpp
+++ b/src/conversion.hpp
@@ -1,13 +1,32 @@
#pragma once
+#include <ctre.hpp>
#include <string_view>
constexpr unsigned int NUMBER_BASE = 10U;
+template <typename ResultType>
+class ConversionResult
+{
+public:
+ explicit ConversionResult(const bool &success_, const ResultType &result_,
+ const std::string_view &fail_reason_ = "")
+ : success(success_), result(result_), fail_reason(fail_reason_)
+ {
+ }
+
+ const bool &success;
+ const ResultType &result;
+ const std::string_view &fail_reason;
+};
+
+static constexpr auto IS_VALID_UINT = ctll::fixed_string("^[0-9]+$");
+static constexpr auto IS_UINT_IN_RANGE = ctll::fixed_string("^[0-9]{1,19}$");
+
/**
* Converts a string to a unsigned integer.
*
* @param str A string that possibly is a unsigned integer
- * @returns A unsigned integer
+ * @returns A conversion result
*/
-unsigned int str_to_uint(const std::string_view &str);
+ConversionResult<unsigned int> str_to_uint(const std::string_view &str);