From 90e31b7cf8c9946f7b85f37a6225c1e04bfc595b Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Mon, 27 Feb 2023 17:26:48 +0100 Subject: [PATCH] Updated to new esp-idf --- CMakeLists.txt | 1 - src/color_utils.cpp | 4 ++-- src/color_utils.h | 6 ++---- src/cpptypesafeenum.h | 6 +++--- src/numberparsing.h | 44 +++++++++++++++++++++---------------------- src/strutils.cpp | 14 +++++++------- src/strutils.h | 6 ++---- 7 files changed, 38 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a526d6..083f9df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,6 @@ set(sources ) set(dependencies - expected fmt ) diff --git a/src/color_utils.cpp b/src/color_utils.cpp index 11b2169..2db8c86 100644 --- a/src/color_utils.cpp +++ b/src/color_utils.cpp @@ -12,7 +12,7 @@ std::string toString(ColorHelper color) return fmt::format("#{:02X}{:02X}{:02X}", color.r, color.g, color.b); } -tl::expected parseColor(std::string_view str) +std::expected parseColor(std::string_view str) { // input may be "#FFF" or "#FFFFFF" or "#FFFFFFFF" @@ -27,7 +27,7 @@ tl::expected parseColor(std::string_view str) return helper; } - return tl::make_unexpected(fmt::format("invalid color {}", str)); + return std::unexpected(fmt::format("invalid color {}", str)); } } // namespace cpputils diff --git a/src/color_utils.h b/src/color_utils.h index 75457ff..d1c2485 100644 --- a/src/color_utils.h +++ b/src/color_utils.h @@ -4,9 +4,7 @@ #include #include #include - -// 3rdparty lib includes -#include +#include namespace cpputils { struct ColorHelper @@ -53,7 +51,7 @@ struct HsvColor }; std::string toString(ColorHelper color); -tl::expected parseColor(std::string_view str); +std::expected parseColor(std::string_view str); inline uint32_t colorToNumber(ColorHelper color) { diff --git a/src/cpptypesafeenum.h b/src/cpptypesafeenum.h index eb6858f..8606681 100644 --- a/src/cpptypesafeenum.h +++ b/src/cpptypesafeenum.h @@ -2,9 +2,9 @@ // system includes #include +#include // 3rdparty lib includes -#include #include // local includes @@ -32,12 +32,12 @@ } \ return fmt::format("Unknown " #Name "({})", int(value)); \ } \ - inline tl::expected parse##Name(std::string_view str) \ + inline std::expected parse##Name(std::string_view str) \ { \ using TheEnum = Name; \ if (false) {} \ Values(DECLARE_TYPESAFE_ENUM_HELPER3) \ - return tl::make_unexpected(fmt::format("invalid " #Name " ({})", str)); \ + return std::unexpected(fmt::format("invalid " #Name " ({})", str)); \ } \ template \ void iterate##Name(T &&cb) \ diff --git a/src/numberparsing.h b/src/numberparsing.h index ee61d67..17205aa 100644 --- a/src/numberparsing.h +++ b/src/numberparsing.h @@ -5,93 +5,93 @@ #include #include #include +#include // 3rdparty lib includes -#include #include namespace cpputils { -template tl::expected fromString(std::string_view str) = delete; +template std::expected fromString(std::string_view str) = delete; -template<> inline tl::expected fromString(std::string_view str) +template<> inline std::expected fromString(std::string_view str) { int8_t val; if (std::sscanf(str.data(), "%" SCNi8, &val) != 1) - return tl::make_unexpected(fmt::format("invalid int8_t {}", str)); + return std::unexpected(fmt::format("invalid int8_t {}", str)); return val; } -template<> inline tl::expected fromString(std::string_view str) +template<> inline std::expected fromString(std::string_view str) { uint8_t val; if (std::sscanf(str.data(), "%" SCNu8, &val) != 1) - return tl::make_unexpected(fmt::format("invalid uint8_t {}", str)); + return std::unexpected(fmt::format("invalid uint8_t {}", str)); return val; } -template<> inline tl::expected fromString(std::string_view str) +template<> inline std::expected fromString(std::string_view str) { int16_t val; if (std::sscanf(str.data(), "%" SCNi16, &val) != 1) - return tl::make_unexpected(fmt::format("invalid int16_t {}", str)); + return std::unexpected(fmt::format("invalid int16_t {}", str)); return val; } -template<> inline tl::expected fromString(std::string_view str) +template<> inline std::expected fromString(std::string_view str) { uint16_t val; if (std::sscanf(str.data(), "%" SCNu16, &val) != 1) - return tl::make_unexpected(fmt::format("invalid uint16_t {}", str)); + return std::unexpected(fmt::format("invalid uint16_t {}", str)); return val; } -template<> inline tl::expected fromString(std::string_view str) +template<> inline std::expected fromString(std::string_view str) { int32_t val; if (std::sscanf(str.data(), "%" SCNi32, &val) != 1) - return tl::make_unexpected(fmt::format("invalid int32_t {}", str)); + return std::unexpected(fmt::format("invalid int32_t {}", str)); return val; } -template<> inline tl::expected fromString(std::string_view str) +template<> inline std::expected fromString(std::string_view str) { uint32_t val; if (std::sscanf(str.data(), "%" SCNu32, &val) != 1) - return tl::make_unexpected(fmt::format("invalid uint32_t {}", str)); + return std::unexpected(fmt::format("invalid uint32_t {}", str)); return val; } #ifdef ESP_PLATFORM -template<> inline tl::expected fromString(std::string_view str) +template<> inline std::expected fromString(std::string_view str) { int val; if (std::sscanf(str.data(), "%i", &val) != 1) - return tl::make_unexpected(fmt::format("invalid int {}", str)); + return std::unexpected(fmt::format("invalid int {}", str)); return val; } -template<> inline tl::expected fromString(std::string_view str) +template<> inline std::expected fromString(std::string_view str) { unsigned int val; if (std::sscanf(str.data(), "%u", &val) != 1) - return tl::make_unexpected(fmt::format("invalid unsigned int {}", str)); + return std::unexpected(fmt::format("invalid unsigned int {}", str)); return val; } #endif -template<> inline tl::expected fromString(std::string_view str) +template<> inline std::expected fromString(std::string_view str) { int64_t val; if (std::sscanf(str.data(), "%" SCNi64, &val) != 1) - return tl::make_unexpected(fmt::format("invalid int64_t {}", str)); + return std::unexpected(fmt::format("invalid int64_t {}", str)); return val; } -template<> inline tl::expected fromString(std::string_view str) +template<> inline std::expected fromString(std::string_view str) { uint64_t val; if (std::sscanf(str.data(), "%" SCNu64, &val) != 1) - return tl::make_unexpected(fmt::format("invalid uint64_t {}", str)); + return std::unexpected(fmt::format("invalid uint64_t {}", str)); return val; } } // namespace cpputils diff --git a/src/strutils.cpp b/src/strutils.cpp index e0c2204..633524e 100644 --- a/src/strutils.cpp +++ b/src/strutils.cpp @@ -9,7 +9,7 @@ namespace cpputils { namespace { -tl::expected sodium_bin2hex(char * const hex, const size_t hex_maxlen, +std::expected sodium_bin2hex(char * const hex, const size_t hex_maxlen, const unsigned char * const bin, const size_t bin_len) __attribute__ ((nonnull(1))); } // namespace @@ -32,10 +32,10 @@ std::string toHexString(std::basic_string_view buf) return hex; } -tl::expected, std::string> fromHexString(std::string_view hex) +std::expected, std::string> fromHexString(std::string_view hex) { if (hex.size() % 2 != 0) - return tl::make_unexpected("hex length not even"); + return std::unexpected("hex length not even"); std::basic_string result; result.reserve(hex.size() / 2); @@ -56,7 +56,7 @@ tl::expected, std::string> fromHexString(std::s case 'A'...'F': nibbles.nibble0 = c - 'A' + 10; break; case 'a'...'f': nibbles.nibble0 = c - 'a' + 10; break; default: - return tl::make_unexpected(fmt::format("invalid character {} at pos {}", c, std::distance(std::begin(hex), iter))); + return std::unexpected(fmt::format("invalid character {} at pos {}", c, std::distance(std::begin(hex), iter))); } iter++; @@ -67,7 +67,7 @@ tl::expected, std::string> fromHexString(std::s case 'A'...'F': nibbles.nibble1 = c - 'A' + 10; break; case 'a'...'f': nibbles.nibble1 = c - 'a' + 10; break; default: - return tl::make_unexpected(fmt::format("invalid character {} at pos {}", c, std::distance(std::begin(hex), iter))); + return std::unexpected(fmt::format("invalid character {} at pos {}", c, std::distance(std::begin(hex), iter))); } iter++; @@ -275,7 +275,7 @@ std::optional getStringBetween(std::string_view search, std::s namespace { /* Derived from original code by CodesInChaos */ -tl::expected +std::expected sodium_bin2hex(char *const hex, const size_t hex_maxlen, const unsigned char *const bin, const size_t bin_len) { @@ -285,7 +285,7 @@ sodium_bin2hex(char *const hex, const size_t hex_maxlen, int c; if (bin_len >= SIZE_MAX / 2 || hex_maxlen <= bin_len * 2U) { - return tl::make_unexpected("misuse because bin_len >= SIZE_MAX / 2 || hex_maxlen <= bin_len * 2U"); + return std::unexpected("misuse because bin_len >= SIZE_MAX / 2 || hex_maxlen <= bin_len * 2U"); } while (i < bin_len) { c = bin[i] & 0xf; diff --git a/src/strutils.h b/src/strutils.h index f18a3b5..f21a4f6 100644 --- a/src/strutils.h +++ b/src/strutils.h @@ -6,9 +6,7 @@ #include #include #include - -// 3rdparty lib includes -#include +#include namespace cpputils { inline std::string toString(bool val) { return val ? "true" : "false"; } @@ -46,7 +44,7 @@ inline std::string toHexString(std::string_view str) return toHexString(std::basic_string_view{reinterpret_cast(str.data()), str.size()}); } -tl::expected, std::string> fromHexString(std::string_view hex); +std::expected, std::string> fromHexString(std::string_view hex); std::string toBase64String(std::basic_string_view buf); inline std::string toBase64String(std::string_view str)