From 6fa7c79169445933eb0a9fc25983a573ceca4562 Mon Sep 17 00:00:00 2001 From: SEK1RO Date: Wed, 11 Sep 2024 17:35:07 +0300 Subject: [PATCH] feat(baseN): isValid char * overloading --- include/base/baseN.hpp | 1 + src/baseN.cpp | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/base/baseN.hpp b/include/base/baseN.hpp index 66fca92..831aba9 100644 --- a/include/base/baseN.hpp +++ b/include/base/baseN.hpp @@ -6,6 +6,7 @@ namespace baseN { + bool isValid(const char *str, const int8_t *map) noexcept; bool isValid(const std::string &str, const int8_t *map) noexcept; std::string encode(std::vector data, uint8_t base, uint64_t enc_size, const char *digits) noexcept; std::vector decode(const std::string &str, uint8_t base, uint64_t dec_size, const char *digits, const int8_t *map); diff --git a/src/baseN.cpp b/src/baseN.cpp index 2c5b498..a6df33a 100644 --- a/src/baseN.cpp +++ b/src/baseN.cpp @@ -4,17 +4,23 @@ namespace baseN { - bool isValid(const std::string &str, const int8_t *map) noexcept + bool isValid(const char *str, const int8_t *map) noexcept { - for (int64_t i = str.size() - 1; i >= 0; i--) + uint8_t i = 0; + while (str[i] != '\0') { if (map[(int8_t)str[i]] == -1) { return false; } + i++; } return true; } + bool isValid(const std::string &str, const int8_t *map) noexcept + { + return baseN::isValid(str.data(), map); + } std::string encode(std::vector data, uint8_t base, uint64_t enc_size, const char *digits) noexcept { if (data.size() == 0)