Procházet zdrojové kódy

downloader: Remove duplicated string manipulation methods

These already exist in string_utils.h
rdb před 4 roky
rodič
revize
70e972a7c0

+ 4 - 3
panda/src/downloader/httpAuthorization.cxx

@@ -14,6 +14,7 @@
 #include "httpAuthorization.h"
 #include "httpChannel.h"
 #include "urlSpec.h"
+#include "string_utils.h"
 
 #ifdef HAVE_OPENSSL
 
@@ -126,7 +127,7 @@ parse_authentication_schemes(HTTPAuthorization::AuthenticationSchemes &schemes,
       ++q;
     }
     // Here's our first scheme.
-    string scheme = HTTPChannel::downcase(field_value.substr(p, q - p));
+    string scheme = downcase(field_value.substr(p, q - p));
     Tokens *tokens = &(schemes[scheme]);
 
     // Now pull off the tokens, one at a time.
@@ -139,7 +140,7 @@ parse_authentication_schemes(HTTPAuthorization::AuthenticationSchemes &schemes,
       }
       if (field_value[q] == '=') {
         // This is a token.
-        string token = HTTPChannel::downcase(field_value.substr(p, q - p));
+        string token = downcase(field_value.substr(p, q - p));
         string value;
         p = scan_quoted_or_unquoted_string(value, field_value, q + 1);
         (*tokens)[token] = value;
@@ -152,7 +153,7 @@ parse_authentication_schemes(HTTPAuthorization::AuthenticationSchemes &schemes,
 
       } else {
         // This is not a token; it must be the start of a new scheme.
-        scheme = HTTPChannel::downcase(field_value.substr(p, q - p));
+        scheme = downcase(field_value.substr(p, q - p));
         tokens = &(schemes[scheme]);
         p = q + 1;
       }

+ 0 - 14
panda/src/downloader/httpChannel.cxx

@@ -819,20 +819,6 @@ get_connection() {
   return stream;
 }
 
-/**
- * Returns the input string with all uppercase letters converted to lowercase.
- */
-string HTTPChannel::
-downcase(const string &s) {
-  string result;
-  result.reserve(s.size());
-  string::const_iterator p;
-  for (p = s.begin(); p != s.end(); ++p) {
-    result += tolower(*p);
-  }
-  return result;
-}
-
 /**
  * Called by ISocketStream destructor when _body_stream is destructing.
  */

+ 0 - 1
panda/src/downloader/httpChannel.h

@@ -195,7 +195,6 @@ PUBLISHED:
   INLINE bool is_download_complete() const;
 
 public:
-  static std::string downcase(const std::string &s);
   void body_stream_destructs(ISocketStream *stream);
 
 private:

+ 5 - 23
panda/src/downloader/httpClient.cxx

@@ -31,24 +31,6 @@ using std::string;
 
 PT(HTTPClient) HTTPClient::_global_ptr;
 
-/**
- *
- */
-static string
-trim_blanks(const string &str) {
-  size_t start = 0;
-  while (start < str.length() && isspace(str[start])) {
-    start++;
-  }
-
-  size_t end = str.length();
-  while (end > start && isspace(str[end - 1])) {
-    end--;
-  }
-
-  return str.substr(start, end - start);
-}
-
 #ifndef NDEBUG
 /**
  * This method is attached as a callback for SSL messages only when debug
@@ -318,7 +300,7 @@ void HTTPClient::
 set_proxy_spec(const string &proxy_spec) {
   clear_proxy();
 
-  string trim_proxy_spec = trim_blanks(proxy_spec);
+  string trim_proxy_spec = trim(proxy_spec);
 
   // Tokenize the string based on the semicolons.
   if (!trim_proxy_spec.empty()) {
@@ -336,10 +318,10 @@ set_proxy_spec(const string &proxy_spec) {
       size_t equals = spec.find('=');
       if (equals == string::npos) {
         scheme = "";
-        proxy = trim_blanks(spec);
+        proxy = trim(spec);
       } else {
-        scheme = trim_blanks(spec.substr(0, equals));
-        proxy = trim_blanks(spec.substr(equals + 1));
+        scheme = trim(spec.substr(0, equals));
+        proxy = trim(spec.substr(equals + 1));
       }
 
       if (proxy == "DIRECT" || proxy.empty()) {
@@ -403,7 +385,7 @@ set_direct_host_spec(const string &direct_host_spec) {
   for (vector_string::const_iterator hi = hosts.begin();
        hi != hosts.end();
        ++hi) {
-    string spec = trim_blanks(*hi);
+    string spec = trim(*hi);
 
     // We should be careful to avoid adding any empty hostnames to the list.
     // In particular, we will get one empty hostname if the direct_host_spec

+ 3 - 2
panda/src/downloader/httpDigestAuthorization.cxx

@@ -16,6 +16,7 @@
 #ifdef HAVE_OPENSSL
 
 #include "httpChannel.h"
+#include "string_utils.h"
 #include "openSSLWrapper.h"  // must be included before any other openssl.
 #include <openssl/ssl.h>
 #include <openssl/md5.h>
@@ -50,7 +51,7 @@ HTTPDigestAuthorization(const HTTPAuthorization::Tokens &tokens,
   _algorithm = A_md5;
   ti = tokens.find("algorithm");
   if (ti != tokens.end()) {
-    string algo_str = HTTPChannel::downcase((*ti).second);
+    string algo_str = downcase((*ti).second);
     if (algo_str == "md5") {
       _algorithm = A_md5;
     } else if (algo_str == "md5-sess") {
@@ -63,7 +64,7 @@ HTTPDigestAuthorization(const HTTPAuthorization::Tokens &tokens,
   _qop = 0;
   ti = tokens.find("qop");
   if (ti != tokens.end()) {
-    string qop_str = HTTPChannel::downcase((*ti).second);
+    string qop_str = downcase((*ti).second);
     // A comma-delimited list of tokens.
 
     size_t p = 0;