summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-11-12 21:27:24 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-11-12 21:27:24 +0900
commitdb5cc4db27c0495873c42dbac224ce599b970570 (patch)
tree613ff47bafeb779595fec8cd389e9275146864dd /src
parent5347efb9678c792b38e8525768be92573c663647 (diff)
Don't append character to std::string.
Diffstat (limited to 'src')
-rw-r--r--src/DownloadEngine.cc10
-rw-r--r--src/HttpHeader.cc2
-rw-r--r--src/HttpRequest.cc2
-rw-r--r--src/base64.h28
-rw-r--r--src/bittorrent_helper.cc4
-rw-r--r--src/json.cc65
-rw-r--r--src/paramed_string.h4
-rw-r--r--src/util.cc10
-rw-r--r--src/util.h2
9 files changed, 59 insertions, 68 deletions
diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc
index 9393857f..03250d6c 100644
--- a/src/DownloadEngine.cc
+++ b/src/DownloadEngine.cc
@@ -311,16 +311,12 @@ std::string createSockPoolKey
std::string key;
if(!username.empty()) {
key += util::percentEncode(username);
- key += '@';
+ key += "@";
}
key += host;
- key += A2STR::COLON_C;
- key += util::uitos(port);
+ key += fmt(":%u", port);
if(!proxyhost.empty()) {
- key += A2STR::SLASH_C;
- key += proxyhost;
- key += A2STR::COLON_C;
- key += util::uitos(proxyport);
+ key += fmt("/%s:%u", proxyhost.c_str(), proxyport);
}
return key;
}
diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc
index 29e92cae..ad926cc0 100644
--- a/src/HttpHeader.cc
+++ b/src/HttpHeader.cc
@@ -208,7 +208,7 @@ void HttpHeader::fill
std::string::const_iterator> p = util::stripIter(first, j);
if(!name.empty() && p.first != p.second) {
if(!value.empty()) {
- value += ' ';
+ value += " ";
}
value.append(p.first, p.second);
}
diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc
index 4660d18c..b013b1a7 100644
--- a/src/HttpRequest.cc
+++ b/src/HttpRequest.cc
@@ -313,7 +313,7 @@ std::string HttpRequest::createProxyRequest() const
std::pair<std::string, std::string> HttpRequest::getProxyAuthString() const
{
std::string authText = proxyRequest_->getUsername();
- authText += ':';
+ authText += ":";
authText += proxyRequest_->getPassword();
std::string val = "Basic ";
val += base64::encode(authText.begin(), authText.end());
diff --git a/src/base64.h b/src/base64.h
index b2e08660..1eb93ba2 100644
--- a/src/base64.h
+++ b/src/base64.h
@@ -61,28 +61,32 @@ std::string encode(InputIterator first, InputIterator last)
}
size_t r = len%3;
InputIterator j = last-r;
+ char temp[4];
while(first != j) {
int n = static_cast<unsigned char>(*first++) << 16;
n += static_cast<unsigned char>(*first++) << 8;
n += static_cast<unsigned char>(*first++);
- res += CHAR_TABLE[n >> 18];
- res += CHAR_TABLE[(n >> 12) & 0x3fu];
- res += CHAR_TABLE[(n >> 6) & 0x3fu];
- res += CHAR_TABLE[n & 0x3fu];
+ temp[0] = CHAR_TABLE[n >> 18];
+ temp[1] = CHAR_TABLE[(n >> 12) & 0x3fu];
+ temp[2] = CHAR_TABLE[(n >> 6) & 0x3fu];
+ temp[3] = CHAR_TABLE[n & 0x3fu];
+ res.append(temp, sizeof(temp));
}
if(r == 2) {
int n = static_cast<unsigned char>(*first++) << 16;
n += static_cast<unsigned char>(*first++) << 8;
- res += CHAR_TABLE[n >> 18];
- res += CHAR_TABLE[(n >> 12) & 0x3fu];
- res += CHAR_TABLE[(n >> 6) & 0x3fu];
- res += '=';
+ temp[0] = CHAR_TABLE[n >> 18];
+ temp[1] = CHAR_TABLE[(n >> 12) & 0x3fu];
+ temp[2] = CHAR_TABLE[(n >> 6) & 0x3fu];
+ temp[3] = '=';
+ res.append(temp, sizeof(temp));
} else if(r == 1) {
int n = static_cast<unsigned char>(*first++) << 16;
- res += CHAR_TABLE[n >> 18];
- res += CHAR_TABLE[(n >> 12) & 0x3fu];
- res += '=';
- res += '=';
+ temp[0] = CHAR_TABLE[n >> 18];
+ temp[1] = CHAR_TABLE[(n >> 12) & 0x3fu];
+ temp[2] = '=';
+ temp[3] = '=';
+ res.append(temp, sizeof(temp));
}
return res;
}
diff --git a/src/bittorrent_helper.cc b/src/bittorrent_helper.cc
index 0997270c..fffbde80 100644
--- a/src/bittorrent_helper.cc
+++ b/src/bittorrent_helper.cc
@@ -275,14 +275,14 @@ void extractFileEntries
error_code::BITTORRENT_PARSE_ERROR);
}
}
- std::string utf8Path = strjoin(pathelem.begin(), pathelem.end(), '/',
+ std::string utf8Path = strjoin(pathelem.begin(), pathelem.end(), "/",
std::ptr_fun(util::encodeNonUtf8));
if(util::detectDirTraversal(utf8Path)) {
throw DL_ABORT_EX2(fmt(MSG_DIR_TRAVERSAL_DETECTED, utf8Path.c_str()),
error_code::BITTORRENT_PARSE_ERROR);
}
std::string pePath =
- strjoin(pathelem.begin(), pathelem.end(), '/',
+ strjoin(pathelem.begin(), pathelem.end(), "/",
std::ptr_fun(static_cast<std::string (*)(const std::string&)>
(util::percentEncode)));
std::vector<std::string> uris;
diff --git a/src/json.cc b/src/json.cc
index df3ac534..d3baf4fd 100644
--- a/src/json.cc
+++ b/src/json.cc
@@ -168,12 +168,12 @@ decodeString
checkEof(first, last);
uint16_t codepoint = util::parseUInt(std::string(uchars, first), 16);
if(codepoint <= 0x007fu) {
- s += static_cast<char>(codepoint);
+ unsigned char temp[1] = { static_cast<char>(codepoint) };
+ s.append(&temp[0], &temp[sizeof(temp)]);
} else if(codepoint <= 0x07ffu) {
- unsigned char c2 = 0x80u | (codepoint & 0x003fu);
- unsigned char c1 = 0xC0u | (codepoint >> 6);
- s += c1;
- s += c2;
+ unsigned char temp[2] = { 0xC0u | (codepoint >> 6),
+ 0x80u | (codepoint & 0x003fu) };
+ s.append(&temp[0], &temp[sizeof(temp)]);
} else if(in(codepoint, 0xD800u, 0xDBFFu)) {
// surrogate pair
if(*first != '\\' || first+1 == last ||
@@ -195,36 +195,31 @@ decodeString
uint32_t fullcodepoint = 0x010000u;
fullcodepoint += (codepoint & 0x03FFu) << 10;
fullcodepoint += (codepoint2 & 0x03FFu);
- unsigned char c4 = 0x80u | (fullcodepoint & 0x003Fu);
- unsigned char c3 = 0x80u | ((fullcodepoint >> 6) & 0x003Fu);
- unsigned char c2 = 0x80u | ((fullcodepoint >> 12) & 0x003Fu);
- unsigned char c1 = 0xf0u | (fullcodepoint >> 18);
- s += c1;
- s += c2;
- s += c3;
- s += c4;
+ unsigned char temp[4] = { 0xf0u | (fullcodepoint >> 18),
+ 0x80u | ((fullcodepoint >> 12) & 0x003Fu),
+ 0x80u | ((fullcodepoint >> 6) & 0x003Fu),
+ 0x80u | (fullcodepoint & 0x003Fu) };
+ s.append(&temp[0], &temp[sizeof(temp)]);
} else {
- unsigned char c3 = 0x80u | (codepoint & 0x003Fu);
- unsigned char c2 = 0x80u | ((codepoint >> 6) & 0x003Fu);
- unsigned char c1 = 0xE0u | (codepoint >> 12);
- s += c1;
- s += c2;
- s += c3;
+ unsigned char temp[3] = { 0xE0u | (codepoint >> 12),
+ 0x80u | ((codepoint >> 6) & 0x003Fu),
+ 0x80u | (codepoint & 0x003Fu) };
+ s.append(&temp[0], &temp[sizeof(temp)]);
}
offset = first;
} else {
if(*first == 'b') {
- s += '\b';
+ s += "\b";
} else if(*first == 'f') {
- s += '\f';
+ s += "\f";
} else if(*first == 'n') {
- s += '\n';
+ s += "\n";
} else if(*first == 'r') {
- s += '\r';
+ s += "\r";
} else if(*first == 't') {
- s += '\t';
+ s += "\t";
} else {
- s += *first;
+ s.append(first, first+1);
}
++first;
offset = first;
@@ -278,7 +273,7 @@ decodeNumber
{
std::string s;
if(*first == '-') {
- s += *first;
+ s.append(first, first+1);
++first;
}
std::string::const_iterator offset = first;
@@ -292,7 +287,7 @@ decodeNumber
bool fp = false;
if(*first == '.') {
fp = true;
- s += *first;
+ s.append(first, first+1);
++first;
offset = first;
while(first != last && in(*first, '0', '9')) {
@@ -304,11 +299,11 @@ decodeNumber
}
if(*first == 'e') {
fp = true;
- s += *first;
+ s.append(first, first+1);
++first;
checkEof(first, last);
if(*first == '+' || *first == '-') {
- s += *first;
+ s.append(first, first+1);
++first;
}
offset = first;
@@ -488,7 +483,7 @@ std::string jsonEscape(const std::string& s)
for(std::string::const_iterator i = s.begin(), eoi = s.end(); i != eoi;
++i) {
if(*i == '"' || *i == '\\' || *i == '/') {
- t += '\\';
+ t += "\\";
t += *i;
} else if(*i == '\b') {
t += "\\b";
@@ -515,7 +510,7 @@ std::string jsonEscape(const std::string& s)
}
t += temp;
} else {
- t += *i;
+ t.append(i, i+1);
}
}
return t;
@@ -574,22 +569,22 @@ decodeGetParams(const std::string& query)
// Assume batch call.
jsonRequest = jsonParam;
} else {
- jsonRequest = '{';
+ jsonRequest = "{";
if(method.first != method.second) {
jsonRequest += "\"method\":\"";
jsonRequest.append(method.first, method.second);
- jsonRequest += '"';
+ jsonRequest += "\"";
}
if(id.first != id.second) {
jsonRequest += ",\"id\":\"";
jsonRequest.append(id.first, id.second);
- jsonRequest += '"';
+ jsonRequest += "\"";
}
if(params.first != params.second) {
jsonRequest += ",\"params\":";
jsonRequest += jsonParam;
}
- jsonRequest += '}';
+ jsonRequest += "}";
}
}
return JsonGetParam(jsonRequest, callback);
diff --git a/src/paramed_string.h b/src/paramed_string.h
index 7ebee8cd..89726f1b 100644
--- a/src/paramed_string.h
+++ b/src/paramed_string.h
@@ -127,9 +127,7 @@ InputIterator expandLoop
if(start <= end) {
std::string format;
if(minus-first == colon-minus-1) {
- format = "%0";
- format += util::uitos(minus-first);
- format += 'd';
+ format = fmt("%%0%lud", minus-first);
} else {
format = "%d";
}
diff --git a/src/util.cc b/src/util.cc
index d6320beb..c625c37e 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -1415,20 +1415,18 @@ bool inPrivateAddress(const std::string& ipv4addr)
{
static const char A2_IP10[] = "10.";
static const char A2_IP192[] = "192.168.";
+ static const char A2_IP172[] = "172.";
if(util::startsWith(ipv4addr.begin(), ipv4addr.end(),
A2_IP10, vend(A2_IP10)-1) ||
util::startsWith(ipv4addr.begin(), ipv4addr.end(),
A2_IP192, vend(A2_IP192)-1)) {
return true;
}
- std::string p172("172.");
if(util::startsWith(ipv4addr.begin(), ipv4addr.end(),
- p172.begin(), p172.end())) {
+ A2_IP172, vend(A2_IP172)-1)) {
for(int i = 16; i <= 31; ++i) {
- std::string t(p172);
- t += util::itos(i);
- t += '.';
- if(util::startsWith(ipv4addr.begin(), ipv4addr.end(),
+ std::string t(fmt("%d.", i));
+ if(util::startsWith(ipv4addr.begin()+4, ipv4addr.end(),
t.begin(), t.end())) {
return true;
}
diff --git a/src/util.h b/src/util.h
index 7a9cdb3a..1c357cb3 100644
--- a/src/util.h
+++ b/src/util.h
@@ -141,7 +141,7 @@ std::string uitos(T value, bool comma = false)
++count;
char digit = value%10+'0';
if(comma && count > 3 && count%3 == 1) {
- str += ',';
+ str += ",";
}
str += digit;
value /= 10;