diff --git a/src/http2.h b/src/http2.h index 7fa42b37..aaf076d6 100644 --- a/src/http2.h +++ b/src/http2.h @@ -340,7 +340,8 @@ std::string normalize_path(InputIt first, InputIt last) { } else { for (; first < last - 2;) { if (*first == '%') { - if (util::isHexDigit(*(first + 1)) && util::isHexDigit(*(first + 2))) { + if (util::is_hex_digit(*(first + 1)) && + util::is_hex_digit(*(first + 2))) { auto c = (util::hex_to_uint(*(first + 1)) << 4) + util::hex_to_uint(*(first + 2)); if (util::in_rfc3986_unreserved_chars(c)) { diff --git a/src/shrpx_client_handler.cc b/src/shrpx_client_handler.cc index 47818894..8ace9d4a 100644 --- a/src/shrpx_client_handler.cc +++ b/src/shrpx_client_handler.cc @@ -859,13 +859,13 @@ ssize_t parse_proxy_line_port(const uint8_t *first, const uint8_t *last) { } if (*p == '0') { - if (p + 1 != last && util::isDigit(*(p + 1))) { + if (p + 1 != last && util::is_digit(*(p + 1))) { return -1; } return 1; } - for (; p != last && util::isDigit(*p); ++p) { + for (; p != last && util::is_digit(*p); ++p) { port *= 10; port += *p - '0'; diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index c9b229eb..565d3118 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -471,7 +471,7 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) { namespace { bool var_token(char c) { - return util::isAlpha(c) || util::isDigit(c) || c == '_'; + return util::is_alpha(c) || util::is_digit(c) || c == '_'; } } // namespace diff --git a/src/util.cc b/src/util.cc index 2962e152..90ace89a 100644 --- a/src/util.cc +++ b/src/util.cc @@ -67,7 +67,7 @@ const char UPPER_XDIGITS[] = "0123456789ABCDEF"; bool in_rfc3986_unreserved_chars(const char c) { static constexpr const char unreserved[] = {'-', '.', '_', '~'}; - return isAlpha(c) || isDigit(c) || + return is_alpha(c) || is_digit(c) || std::find(std::begin(unreserved), std::end(unreserved), c) != std::end(unreserved); } @@ -120,7 +120,7 @@ bool in_token(char c) { static constexpr const char extra[] = {'!', '#', '$', '%', '&', '\'', '*', '+', '-', '.', '^', '_', '`', '|', '~'}; - return isAlpha(c) || isDigit(c) || + return is_alpha(c) || is_digit(c) || std::find(std::begin(extra), std::end(extra), c) != std::end(extra); } diff --git a/src/util.h b/src/util.h index a4468bcb..9319e7cd 100644 --- a/src/util.h +++ b/src/util.h @@ -64,14 +64,14 @@ constexpr const char NGHTTP2_H1_1[] = "http/1.1"; namespace util { -inline bool isAlpha(const char c) { +inline bool is_alpha(const char c) { return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'); } -inline bool isDigit(const char c) { return '0' <= c && c <= '9'; } +inline bool is_digit(const char c) { return '0' <= c && c <= '9'; } -inline bool isHexDigit(const char c) { - return isDigit(c) || ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f'); +inline bool is_hex_digit(const char c) { + return is_digit(c) || ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f'); } bool in_rfc3986_unreserved_chars(const char c); @@ -84,7 +84,7 @@ bool in_token(char c); bool in_attr_char(char c); // Returns integer corresponding to hex notation |c|. It is undefined -// if isHexDigit(c) is false. +// if is_hex_digit(c) is false. uint32_t hex_to_uint(char c); std::string percent_encode(const unsigned char *target, size_t len); @@ -99,8 +99,8 @@ std::string percent_decode(InputIt first, InputIt last) { std::string result; for (; first != last; ++first) { if (*first == '%') { - if (first + 1 != last && first + 2 != last && isHexDigit(*(first + 1)) && - isHexDigit(*(first + 2))) { + if (first + 1 != last && first + 2 != last && + is_hex_digit(*(first + 1)) && is_hex_digit(*(first + 2))) { result += (hex_to_uint(*(first + 1)) << 4) + hex_to_uint(*(first + 2)); first += 2; continue;