Updated to new esp-idf
This commit is contained in:
@ -24,7 +24,6 @@ set(sources
|
||||
)
|
||||
|
||||
set(dependencies
|
||||
expected
|
||||
fmt
|
||||
)
|
||||
|
||||
|
@ -12,7 +12,7 @@ std::string toString(ColorHelper color)
|
||||
return fmt::format("#{:02X}{:02X}{:02X}", color.r, color.g, color.b);
|
||||
}
|
||||
|
||||
tl::expected<ColorHelper, std::string> parseColor(std::string_view str)
|
||||
std::expected<ColorHelper, std::string> parseColor(std::string_view str)
|
||||
{
|
||||
// input may be "#FFF" or "#FFFFFF" or "#FFFFFFFF"
|
||||
|
||||
@ -27,7 +27,7 @@ tl::expected<ColorHelper, std::string> 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
|
||||
|
@ -4,9 +4,7 @@
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <array>
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <tl/expected.hpp>
|
||||
#include <expected>
|
||||
|
||||
namespace cpputils {
|
||||
struct ColorHelper
|
||||
@ -53,7 +51,7 @@ struct HsvColor
|
||||
};
|
||||
|
||||
std::string toString(ColorHelper color);
|
||||
tl::expected<ColorHelper, std::string> parseColor(std::string_view str);
|
||||
std::expected<ColorHelper, std::string> parseColor(std::string_view str);
|
||||
|
||||
inline uint32_t colorToNumber(ColorHelper color)
|
||||
{
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
// system includes
|
||||
#include <string>
|
||||
#include <expected>
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <tl/expected.hpp>
|
||||
#include <fmt/core.h>
|
||||
|
||||
// local includes
|
||||
@ -32,12 +32,12 @@
|
||||
} \
|
||||
return fmt::format("Unknown " #Name "({})", int(value)); \
|
||||
} \
|
||||
inline tl::expected<Name, std::string> parse##Name(std::string_view str) \
|
||||
inline std::expected<Name, std::string> 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<typename T> \
|
||||
void iterate##Name(T &&cb) \
|
||||
|
@ -5,93 +5,93 @@
|
||||
#include <cstdio>
|
||||
#include <inttypes.h>
|
||||
#include <string>
|
||||
#include <expected>
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <tl/expected.hpp>
|
||||
#include <fmt/format.h>
|
||||
|
||||
namespace cpputils {
|
||||
template<typename T> tl::expected<T, std::string> fromString(std::string_view str) = delete;
|
||||
template<typename T> std::expected<T, std::string> fromString(std::string_view str) = delete;
|
||||
|
||||
template<> inline tl::expected<int8_t, std::string> fromString<int8_t>(std::string_view str)
|
||||
template<> inline std::expected<int8_t, std::string> fromString<int8_t>(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<uint8_t, std::string> fromString<uint8_t>(std::string_view str)
|
||||
template<> inline std::expected<uint8_t, std::string> fromString<uint8_t>(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<int16_t, std::string> fromString<int16_t>(std::string_view str)
|
||||
template<> inline std::expected<int16_t, std::string> fromString<int16_t>(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<uint16_t, std::string> fromString<uint16_t>(std::string_view str)
|
||||
template<> inline std::expected<uint16_t, std::string> fromString<uint16_t>(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<int32_t, std::string> fromString<int32_t>(std::string_view str)
|
||||
template<> inline std::expected<int32_t, std::string> fromString<int32_t>(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<uint32_t, std::string> fromString<uint32_t>(std::string_view str)
|
||||
template<> inline std::expected<uint32_t, std::string> fromString<uint32_t>(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<int, std::string> fromString<int>(std::string_view str)
|
||||
template<> inline std::expected<int, std::string> fromString<int>(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<unsigned int, std::string> fromString<unsigned int>(std::string_view str)
|
||||
template<> inline std::expected<unsigned int, std::string> fromString<unsigned int>(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<int64_t, std::string> fromString<int64_t>(std::string_view str)
|
||||
template<> inline std::expected<int64_t, std::string> fromString<int64_t>(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<uint64_t, std::string> fromString<uint64_t>(std::string_view str)
|
||||
template<> inline std::expected<uint64_t, std::string> fromString<uint64_t>(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
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
namespace cpputils {
|
||||
namespace {
|
||||
tl::expected<char *, std::string> sodium_bin2hex(char * const hex, const size_t hex_maxlen,
|
||||
std::expected<char *, std::string> 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<unsigned char> buf)
|
||||
return hex;
|
||||
}
|
||||
|
||||
tl::expected<std::basic_string<unsigned char>, std::string> fromHexString(std::string_view hex)
|
||||
std::expected<std::basic_string<unsigned char>, 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<unsigned char> result;
|
||||
result.reserve(hex.size() / 2);
|
||||
@ -56,7 +56,7 @@ tl::expected<std::basic_string<unsigned char>, 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::basic_string<unsigned char>, 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<std::string_view> getStringBetween(std::string_view search, std::s
|
||||
|
||||
namespace {
|
||||
/* Derived from original code by CodesInChaos */
|
||||
tl::expected<char *, std::string>
|
||||
std::expected<char *, std::string>
|
||||
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;
|
||||
|
@ -6,9 +6,7 @@
|
||||
#include <string_view>
|
||||
#include <random>
|
||||
#include <algorithm>
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <tl/expected.hpp>
|
||||
#include <expected>
|
||||
|
||||
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<unsigned char>{reinterpret_cast<const unsigned char *>(str.data()), str.size()});
|
||||
}
|
||||
|
||||
tl::expected<std::basic_string<unsigned char>, std::string> fromHexString(std::string_view hex);
|
||||
std::expected<std::basic_string<unsigned char>, std::string> fromHexString(std::string_view hex);
|
||||
|
||||
std::string toBase64String(std::basic_string_view<unsigned char> buf);
|
||||
inline std::string toBase64String(std::string_view str)
|
||||
|
Reference in New Issue
Block a user