feat(baseN): isValid char * overloading
This commit is contained in:
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
namespace baseN
|
namespace baseN
|
||||||
{
|
{
|
||||||
|
bool isValid(const char *str, const int8_t *map) noexcept;
|
||||||
bool isValid(const std::string &str, const int8_t *map) noexcept;
|
bool isValid(const std::string &str, const int8_t *map) noexcept;
|
||||||
std::string encode(std::vector<uint8_t> data, uint8_t base, uint64_t enc_size, const char *digits) noexcept;
|
std::string encode(std::vector<uint8_t> data, uint8_t base, uint64_t enc_size, const char *digits) noexcept;
|
||||||
std::vector<uint8_t> decode(const std::string &str, uint8_t base, uint64_t dec_size, const char *digits, const int8_t *map);
|
std::vector<uint8_t> decode(const std::string &str, uint8_t base, uint64_t dec_size, const char *digits, const int8_t *map);
|
||||||
|
|||||||
@ -4,17 +4,23 @@
|
|||||||
|
|
||||||
namespace baseN
|
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)
|
if (map[(int8_t)str[i]] == -1)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
bool isValid(const std::string &str, const int8_t *map) noexcept
|
||||||
|
{
|
||||||
|
return baseN::isValid(str.data(), map);
|
||||||
|
}
|
||||||
std::string encode(std::vector<uint8_t> data, uint8_t base, uint64_t enc_size, const char *digits) noexcept
|
std::string encode(std::vector<uint8_t> data, uint8_t base, uint64_t enc_size, const char *digits) noexcept
|
||||||
{
|
{
|
||||||
if (data.size() == 0)
|
if (data.size() == 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user