From de247f7d332fef45b22b49108af20d8ed635c161 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 28 Nov 2015 00:31:42 +0900 Subject: [PATCH] src: Rename startsWith as starts_with --- src/asio_server_serve_mux.cc | 2 +- src/http2.cc | 4 ++-- src/shrpx.cc | 10 +++++----- src/shrpx_config.cc | 6 +++--- src/shrpx_ssl.cc | 4 ++-- src/util.cc | 6 +++--- src/util.h | 26 +++++++++++++------------- src/util_test.cc | 16 ++++++++-------- 8 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/asio_server_serve_mux.cc b/src/asio_server_serve_mux.cc index d2b43925..b635ee4d 100644 --- a/src/asio_server_serve_mux.cc +++ b/src/asio_server_serve_mux.cc @@ -108,7 +108,7 @@ bool path_match(const std::string &pattern, const std::string &path) { if (pattern.back() != '/') { return pattern == path; } - return util::startsWith(path, pattern); + return util::starts_with(path, pattern); } } // namespace diff --git a/src/http2.cc b/src/http2.cc index 6faaeddf..671b1a92 100644 --- a/src/http2.cc +++ b/src/http2.cc @@ -454,8 +454,8 @@ std::string rewrite_location_uri(const std::string &uri, return ""; } auto field = &u.field_data[UF_HOST]; - if (!util::startsWith(std::begin(match_host), std::end(match_host), - &uri[field->off], &uri[field->off] + field->len) || + if (!util::starts_with(std::begin(match_host), std::end(match_host), + &uri[field->off], &uri[field->off] + field->len) || (match_host.size() != field->len && match_host[field->len] != ':')) { return ""; } diff --git a/src/shrpx.cc b/src/shrpx.cc index ab9e673a..a83062f3 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -325,11 +325,11 @@ void exec_binary(SignalServer *ssv) { } for (size_t i = 0; i < envlen; ++i) { - if (util::startsWith(environ[i], ENV_LISTENER4_FD) || - util::startsWith(environ[i], ENV_LISTENER6_FD) || - util::startsWith(environ[i], ENV_PORT) || - util::startsWith(environ[i], ENV_UNIX_FD) || - util::startsWith(environ[i], ENV_UNIX_PATH)) { + if (util::starts_with(environ[i], ENV_LISTENER4_FD) || + util::starts_with(environ[i], ENV_LISTENER6_FD) || + util::starts_with(environ[i], ENV_PORT) || + util::starts_with(environ[i], ENV_UNIX_FD) || + util::starts_with(environ[i], ENV_UNIX_PATH)) { continue; } diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index c6b88721..c9b229eb 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -519,7 +519,7 @@ std::vector parse_log_format(const char *optarg) { auto type = log_var_lookup_token(var_name, var_namelen); if (type == SHRPX_LOGF_NONE) { - if (util::istartsWith(var_name, var_namelen, "http_")) { + if (util::istarts_with(var_name, var_namelen, "http_")) { if (util::streq("host", var_name + str_size("http_"), var_namelen - str_size("http_"))) { // Special handling of host header field. We will use @@ -1342,7 +1342,7 @@ int parse_config(const char *opt, const char *optarg, pat_delim = optarg + optarglen; } DownstreamAddr addr; - if (util::istartsWith(optarg, SHRPX_UNIX_PATH_PREFIX)) { + if (util::istarts_with(optarg, SHRPX_UNIX_PATH_PREFIX)) { auto path = optarg + str_size(SHRPX_UNIX_PATH_PREFIX); addr.host = strcopy(path, pat_delim); addr.host_unix = true; @@ -1368,7 +1368,7 @@ int parse_config(const char *opt, const char *optarg, return 0; } case SHRPX_OPTID_FRONTEND: { - if (util::istartsWith(optarg, SHRPX_UNIX_PATH_PREFIX)) { + if (util::istarts_with(optarg, SHRPX_UNIX_PATH_PREFIX)) { auto path = optarg + str_size(SHRPX_UNIX_PATH_PREFIX); mod_config()->host = strcopy(path); mod_config()->port = 0; diff --git a/src/shrpx_ssl.cc b/src/shrpx_ssl.cc index 8c4b4166..b3cf2537 100644 --- a/src/shrpx_ssl.cc +++ b/src/shrpx_ssl.cc @@ -792,7 +792,7 @@ bool tls_hostname_match(const char *pattern, const char *hostname) { // Don't attempt to match a presented identifier where the wildcard // character is embedded within an A-label. if (ptLeftLabelEnd == 0 || strchr(ptLeftLabelEnd + 1, '.') == 0 || - ptLeftLabelEnd < ptWildcard || util::istartsWith(pattern, "xn--")) { + ptLeftLabelEnd < ptWildcard || util::istarts_with(pattern, "xn--")) { wildcardEnabled = false; } if (!wildcardEnabled) { @@ -807,7 +807,7 @@ bool tls_hostname_match(const char *pattern, const char *hostname) { if (hnLeftLabelEnd - hostname < ptLeftLabelEnd - pattern) { return false; } - return util::istartsWith(hostname, hnLeftLabelEnd, pattern, ptWildcard) && + return util::istarts_with(hostname, hnLeftLabelEnd, pattern, ptWildcard) && util::iendsWith(hostname, hnLeftLabelEnd, ptWildcard + 1, ptLeftLabelEnd); } diff --git a/src/util.cc b/src/util.cc index 8dd84b1e..5d884b3c 100644 --- a/src/util.cc +++ b/src/util.cc @@ -353,7 +353,7 @@ void streq_advance(const char **ap, const char **bp) { } } // namespace -bool istartsWith(const char *a, const char *b) { +bool istarts_with(const char *a, const char *b) { if (!a || !b) { return false; } @@ -509,8 +509,8 @@ void show_candidates(const char *unkopt, option *options) { for (size_t i = 0; options[i].name != nullptr; ++i) { auto optnamelen = strlen(options[i].name); // Use cost 0 for prefix match - if (istartsWith(options[i].name, options[i].name + optnamelen, unkopt, - unkopt + unkoptlen)) { + if (istarts_with(options[i].name, options[i].name + optnamelen, unkopt, + unkopt + unkoptlen)) { if (optnamelen == static_cast(unkoptlen)) { // Exact match, then we don't show any condidates. return; diff --git a/src/util.h b/src/util.h index b2e62171..7fcc7817 100644 --- a/src/util.h +++ b/src/util.h @@ -169,20 +169,20 @@ inline char lowcase(char c) { } template -bool startsWith(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2) { +bool starts_with(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2) { if (last1 - first1 < last2 - first2) { return false; } return std::equal(first2, last2, first1); } -inline bool startsWith(const std::string &a, const std::string &b) { - return startsWith(std::begin(a), std::end(a), std::begin(b), std::end(b)); +inline bool starts_with(const std::string &a, const std::string &b) { + return starts_with(std::begin(a), std::end(a), std::begin(b), std::end(b)); } -inline bool startsWith(const char *a, const char *b) { - return startsWith(a, a + strlen(a), b, b + strlen(b)); +inline bool starts_with(const char *a, const char *b) { + return starts_with(a, a + strlen(a), b, b + strlen(b)); } struct CaseCmp { @@ -192,24 +192,24 @@ struct CaseCmp { }; template -bool istartsWith(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2) { +bool istarts_with(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2) { if (last1 - first1 < last2 - first2) { return false; } return std::equal(first2, last2, first1, CaseCmp()); } -inline bool istartsWith(const std::string &a, const std::string &b) { - return istartsWith(std::begin(a), std::end(a), std::begin(b), std::end(b)); +inline bool istarts_with(const std::string &a, const std::string &b) { + return istarts_with(std::begin(a), std::end(a), std::begin(b), std::end(b)); } template -bool istartsWith(InputIt a, size_t an, const char *b) { - return istartsWith(a, a + an, b, b + strlen(b)); +bool istarts_with(InputIt a, size_t an, const char *b) { + return istarts_with(a, a + an, b, b + strlen(b)); } -bool istartsWith(const char *a, const char *b); +bool istarts_with(const char *a, const char *b); template bool endsWith(InputIterator1 first1, InputIterator1 last1, diff --git a/src/util_test.cc b/src/util_test.cc index 77542017..19cdbf90 100644 --- a/src/util_test.cc +++ b/src/util_test.cc @@ -344,15 +344,15 @@ void test_util_format_duration(void) { } void test_util_starts_with(void) { - CU_ASSERT(util::startsWith("foo", "foo")); - CU_ASSERT(util::startsWith("fooo", "foo")); - CU_ASSERT(util::startsWith("ofoo", "")); - CU_ASSERT(!util::startsWith("ofoo", "foo")); + CU_ASSERT(util::starts_with("foo", "foo")); + CU_ASSERT(util::starts_with("fooo", "foo")); + CU_ASSERT(util::starts_with("ofoo", "")); + CU_ASSERT(!util::starts_with("ofoo", "foo")); - CU_ASSERT(util::istartsWith("FOO", "fOO")); - CU_ASSERT(util::startsWith("ofoo", "")); - CU_ASSERT(util::istartsWith("fOOo", "Foo")); - CU_ASSERT(!util::istartsWith("ofoo", "foo")); + CU_ASSERT(util::istarts_with("FOO", "fOO")); + CU_ASSERT(util::starts_with("ofoo", "")); + CU_ASSERT(util::istarts_with("fOOo", "Foo")); + CU_ASSERT(!util::istarts_with("ofoo", "foo")); } void test_util_ends_with(void) {