mirror of
https://github.com/drogonframework/drogon.git
synced 2025-07-17 00:00:35 -04:00
Compare commits
2 Commits
3c82dcb491
...
cb2ae14bdf
Author | SHA1 | Date | |
---|---|---|---|
|
cb2ae14bdf | ||
|
34a5c37974 |
@ -59,9 +59,13 @@ 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
|
||||||
/**
|
/**
|
||||||
@ -102,8 +106,10 @@ 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.
|
||||||
DROGON_EXPORT size_t base64EncodedLength(unsigned int in_len,
|
constexpr size_t base64EncodedLength(unsigned int in_len, bool padded = true)
|
||||||
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,
|
||||||
@ -135,7 +141,10 @@ inline std::string base64EncodeUnpadded(string_view data, bool url_safe = false)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the decoded length of base64.
|
/// Get the decoded length of base64.
|
||||||
DROGON_EXPORT size_t base64DecodedLength(unsigned int in_len);
|
constexpr 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,11 +141,16 @@ static inline bool isBase64(unsigned char c)
|
|||||||
|
|
||||||
bool isInteger(const std::string &str)
|
bool isInteger(const std::string &str)
|
||||||
{
|
{
|
||||||
for (auto const &c : str)
|
for (auto c : str)
|
||||||
{
|
if (c < '0' || c > '9')
|
||||||
if (c > '9' || c < '0')
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool isInteger(string_view str)
|
||||||
|
{
|
||||||
|
for (auto c : str)
|
||||||
|
if (c < '0' || c > '9')
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,6 +161,13 @@ 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)
|
||||||
{
|
{
|
||||||
@ -395,11 +407,6 @@ 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,
|
||||||
@ -460,11 +467,6 @@ 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