aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-06-02 20:11:29 +0200
committerHampusM <hampus@hampusmat.com>2022-06-13 17:57:00 +0200
commit2d8e52e59af27fc68f4ff5b63d1b53e8d6d4c043 (patch)
treee00b263afb9f3ef7356ec755b60ce03062110628
parentcf3bfd60ad03f2feb2ccc62a12fc2922bdc2fb71 (diff)
refactor: remove conversion & ctre dependency
-rw-r--r--lib/CMakeLists.txt8
-rw-r--r--lib/ctre/CMakeLists.txt4
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/conversion.cpp33
-rw-r--r--src/conversion.hpp34
5 files changed, 0 insertions, 81 deletions
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index df9b253..84c5a77 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -1,14 +1,6 @@
include(FetchContent)
FetchContent_Declare(
- ctre
- GIT_REPOSITORY "https://github.com/hanickadot/compile-time-regular-expressions"
- GIT_TAG v3.5
-)
-
-add_subdirectory(ctre)
-
-FetchContent_Declare(
fmt
GIT_REPOSITORY "https://github.com/fmtlib/fmt"
GIT_TAG 8.1.1
diff --git a/lib/ctre/CMakeLists.txt b/lib/ctre/CMakeLists.txt
deleted file mode 100644
index 1f05163..0000000
--- a/lib/ctre/CMakeLists.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-message(STATUS "Fetching ctre...")
-
-FetchContent_MakeAvailable(ctre)
-
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 76a6d5a..7c7c58f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -11,7 +11,6 @@ endfunction(target_link_libraries_system)
file(GLOB SOURCES
game_of_life.cpp
bootstrap.cpp
- conversion.cpp
util/color.cpp
game/game.cpp
game/status_manager.cpp
@@ -62,7 +61,6 @@ target_include_directories(${PROJECT_NAME} PRIVATE .)
target_link_libraries_system(
${PROJECT_NAME}
- ctre
fmt::fmt-header-only
GSL
yacppdic
diff --git a/src/conversion.cpp b/src/conversion.cpp
deleted file mode 100644
index 078d66b..0000000
--- a/src/conversion.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-#include "conversion.hpp"
-
-#include <climits>
-#include <stdexcept>
-
-auto str_to_uint(const std::string_view &str) noexcept -> ConversionResult<uint32_t>
-{
- if (!ctre::match<IS_VALID_UINT>(str))
- {
- return ConversionResult(false, 0U, "Not a number");
- }
-
- if (!ctre::match<IS_UINT_IN_RANGE>(str))
- {
- return ConversionResult(false, 0U, "Out of range");
- }
-
- std::size_t waste_pos = 0;
-
- auto num = std::stoul(str.data(), &waste_pos, NUMBER_BASE);
-
- if (waste_pos != str.length())
- {
- return ConversionResult(false, 0U, "Not a number");
- }
-
- if (num > UINT_MAX)
- {
- return ConversionResult(false, 0U, "Out of range");
- }
-
- return ConversionResult(true, static_cast<uint32_t>(num));
-}
diff --git a/src/conversion.hpp b/src/conversion.hpp
deleted file mode 100644
index b1f2438..0000000
--- a/src/conversion.hpp
+++ /dev/null
@@ -1,34 +0,0 @@
-#pragma once
-
-#include <ctre.hpp>
-#include <string_view>
-
-constexpr uint32_t NUMBER_BASE = 10U;
-
-template <typename ResultType>
-class ConversionResult
-{
-public:
- explicit ConversionResult(
- const bool &success_,
- const ResultType &result_,
- const std::string_view &fail_reason_ = "") noexcept
- : 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 conversion result
- */
-auto str_to_uint(const std::string_view &str) noexcept -> ConversionResult<uint32_t>;