src: Rename startsWith as starts_with

This commit is contained in:
Tatsuhiro Tsujikawa 2015-11-28 00:31:42 +09:00
parent 1ba28bef1f
commit de247f7d33
8 changed files with 37 additions and 37 deletions

View File

@ -108,7 +108,7 @@ bool path_match(const std::string &pattern, const std::string &path) {
if (pattern.back() != '/') { if (pattern.back() != '/') {
return pattern == path; return pattern == path;
} }
return util::startsWith(path, pattern); return util::starts_with(path, pattern);
} }
} // namespace } // namespace

View File

@ -454,7 +454,7 @@ std::string rewrite_location_uri(const std::string &uri,
return ""; return "";
} }
auto field = &u.field_data[UF_HOST]; auto field = &u.field_data[UF_HOST];
if (!util::startsWith(std::begin(match_host), std::end(match_host), if (!util::starts_with(std::begin(match_host), std::end(match_host),
&uri[field->off], &uri[field->off] + field->len) || &uri[field->off], &uri[field->off] + field->len) ||
(match_host.size() != field->len && match_host[field->len] != ':')) { (match_host.size() != field->len && match_host[field->len] != ':')) {
return ""; return "";

View File

@ -325,11 +325,11 @@ void exec_binary(SignalServer *ssv) {
} }
for (size_t i = 0; i < envlen; ++i) { for (size_t i = 0; i < envlen; ++i) {
if (util::startsWith(environ[i], ENV_LISTENER4_FD) || if (util::starts_with(environ[i], ENV_LISTENER4_FD) ||
util::startsWith(environ[i], ENV_LISTENER6_FD) || util::starts_with(environ[i], ENV_LISTENER6_FD) ||
util::startsWith(environ[i], ENV_PORT) || util::starts_with(environ[i], ENV_PORT) ||
util::startsWith(environ[i], ENV_UNIX_FD) || util::starts_with(environ[i], ENV_UNIX_FD) ||
util::startsWith(environ[i], ENV_UNIX_PATH)) { util::starts_with(environ[i], ENV_UNIX_PATH)) {
continue; continue;
} }

View File

@ -519,7 +519,7 @@ std::vector<LogFragment> parse_log_format(const char *optarg) {
auto type = log_var_lookup_token(var_name, var_namelen); auto type = log_var_lookup_token(var_name, var_namelen);
if (type == SHRPX_LOGF_NONE) { 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_"), if (util::streq("host", var_name + str_size("http_"),
var_namelen - str_size("http_"))) { var_namelen - str_size("http_"))) {
// Special handling of host header field. We will use // 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; pat_delim = optarg + optarglen;
} }
DownstreamAddr addr; 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); auto path = optarg + str_size(SHRPX_UNIX_PATH_PREFIX);
addr.host = strcopy(path, pat_delim); addr.host = strcopy(path, pat_delim);
addr.host_unix = true; addr.host_unix = true;
@ -1368,7 +1368,7 @@ int parse_config(const char *opt, const char *optarg,
return 0; return 0;
} }
case SHRPX_OPTID_FRONTEND: { 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); auto path = optarg + str_size(SHRPX_UNIX_PATH_PREFIX);
mod_config()->host = strcopy(path); mod_config()->host = strcopy(path);
mod_config()->port = 0; mod_config()->port = 0;

View File

@ -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 // Don't attempt to match a presented identifier where the wildcard
// character is embedded within an A-label. // character is embedded within an A-label.
if (ptLeftLabelEnd == 0 || strchr(ptLeftLabelEnd + 1, '.') == 0 || if (ptLeftLabelEnd == 0 || strchr(ptLeftLabelEnd + 1, '.') == 0 ||
ptLeftLabelEnd < ptWildcard || util::istartsWith(pattern, "xn--")) { ptLeftLabelEnd < ptWildcard || util::istarts_with(pattern, "xn--")) {
wildcardEnabled = false; wildcardEnabled = false;
} }
if (!wildcardEnabled) { if (!wildcardEnabled) {
@ -807,7 +807,7 @@ bool tls_hostname_match(const char *pattern, const char *hostname) {
if (hnLeftLabelEnd - hostname < ptLeftLabelEnd - pattern) { if (hnLeftLabelEnd - hostname < ptLeftLabelEnd - pattern) {
return false; return false;
} }
return util::istartsWith(hostname, hnLeftLabelEnd, pattern, ptWildcard) && return util::istarts_with(hostname, hnLeftLabelEnd, pattern, ptWildcard) &&
util::iendsWith(hostname, hnLeftLabelEnd, ptWildcard + 1, util::iendsWith(hostname, hnLeftLabelEnd, ptWildcard + 1,
ptLeftLabelEnd); ptLeftLabelEnd);
} }

View File

@ -353,7 +353,7 @@ void streq_advance(const char **ap, const char **bp) {
} }
} // namespace } // namespace
bool istartsWith(const char *a, const char *b) { bool istarts_with(const char *a, const char *b) {
if (!a || !b) { if (!a || !b) {
return false; return false;
} }
@ -509,7 +509,7 @@ void show_candidates(const char *unkopt, option *options) {
for (size_t i = 0; options[i].name != nullptr; ++i) { for (size_t i = 0; options[i].name != nullptr; ++i) {
auto optnamelen = strlen(options[i].name); auto optnamelen = strlen(options[i].name);
// Use cost 0 for prefix match // Use cost 0 for prefix match
if (istartsWith(options[i].name, options[i].name + optnamelen, unkopt, if (istarts_with(options[i].name, options[i].name + optnamelen, unkopt,
unkopt + unkoptlen)) { unkopt + unkoptlen)) {
if (optnamelen == static_cast<size_t>(unkoptlen)) { if (optnamelen == static_cast<size_t>(unkoptlen)) {
// Exact match, then we don't show any condidates. // Exact match, then we don't show any condidates.

View File

@ -169,7 +169,7 @@ inline char lowcase(char c) {
} }
template <typename InputIterator1, typename InputIterator2> template <typename InputIterator1, typename InputIterator2>
bool startsWith(InputIterator1 first1, InputIterator1 last1, bool starts_with(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2) { InputIterator2 first2, InputIterator2 last2) {
if (last1 - first1 < last2 - first2) { if (last1 - first1 < last2 - first2) {
return false; return false;
@ -177,12 +177,12 @@ bool startsWith(InputIterator1 first1, InputIterator1 last1,
return std::equal(first2, last2, first1); return std::equal(first2, last2, first1);
} }
inline bool startsWith(const std::string &a, const std::string &b) { inline bool starts_with(const std::string &a, const std::string &b) {
return startsWith(std::begin(a), std::end(a), std::begin(b), std::end(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) { inline bool starts_with(const char *a, const char *b) {
return startsWith(a, a + strlen(a), b, b + strlen(b)); return starts_with(a, a + strlen(a), b, b + strlen(b));
} }
struct CaseCmp { struct CaseCmp {
@ -192,7 +192,7 @@ struct CaseCmp {
}; };
template <typename InputIterator1, typename InputIterator2> template <typename InputIterator1, typename InputIterator2>
bool istartsWith(InputIterator1 first1, InputIterator1 last1, bool istarts_with(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2) { InputIterator2 first2, InputIterator2 last2) {
if (last1 - first1 < last2 - first2) { if (last1 - first1 < last2 - first2) {
return false; return false;
@ -200,16 +200,16 @@ bool istartsWith(InputIterator1 first1, InputIterator1 last1,
return std::equal(first2, last2, first1, CaseCmp()); return std::equal(first2, last2, first1, CaseCmp());
} }
inline bool istartsWith(const std::string &a, const std::string &b) { inline bool istarts_with(const std::string &a, const std::string &b) {
return istartsWith(std::begin(a), std::end(a), std::begin(b), std::end(b)); return istarts_with(std::begin(a), std::end(a), std::begin(b), std::end(b));
} }
template <typename InputIt> template <typename InputIt>
bool istartsWith(InputIt a, size_t an, const char *b) { bool istarts_with(InputIt a, size_t an, const char *b) {
return istartsWith(a, a + an, b, b + strlen(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 <typename InputIterator1, typename InputIterator2> template <typename InputIterator1, typename InputIterator2>
bool endsWith(InputIterator1 first1, InputIterator1 last1, bool endsWith(InputIterator1 first1, InputIterator1 last1,

View File

@ -344,15 +344,15 @@ void test_util_format_duration(void) {
} }
void test_util_starts_with(void) { void test_util_starts_with(void) {
CU_ASSERT(util::startsWith("foo", "foo")); CU_ASSERT(util::starts_with("foo", "foo"));
CU_ASSERT(util::startsWith("fooo", "foo")); CU_ASSERT(util::starts_with("fooo", "foo"));
CU_ASSERT(util::startsWith("ofoo", "")); CU_ASSERT(util::starts_with("ofoo", ""));
CU_ASSERT(!util::startsWith("ofoo", "foo")); CU_ASSERT(!util::starts_with("ofoo", "foo"));
CU_ASSERT(util::istartsWith("FOO", "fOO")); CU_ASSERT(util::istarts_with("FOO", "fOO"));
CU_ASSERT(util::startsWith("ofoo", "")); CU_ASSERT(util::starts_with("ofoo", ""));
CU_ASSERT(util::istartsWith("fOOo", "Foo")); CU_ASSERT(util::istarts_with("fOOo", "Foo"));
CU_ASSERT(!util::istartsWith("ofoo", "foo")); CU_ASSERT(!util::istarts_with("ofoo", "foo"));
} }
void test_util_ends_with(void) { void test_util_ends_with(void) {