Removed strconcat

pull/4/head
Tatsuhiro Tsujikawa 2011-11-12 18:17:34 +09:00
parent c4e66390ac
commit 2e5d9b056f
30 changed files with 160 additions and 195 deletions

View File

@ -51,7 +51,10 @@ AuthConfig::~AuthConfig() {}
std::string AuthConfig::getAuthText() const
{
return strconcat(user_, ":", password_);
std::string s = user_;
s += ":";
s += password_;
return s;
}
std::ostream& operator<<(std::ostream& o, const AuthConfigHandle& authConfig)

View File

@ -119,7 +119,10 @@ size_t BtBitfieldMessage::getMessageLength() {
}
std::string BtBitfieldMessage::toString() const {
return strconcat(NAME, " ", util::toHex(bitfield_, bitfieldLength_));
std::string s = NAME;
s += " ";
s += util::toHex(bitfield_, bitfieldLength_);
return s;
}
} // namespace aria2

View File

@ -90,7 +90,10 @@ bool BtExtendedMessage::sendPredicate() const
}
std::string BtExtendedMessage::toString() const {
return strconcat(NAME, " ", extensionMessage_->toString());
std::string s = NAME;
s += " ";
s += extensionMessage_->toString();
return s;
}
BtExtendedMessageHandle

View File

@ -103,10 +103,13 @@ size_t BtHandshakeMessage::getMessageLength() {
}
std::string BtHandshakeMessage::toString() const {
return strconcat(NAME, " peerId=",
util::percentEncode(peerId_, PEER_ID_LENGTH),
", reserved=",
util::toHex(reserved_, RESERVED_LENGTH));
char buf[256];
snprintf(buf, sizeof(buf),
"%s peerId=%s, reserved=%s",
NAME.c_str(),
util::percentEncode(peerId_, PEER_ID_LENGTH).c_str(),
util::toHex(reserved_, RESERVED_LENGTH).c_str());
return buf;
}
bool BtHandshakeMessage::isFastExtensionSupported() const {

View File

@ -213,8 +213,13 @@ void BtPieceMessage::pushPieceData(off_t offset, size_t length) const
std::string BtPieceMessage::toString() const
{
return strconcat(NAME, " index=", util::itos(index_), ", begin=",
util::itos(begin_), ", length=", util::itos(blockLength_));
char buf[256];
snprintf(buf, sizeof(buf), "%s index=%lu, begin=%u, length=%lu",
NAME.c_str(),
static_cast<unsigned long>(index_),
begin_,
static_cast<unsigned long>(blockLength_));
return buf;
}
bool BtPieceMessage::checkPieceHash(const SharedHandle<Piece>& piece)

View File

@ -118,7 +118,9 @@ size_t BtPortMessage::getMessageLength() {
}
std::string BtPortMessage::toString() const {
return strconcat(NAME, " port=", util::uitos(port_));
char buf[256];
snprintf(buf, sizeof(buf), "%s port=%u", NAME.c_str(), port_);
return buf;
}
void BtPortMessage::setLocalNode(DHTNode* localNode)

View File

@ -110,7 +110,10 @@ Cookie& Cookie::operator=(const Cookie& c)
std::string Cookie::toString() const
{
return strconcat(name_, '=', value_);
std::string s = name_;
s += "=";
s += value_;
return s;
}
bool Cookie::match

View File

@ -129,9 +129,13 @@ void DHTAnnouncePeerMessage::setTokenTracker(DHTTokenTracker* tokenTracker)
std::string DHTAnnouncePeerMessage::toStringOptional() const
{
return strconcat("token=", util::toHex(token_),
", info_hash=", util::toHex(infoHash_, INFO_HASH_LENGTH),
", tcpPort=", util::uitos(tcpPort_));
char buf[256];
snprintf(buf, sizeof(buf),
"token=%s, info_hash=%s, tcpPort=%u",
util::toHex(token_).c_str(),
util::toHex(infoHash_, INFO_HASH_LENGTH).c_str(),
tcpPort_);
return buf;
}
} // namespace aria2

View File

@ -158,9 +158,13 @@ void DHTGetPeersReplyMessage::accept(DHTMessageCallback* callback)
std::string DHTGetPeersReplyMessage::toStringOptional() const
{
return strconcat("token=", util::toHex(token_),
", values=", util::uitos(values_.size()),
", nodes=", util::uitos(closestKNodes_.size()));
char buf[256];
snprintf(buf, sizeof(buf),
"token=%s, values=%lu, nodes=%lu",
util::toHex(token_).c_str(),
static_cast<unsigned long>(values_.size()),
static_cast<unsigned long>(closestKNodes_.size()));
return buf;
}
} // namespace aria2

View File

@ -117,10 +117,15 @@ void DHTNode::timeout()
std::string DHTNode::toString() const
{
return strconcat("DHTNode ID=", util::toHex(id_, DHT_ID_LENGTH),
", Host=", ipaddr_, ":", util::uitos(port_),
", Condition=", util::uitos(condition_),
", RTT=", util::uitos(rtt_));
char buf[256];
snprintf(buf, sizeof(buf),
"DHTNode ID=%s, Host=%s(%u), Condition=%u, RTT=%u",
util::toHex(id_, DHT_ID_LENGTH).c_str(),
ipaddr_.c_str(),
port_,
condition_,
rtt_);
return buf;
}
void DHTNode::setID(const unsigned char* id)

View File

@ -68,20 +68,17 @@ bool DHTQueryMessage::isReply() const
std::string DHTQueryMessage::toString() const
{
std::string s = strconcat
("dht query ", getMessageType(),
" TransactionID=", util::toHex(getTransactionID()),
" Remote:", getRemoteNode()->getIPAddress(),
":", util::uitos(getRemoteNode()->getPort()),
", id=", util::toHex(getRemoteNode()->getID(), DHT_ID_LENGTH),
", ");
if(!getVersion().empty()) {
s += "v=";
s += util::torrentPercentEncode(getVersion());
s += ", ";
}
s += toStringOptional();
return s;
char buf[256];
snprintf(buf, sizeof(buf),
"dht query %s TransactionID=%s Remote:%s(%u), id=%s, v=%s, %s",
getMessageType().c_str(),
util::toHex(getTransactionID()).c_str(),
getRemoteNode()->getIPAddress().c_str(),
getRemoteNode()->getPort(),
util::toHex(getRemoteNode()->getID(), DHT_ID_LENGTH).c_str(),
util::torrentPercentEncode(getVersion()).c_str(),
toStringOptional().c_str());
return buf;
}
} // namespace aria2

View File

@ -65,20 +65,17 @@ bool DHTResponseMessage::isReply() const
std::string DHTResponseMessage::toString() const
{
std::string s = strconcat
("dht response ", getMessageType(),
" TransactionID=", util::toHex(getTransactionID()),
" Remote:", getRemoteNode()->getIPAddress(),
":", util::uitos(getRemoteNode()->getPort()),
", id=", util::toHex(getRemoteNode()->getID(), DHT_ID_LENGTH),
", ");
if(!getVersion().empty()) {
s += "v=";
s += util::torrentPercentEncode(getVersion());
s += ", ";
}
s += toStringOptional();
return s;
char buf[256];
snprintf(buf, sizeof(buf),
"dht response %s TransactionID=%s Remote:%s(%u), id=%s, v=%s, %s",
getMessageType().c_str(),
util::toHex(getTransactionID()).c_str(),
getRemoteNode()->getIPAddress().c_str(),
getRemoteNode()->getPort(),
util::toHex(getRemoteNode()->getID(), DHT_ID_LENGTH).c_str(),
util::torrentPercentEncode(getVersion()).c_str(),
toStringOptional().c_str());
return buf;
}
} // namespace aria2

View File

@ -89,10 +89,13 @@ std::string DHTUnknownMessage::toString() const
sampleLength = length_;
}
std::string sample(&data_[0], &data_[sampleLength]);
return strconcat("dht unknown Remote:", ipaddr_, ":", util::uitos(port_),
" length=", util::uitos(length_),
", first 8 bytes(hex)=", util::toHex(sample));
char buf[256];
snprintf(buf, sizeof(buf),
"dht unknown Remote:%s(%u) length=%lu, first 8 bytes(hex)=%s",
ipaddr_.c_str(), port_,
static_cast<unsigned long>(length_),
util::toHex(data_, sampleLength).c_str());
return buf;
}
} // namespace aria2

View File

@ -723,8 +723,11 @@ bool FtpNegotiationCommand::sendTunnelRequest()
httpRequest->setUserAgent(getOption()->get(PREF_USER_AGENT));
SharedHandle<Request> req(new Request());
// Construct fake URI in order to use HttpRequest
req->setUri(strconcat("ftp://", dataConnAddr_.first,
A2STR::COLON_C, util::uitos(dataConnAddr_.second)));
// TODO Handle IPv6 address; it must be enclosed with [].
char fakeUriBuf[1024];
snprintf(fakeUriBuf, sizeof(fakeUriBuf), "ftp://%s:%u",
dataConnAddr_.first.c_str(), dataConnAddr_.second);
req->setUri(fakeUriBuf);
httpRequest->setRequest(req);
httpRequest->setProxyRequest(createProxyRequest());
http_->sendProxyRequest(httpRequest);

View File

@ -229,14 +229,17 @@ std::string HttpRequest::createRequest()
}
if(cookieStorage_) {
std::string cookiesValue;
std::string path = getDir();
if(getDir() == "/") {
path += getFile();
} else {
path += "/";
path += getFile();
}
std::vector<Cookie> cookies =
cookieStorage_->criteriaFind
(getHost(),
getDir() == A2STR::SLASH_C?
getDir()+getFile():strconcat(getDir(), A2STR::SLASH_C, getFile()),
Time().getTime(),
getProtocol() == Request::PROTO_HTTPS ?
true : false);
cookieStorage_->criteriaFind(getHost(), path,
Time().getTime(),
getProtocol() == Request::PROTO_HTTPS);
for(std::vector<Cookie>::const_iterator itr = cookies.begin(),
eoi = cookies.end(); itr != eoi; ++itr) {
strappend(cookiesValue, (*itr).toString(), ";");

View File

@ -60,7 +60,11 @@ size_t IndexBtMessage::getMessageLength()
std::string IndexBtMessage::toString() const
{
return strconcat(getName(), " index=", util::itos(index_));
char buf[256];
snprintf(buf, sizeof(buf), "%s index=%lu",
getName().c_str(),
static_cast<unsigned long>(index_));
return buf;
}
} // namespace aria2

View File

@ -167,8 +167,11 @@ bool Piece::getAllMissingBlockIndexes
}
std::string Piece::toString() const {
return strconcat("piece: index=", util::itos(index_),
", length=", util::itos(length_));
char buf[256];
snprintf(buf, sizeof(buf), "piece: index=%lu, length=%lu",
static_cast<unsigned long>(index_),
static_cast<unsigned long>(length_));
return buf;
}
void Piece::reconfigure(size_t length)

View File

@ -72,9 +72,14 @@ size_t RangeBtMessage::getMessageLength()
std::string RangeBtMessage::toString() const
{
return strconcat(getName(), " index=", util::uitos(index_),
", begin=", util::uitos(begin_),
", length=", util::uitos(length_));
char buf[256];
snprintf(buf, sizeof(buf),
"%s index=%lu, begin=%u, length=%lu",
getName().c_str(),
static_cast<unsigned long>(index_),
begin_,
static_cast<unsigned long>(length_));
return buf;
}
} // namespace aria2

View File

@ -163,7 +163,10 @@ const SharedHandle<PeerStat>& Request::initPeerStat()
std::string Request::getURIHost() const
{
if(isIPv6LiteralAddress()) {
return strconcat("[", getHost(), "]");
std::string s = "[";
s += getHost();
s += "]";
return s;
} else {
return getHost();
}

View File

@ -793,7 +793,10 @@ bool RequestGroup::tryAutoFileRenaming()
return false;
}
for(unsigned int i = 1; i < 10000; ++i) {
File newfile(strconcat(filepath, A2STR::DOT_C, util::uitos(i)));
std::string newfilename = filepath;
newfilename += ".";
newfilename += util::uitos(i);
File newfile(newfilename);
File ctrlfile(newfile.getPath()+DefaultBtProgressInfoFile::getSuffix());
if(!newfile.exists() || (newfile.exists() && ctrlfile.exists())) {
downloadContext_->getFirstFileEntry()->setPath(newfile.getPath());

View File

@ -71,7 +71,10 @@ std::string UTMetadataDataExtensionMessage::getPayload()
std::string UTMetadataDataExtensionMessage::toString() const
{
return strconcat("ut_metadata data piece=", util::uitos(getIndex()));
char buf[256];
snprintf(buf, sizeof(buf), "ut_metadata data piece=%lu",
static_cast<unsigned long>(getIndex()));
return buf;
}
void UTMetadataDataExtensionMessage::doReceivedAction()

View File

@ -54,7 +54,10 @@ std::string UTMetadataRejectExtensionMessage::getPayload()
std::string UTMetadataRejectExtensionMessage::toString() const
{
return strconcat("ut_metadata reject piece=", util::uitos(getIndex()));
char buf[256];
snprintf(buf, sizeof(buf), "ut_metadata reject piece=%lu",
static_cast<unsigned long>(getIndex()));
return buf;
}
void UTMetadataRejectExtensionMessage::doReceivedAction()

View File

@ -69,7 +69,10 @@ std::string UTMetadataRequestExtensionMessage::getPayload()
std::string UTMetadataRequestExtensionMessage::toString() const
{
return strconcat("ut_metadata request piece=", util::uitos(getIndex()));
char buf[256];
snprintf(buf, sizeof(buf), "ut_metadata request piece=%lu",
static_cast<unsigned long>(getIndex()));
return buf;
}
void UTMetadataRequestExtensionMessage::doReceivedAction()

View File

@ -121,8 +121,11 @@ UTPexExtensionMessage::createCompactPeerListAndFlag
std::string UTPexExtensionMessage::toString() const
{
return strconcat("ut_pex added=", util::uitos(freshPeers_.size()),
", dropped=", util::uitos(droppedPeers_.size()));
char buf[256];
snprintf(buf, sizeof(buf), "ut_pex added=%lu, dropped=%lu",
static_cast<unsigned long>(freshPeers_.size()),
static_cast<unsigned long>(droppedPeers_.size()));
return buf;
}
void UTPexExtensionMessage::doReceivedAction()

View File

@ -283,109 +283,6 @@ std::string strjoin(InputIterator first, InputIterator last,
return result;
}
template<typename T1, typename T2>
inline std::string strconcat(const T1& a1, const T2& a2)
{
std::string s(a1); s += a2; return s;
}
template<typename T1, typename T2, typename T3>
inline std::string strconcat(const T1& a1, const T2& a2, const T3& a3)
{
std::string s(a1); s += a2; s += a3; return s;
}
template<typename T1, typename T2, typename T3, typename T4>
inline std::string
strconcat(const T1& a1, const T2& a2, const T3& a3, const T4& a4)
{
std::string s(a1); s += a2; s += a3; s += a4; return s;
}
template<typename T1, typename T2, typename T3, typename T4, typename T5>
inline std::string
strconcat(const T1& a1, const T2& a2, const T3& a3, const T4& a4,
const T5& a5)
{
std::string s(a1); s += a2; s += a3; s += a4; s += a5; return s;
}
template<typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6>
inline std::string
strconcat(const T1& a1, const T2& a2, const T3& a3, const T4& a4,
const T5& a5, const T6& a6)
{
std::string s(a1); s += a2; s += a3; s += a4; s += a5; s += a6; return s;
}
template<typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7>
inline std::string
strconcat(const T1& a1, const T2& a2, const T3& a3, const T4& a4,
const T5& a5, const T6& a6, const T7& a7)
{
std::string s(a1); s += a2; s += a3; s += a4; s += a5; s += a6; s += a7;
return s;
}
template<typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8>
inline std::string
strconcat(const T1& a1, const T2& a2, const T3& a3, const T4& a4,
const T5& a5, const T6& a6, const T7& a7, const T8& a8)
{
std::string s(a1); s += a2; s += a3; s += a4; s += a5; s += a6; s += a7;
s += a8; return s;
}
template<typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9>
inline std::string
strconcat(const T1& a1, const T2& a2, const T3& a3, const T4& a4,
const T5& a5, const T6& a6, const T7& a7, const T8& a8,
const T9& a9)
{
std::string s(a1); s += a2; s += a3; s += a4; s += a5; s += a6; s += a7;
s += a8; s += a9; return s;
}
template<typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename T10>
inline std::string
strconcat(const T1& a1, const T2& a2, const T3& a3, const T4& a4,
const T5& a5, const T6& a6, const T7& a7, const T8& a8,
const T9& a9, const T10& a10)
{
std::string s(a1); s += a2; s += a3; s += a4; s += a5; s += a6; s += a7;
s += a8; s += a9; s += a10; return s;
}
template<typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename T10,
typename T11>
inline std::string
strconcat(const T1& a1, const T2& a2, const T3& a3, const T4& a4,
const T5& a5, const T6& a6, const T7& a7, const T8& a8,
const T9& a9, const T10& a10, const T11& a11)
{
std::string s(a1); s += a2; s += a3; s += a4; s += a5; s += a6; s += a7;
s += a8; s += a9; s += a10; s += a11; return s;
}
template<typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename T10,
typename T11, typename T12>
inline std::string
strconcat(const T1& a1, const T2& a2, const T3& a3, const T4& a4,
const T5& a5, const T6& a6, const T7& a7, const T8& a8,
const T9& a9, const T10& a10, const T11& a11,
const T12& a12)
{
std::string s(a1); s += a2; s += a3; s += a4; s += a5; s += a6; s += a7;
s += a8; s += a9; s += a10; s += a11; s += a12; return s;
}
template<typename T1, typename T2>
inline void strappend(std::string& base, const T1& a1, const T2& a2)
{

View File

@ -220,7 +220,8 @@ void extractFileEntries
error_code::BITTORRENT_PARSE_ERROR);
}
} else {
utf8Name = strconcat(File(defaultName).getBasename(), ".file");
utf8Name = File(defaultName).getBasename();
utf8Name += ".file";
}
} else {
utf8Name = overrideName;
@ -951,8 +952,9 @@ std::string metadata2Torrent
torrent += "13:announce-list";
torrent += bencode2::encode(&announceList);
}
torrent +=
strconcat("4:info", metadata, "e");
torrent += "4:info";
torrent += metadata;
torrent += "e";
return torrent;
}

View File

@ -1367,11 +1367,16 @@ std::string applyDir(const std::string& dir, const std::string& relPath)
{
std::string s;
if(dir.empty()) {
s = strconcat(A2STR::DOT_C, A2STR::SLASH_C, relPath);
} else if(dir == A2STR::SLASH_C) {
s = strconcat(A2STR::SLASH_C, relPath);
s = "./";
s += relPath;
} else {
s = strconcat(dir, A2STR::SLASH_C, relPath);
s = dir;
if(dir == "/") {
s += relPath;
} else {
s += "/";
s += relPath;
}
}
#ifdef __MINGW32__
for(std::string::iterator i = s.begin(), eoi = s.end(); i != eoi; ++i) {

View File

@ -35,7 +35,7 @@ void DHTUnknownMessageTest::testToString()
data.size(),
ipaddr, port);
CPPUNIT_ASSERT_EQUAL(std::string("dht unknown Remote:192.168.0.1:6881 length=9, first 8 bytes(hex)=63686f636f6c6174"), msg.toString());
CPPUNIT_ASSERT_EQUAL(std::string("dht unknown Remote:192.168.0.1(6881) length=9, first 8 bytes(hex)=63686f636f6c6174"), msg.toString());
}
{
// data.size() == 3
@ -45,7 +45,7 @@ void DHTUnknownMessageTest::testToString()
data.size(),
ipaddr, port);
CPPUNIT_ASSERT_EQUAL(std::string("dht unknown Remote:192.168.0.1:6881 length=3, first 8 bytes(hex)=666f6f"), msg.toString());
CPPUNIT_ASSERT_EQUAL(std::string("dht unknown Remote:192.168.0.1(6881) length=3, first 8 bytes(hex)=666f6f"), msg.toString());
}
}

View File

@ -77,7 +77,7 @@ void SessionSerializerTest::testSave()
std::getline(ss, line);
CPPUNIT_ASSERT_EQUAL(std::string("http://error\t"), line);
std::getline(ss, line);
CPPUNIT_ASSERT_EQUAL(strconcat(uris[0], "\t", uris[1], "\t"), line);
CPPUNIT_ASSERT_EQUAL(uris[0]+"\t"+uris[1]+"\t", line);
std::getline(ss, line);
CPPUNIT_ASSERT_EQUAL(std::string(" dir=/tmp"), line);
std::getline(ss, line);

View File

@ -14,7 +14,6 @@ class a2functionalTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testMemFunSh);
CPPUNIT_TEST(testAdopt2nd);
CPPUNIT_TEST(testStrjoin);
CPPUNIT_TEST(testStrconcat);
CPPUNIT_TEST(testStrappend);
CPPUNIT_TEST(testLeastRecentAccess);
CPPUNIT_TEST_SUITE_END();
@ -22,7 +21,6 @@ public:
void testMemFunSh();
void testAdopt2nd();
void testStrjoin();
void testStrconcat();
void testStrappend();
void testLeastRecentAccess();
@ -100,11 +98,6 @@ void a2functionalTest::testStrjoin()
strjoin(v.begin(), v.end(), " "));
}
void a2functionalTest::testStrconcat()
{
CPPUNIT_ASSERT_EQUAL(std::string("X=3"), strconcat("X=", "3"));
}
void a2functionalTest::testStrappend()
{
std::string str = "X=";