From 41654be16d5ed188f5e2c0e1d8889c68283ef8ac Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 8 Aug 2016 15:01:18 +0300 Subject: Sort out case conversion, ignore case comparison --- bpkg/manifest.cxx | 44 +++++--------------------------------------- 1 file changed, 5 insertions(+), 39 deletions(-) diff --git a/bpkg/manifest.cxx b/bpkg/manifest.cxx index ce36b9b..86ca7fa 100644 --- a/bpkg/manifest.cxx +++ b/bpkg/manifest.cxx @@ -17,6 +17,7 @@ #include #include +#include // casecmp(), lcase(), alpha(), digit() #include #include @@ -47,18 +48,6 @@ namespace bpkg } inline static bool - digit (char c) noexcept - { - return c >= '0' && c <= '9'; - } - - inline static bool - alpha (char c) noexcept - { - return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); - } - - inline static bool valid_sha256 (const string& s) noexcept { if (s.size () != 64) @@ -73,15 +62,6 @@ namespace bpkg return true; } - // Replace std::tolower to keep things locale independent. - // - inline static char - lowercase (char c) noexcept - { - const unsigned char shift ('a' - 'A'); - return c >= 'A' && c <='Z' ? c + shift : c; - } - // Resize v up to ';', return what goes after ';'. // inline static string @@ -249,10 +229,7 @@ namespace bpkg zo = stoul (c) == 0; } else - { - for (const char* i (begin); i != end; ++i) - append (1, lowercase (*i)); - } + append (lcase (begin, end - begin)); if (!zo) len_ = size (); @@ -1385,21 +1362,10 @@ namespace bpkg { using protocol = url_parts::protocol; - // Check if the location starts with the specified schema. The argument - // must be in the lower case (we don't use str[n]casecmp() since it's not - // portable). - // - auto schema = [&location](const char* s) -> bool - { - size_t i (0); - for (; s[i] != '\0' && s[i] == lowercase (location[i]); ++i) ; - return s[i] == '\0'; - }; - optional p; - if (schema ("http://")) + if (casecmp (location, "http://", 7) == 0) p = protocol::http; - else if (schema ("https://")) + else if (casecmp (location, "https://", 8) == 0) p = protocol::https; return p; @@ -1450,7 +1416,7 @@ namespace bpkg transform (s.cbegin () + host_offset, p == string::npos ? s.cend () : s.cbegin () + p, back_inserter (host), - lowercase); + static_cast (lcase)); // Validate host name according to "2.3.1. Preferred name syntax" and // "2.3.4. Size limits" of https://tools.ietf.org/html/rfc1035. -- cgit v1.1