Code format

This commit is contained in:
yhirose 2020-12-19 20:14:53 -05:00
parent 40db42108f
commit e9c6c6e609
2 changed files with 59 additions and 65 deletions

View File

@ -192,6 +192,7 @@ using socket_t = int;
#include <fcntl.h> #include <fcntl.h>
#include <fstream> #include <fstream>
#include <functional> #include <functional>
#include <iomanip>
#include <iostream> #include <iostream>
#include <list> #include <list>
#include <map> #include <map>
@ -203,7 +204,6 @@ using socket_t = int;
#include <string> #include <string>
#include <sys/stat.h> #include <sys/stat.h>
#include <thread> #include <thread>
#include <iomanip>
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
#include <openssl/err.h> #include <openssl/err.h>
@ -1457,26 +1457,19 @@ inline bool is_valid_path(const std::string &path) {
return true; return true;
} }
inline std::string encode_query_param(const std::string &value){ inline std::string encode_query_param(const std::string &value) {
std::ostringstream escaped; std::ostringstream escaped;
escaped.fill('0'); escaped.fill('0');
escaped << std::hex; escaped << std::hex;
for (char const &c: value) { for (char const &c : value) {
if (std::isalnum(c) || if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '!' ||
c == '-' || c == '~' || c == '*' || c == '\'' || c == '(' || c == ')') {
c == '_' ||
c == '.' ||
c == '!' ||
c == '~' ||
c == '*' ||
c == '\'' ||
c == '(' ||
c == ')') {
escaped << c; escaped << c;
} else { } else {
escaped << std::uppercase; escaped << std::uppercase;
escaped << '%' << std::setw(2) << static_cast<int>(static_cast<unsigned char>(c)); escaped << '%' << std::setw(2)
<< static_cast<int>(static_cast<unsigned char>(c));
escaped << std::nouppercase; escaped << std::nouppercase;
} }
} }
@ -2175,9 +2168,9 @@ inline unsigned int str2tag(const std::string &s) {
namespace udl { namespace udl {
inline constexpr unsigned int operator"" _(const char *s, size_t l) { inline constexpr unsigned int operator"" _(const char *s, size_t l) {
return str2tag_core(s, l, 0); return str2tag_core(s, l, 0);
} }
} // namespace udl } // namespace udl

View File

@ -46,16 +46,17 @@ TEST(StartupTest, WSAStartup) {
} }
#endif #endif
TEST(EncodeQueryParamTest, ParseUnescapedChararactersTest){ TEST(EncodeQueryParamTest, ParseUnescapedChararactersTest) {
string unescapedCharacters = "-_.!~*'()"; string unescapedCharacters = "-_.!~*'()";
EXPECT_EQ(detail::encode_query_param(unescapedCharacters), "-_.!~*'()"); EXPECT_EQ(detail::encode_query_param(unescapedCharacters), "-_.!~*'()");
} }
TEST(EncodeQueryParamTest, ParseReservedCharactersTest){ TEST(EncodeQueryParamTest, ParseReservedCharactersTest) {
string reservedCharacters = ";,/?:@&=+$"; string reservedCharacters = ";,/?:@&=+$";
EXPECT_EQ(detail::encode_query_param(reservedCharacters), "%3B%2C%2F%3F%3A%40%26%3D%2B%24"); EXPECT_EQ(detail::encode_query_param(reservedCharacters),
"%3B%2C%2F%3F%3A%40%26%3D%2B%24");
} }
TEST(TrimTests, TrimStringTests) { TEST(TrimTests, TrimStringTests) {