mirror of
https://github.com/drogonframework/drogon.git
synced 2025-07-19 00:00:43 -04:00
Compare commits
No commits in common. "cb2ae14bdf0883f196e5ac2f673b2584b95c4d6e" and "3c82dcb491a1433be84dc96d9d0a5406371a579d" have entirely different histories.
cb2ae14bdf
...
3c82dcb491
@ -59,13 +59,9 @@ namespace utils
|
|||||||
{
|
{
|
||||||
/// Determine if the string is an integer
|
/// Determine if the string is an integer
|
||||||
DROGON_EXPORT bool isInteger(const std::string &str);
|
DROGON_EXPORT bool isInteger(const std::string &str);
|
||||||
/// Determine if the string is an integer
|
|
||||||
DROGON_EXPORT bool isInteger(string_view str);
|
|
||||||
|
|
||||||
/// Determine if the string is base64 encoded
|
/// Determine if the string is base64 encoded
|
||||||
DROGON_EXPORT bool isBase64(const std::string &str);
|
DROGON_EXPORT bool isBase64(const std::string &str);
|
||||||
/// Determine if the string is base64 encoded
|
|
||||||
DROGON_EXPORT bool isBase64(string_view str);
|
|
||||||
|
|
||||||
/// Generate random a string
|
/// Generate random a string
|
||||||
/**
|
/**
|
||||||
@ -106,10 +102,8 @@ DROGON_EXPORT std::set<std::string> splitStringToSet(
|
|||||||
DROGON_EXPORT std::string getUuid();
|
DROGON_EXPORT std::string getUuid();
|
||||||
|
|
||||||
/// Get the encoded length of base64.
|
/// Get the encoded length of base64.
|
||||||
constexpr size_t base64EncodedLength(unsigned int in_len, bool padded = true)
|
DROGON_EXPORT size_t base64EncodedLength(unsigned int in_len,
|
||||||
{
|
bool padded = true);
|
||||||
return padded ? ((in_len + 3 - 1) / 3) * 4 : (in_len * 8 + 6 - 1) / 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Encode the string to base64 format.
|
/// Encode the string to base64 format.
|
||||||
DROGON_EXPORT std::string base64Encode(const unsigned char *bytes_to_encode,
|
DROGON_EXPORT std::string base64Encode(const unsigned char *bytes_to_encode,
|
||||||
@ -141,10 +135,7 @@ inline std::string base64EncodeUnpadded(string_view data, bool url_safe = false)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the decoded length of base64.
|
/// Get the decoded length of base64.
|
||||||
constexpr size_t base64DecodedLength(unsigned int in_len)
|
DROGON_EXPORT size_t base64DecodedLength(unsigned int in_len);
|
||||||
{
|
|
||||||
return (in_len * 3) / 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Decode the base64 format string.
|
/// Decode the base64 format string.
|
||||||
DROGON_EXPORT std::string base64Decode(string_view encoded_string);
|
DROGON_EXPORT std::string base64Decode(string_view encoded_string);
|
||||||
|
@ -141,16 +141,11 @@ static inline bool isBase64(unsigned char c)
|
|||||||
|
|
||||||
bool isInteger(const std::string &str)
|
bool isInteger(const std::string &str)
|
||||||
{
|
{
|
||||||
for (auto c : str)
|
for (auto const &c : str)
|
||||||
if (c < '0' || c > '9')
|
{
|
||||||
return false;
|
if (c > '9' || c < '0')
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool isInteger(string_view str)
|
|
||||||
{
|
|
||||||
for (auto c : str)
|
|
||||||
if (c < '0' || c > '9')
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,13 +156,6 @@ bool isBase64(const std::string &str)
|
|||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool isBase64(string_view str)
|
|
||||||
{
|
|
||||||
for (auto c : str)
|
|
||||||
if (!isBase64(c))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string genRandomString(int length)
|
std::string genRandomString(int length)
|
||||||
{
|
{
|
||||||
@ -407,6 +395,11 @@ std::string getUuid()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t base64EncodedLength(unsigned int in_len, bool padded)
|
||||||
|
{
|
||||||
|
return padded ? ((in_len + 3 - 1) / 3) * 4 : (in_len * 8 + 6 - 1) / 6;
|
||||||
|
}
|
||||||
|
|
||||||
std::string base64Encode(const unsigned char *bytes_to_encode,
|
std::string base64Encode(const unsigned char *bytes_to_encode,
|
||||||
unsigned int in_len,
|
unsigned int in_len,
|
||||||
bool url_safe,
|
bool url_safe,
|
||||||
@ -467,6 +460,11 @@ std::string base64EncodeUnpadded(const unsigned char *bytes_to_encode,
|
|||||||
return base64Encode(bytes_to_encode, in_len, url_safe, false);
|
return base64Encode(bytes_to_encode, in_len, url_safe, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t base64DecodedLength(unsigned int in_len)
|
||||||
|
{
|
||||||
|
return (in_len * 3) / 4;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<char> base64DecodeToVector(string_view encoded_string)
|
std::vector<char> base64DecodeToVector(string_view encoded_string)
|
||||||
{
|
{
|
||||||
auto in_len = encoded_string.size();
|
auto in_len = encoded_string.size();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user