Optimization on the tolower function

This commit is contained in:
Felipe Zimmerle 2016-01-07 09:16:06 -03:00
parent 0762892368
commit 8c7b6199f7
2 changed files with 10 additions and 7 deletions

View File

@ -433,12 +433,13 @@ int Assay::addRequestHeader(const std::string& key,
this->m_collections.store("REQUEST_HEADERS:" + key, value);
if (tolower(key) == tolower("Authorization")) {
std::string keyl = tolower(key);
if (keyl == "authorization") {
std::vector<std::string> type = split(value, ' ');
this->m_collections.store("AUTH_TYPE", type[0]);
}
if (tolower(key) == "cookie") {
if (keyl == "cookie") {
std::vector<std::string> cookies = split(value, ';');
while (cookies.empty() == false) {
std::vector<std::string> s = split(cookies.back(), '=');
@ -461,7 +462,7 @@ int Assay::addRequestHeader(const std::string& key,
*
*/
if (tolower(key) == "content-type") {
if (keyl == "content-type") {
std::string multipart("multipart/form-data");
std::string l = tolower(value);

View File

@ -25,7 +25,7 @@
#include <stdint.h>
#include <inttypes.h>
#include <algorithm>
#include <random>
#include <memory>
#include <functional>
@ -126,10 +126,12 @@ void chomp(std::string *str) {
std::string tolower(std::string str) {
std::locale loc;
std::string value;
value.resize(str.length());
for (std::string::size_type i=0; i < str.length(); ++i) {
value.assign(value + std::tolower(str[i], loc));
}
std::transform(str.begin(),
str.end(),
value.begin(),
::tolower);
return value;
}