Răsfoiți Sursa

2010-11-20 Tatsuhiro Tsujikawa <[email protected]>

	Replaced StringFormat with fmt
Tatsuhiro Tsujikawa 15 ani în urmă
părinte
comite
694fb307aa
95 a modificat fișierele cu 647 adăugiri și 886 ștergeri
  1. 4 0
      ChangeLog
  2. 5 7
      src/AbstractCommand.cc
  3. 27 30
      src/AbstractDiskWriter.cc
  4. 3 3
      src/BtAllowedFastMessage.cc
  5. 0 1
      src/BtBitfieldMessage.cc
  6. 2 3
      src/BtDependency.cc
  7. 0 1
      src/BtExtendedMessage.cc
  8. 10 10
      src/BtHandshakeMessageValidator.cc
  9. 3 3
      src/BtHaveAllMessage.cc
  10. 3 3
      src/BtHaveNoneMessage.cc
  11. 0 1
      src/BtPieceMessage.cc
  12. 0 1
      src/BtPortMessage.cc
  13. 3 3
      src/BtRejectMessage.cc
  14. 0 1
      src/ChunkedDecodingStreamFilter.cc
  15. 0 1
      src/CookieStorage.cc
  16. 5 5
      src/DHTAnnouncePeerMessage.cc
  17. 2 3
      src/DHTAutoSaveCommand.cc
  18. 4 5
      src/DHTEntryPointNameResolveCommand.cc
  19. 0 1
      src/DHTMessageDispatcherImpl.cc
  20. 20 21
      src/DHTMessageFactoryImpl.cc
  21. 2 3
      src/DHTMessageTracker.cc
  22. 6 6
      src/DHTRoutingTableDeserializer.cc
  23. 0 1
      src/DHTRoutingTableSerializer.cc
  24. 3 3
      src/DHTTokenTracker.cc
  25. 1 2
      src/DefaultBtAnnounce.cc
  26. 9 12
      src/DefaultBtInteractive.cc
  27. 2 2
      src/DefaultBtMessageFactory.cc
  28. 27 29
      src/DefaultBtProgressInfoFile.cc
  29. 11 11
      src/DefaultExtensionMessageFactory.cc
  30. 0 1
      src/DefaultPieceStorage.cc
  31. 6 7
      src/DownloadCommand.cc
  32. 4 4
      src/DownloadContext.cc
  33. 2 3
      src/FtpConnection.cc
  34. 0 1
      src/FtpFinishDownloadCommand.cc
  35. 15 16
      src/FtpNegotiationCommand.cc
  36. 3 3
      src/GZipDecoder.cc
  37. 3 3
      src/GZipDecodingStreamFilter.cc
  38. 3 3
      src/GZipEncoder.cc
  39. 3 4
      src/HandshakeExtensionMessage.cc
  40. 2 2
      src/HashFuncEntry.h
  41. 12 16
      src/HttpResponse.cc
  42. 4 5
      src/HttpResponseCommand.cc
  43. 2 4
      src/HttpSkipResponseCommand.cc
  44. 5 5
      src/InitiateConnectionCommandFactory.cc
  45. 2 3
      src/IteratableChunkChecksumValidator.cc
  46. 3 3
      src/LibgcryptARC4Context.cc
  47. 3 3
      src/LibgcryptARC4Decryptor.cc
  48. 3 3
      src/LibgcryptARC4Encryptor.cc
  49. 9 10
      src/LibgcryptDHKeyExchange.cc
  50. 0 1
      src/LibgnutlsTLSContext.cc
  51. 3 3
      src/LibsslARC4Context.cc
  52. 3 3
      src/LibsslARC4Decryptor.cc
  53. 3 3
      src/LibsslARC4Encryptor.cc
  54. 17 20
      src/LibsslDHKeyExchange.cc
  55. 0 1
      src/LibsslMessageDigestImpl.cc
  56. 0 1
      src/LibsslTLSContext.cc
  57. 6 7
      src/MSEHandshake.cc
  58. 0 1
      src/Makefile.am
  59. 13 15
      src/Makefile.in
  60. 7 10
      src/MessageDigestHelper.cc
  61. 5 6
      src/MultiDiskAdaptor.cc
  62. 3 3
      src/NameResolver.cc
  63. 4 5
      src/Netrc.cc
  64. 2 3
      src/NsCookieParser.cc
  65. 3 3
      src/OptionHandlerException.cc
  66. 19 18
      src/OptionHandlerFactory.cc
  67. 14 18
      src/OptionHandlerImpl.cc
  68. 2 3
      src/PeerAbstractCommand.cc
  69. 1 2
      src/PeerConnection.cc
  70. 4 5
      src/PeerReceiveHandshakeCommand.cc
  71. 2 2
      src/Request.cc
  72. 24 29
      src/RequestGroup.cc
  73. 2 3
      src/RequestGroupMan.cc
  74. 2 3
      src/SocketBuffer.cc
  75. 69 90
      src/SocketCore.cc
  76. 5 4
      src/Sqlite3CookieParser.cc
  77. 0 68
      src/StringFormat.cc
  78. 0 61
      src/StringFormat.h
  79. 3 4
      src/UTMetadataRequestExtensionMessage.cc
  80. 4 4
      src/UTPexExtensionMessage.cc
  81. 4 7
      src/XmlRpcMethod.cc
  82. 26 28
      src/XmlRpcMethodImpl.cc
  83. 9 9
      src/bencode2.cc
  84. 32 38
      src/bittorrent_helper.cc
  85. 2 3
      src/download_helper.cc
  86. 2 3
      src/option_processing.cc
  87. 34 38
      src/util.cc
  88. 11 11
      src/version_usage.cc
  89. 0 1
      test/DefaultExtensionMessageFactoryTest.cc
  90. 28 0
      test/FmtTest.cc
  91. 1 1
      test/Makefile.am
  92. 5 5
      test/Makefile.in
  93. 32 32
      test/MetalinkProcessorTest.cc
  94. 0 35
      test/StringFormatTest.cc
  95. 5 5
      test/TestUtil.cc

+ 4 - 0
ChangeLog

@@ -1,3 +1,7 @@
+2010-11-20  Tatsuhiro Tsujikawa  <[email protected]>
+
+	Replaced StringFormat with fmt
+
 2010-11-20  Tatsuhiro Tsujikawa  <[email protected]>
 
 	Rewritten Logger interface. Logger now writes source file name and

+ 5 - 7
src/AbstractCommand.cc

@@ -54,7 +54,6 @@
 #include "Socket.h"
 #include "message.h"
 #include "prefs.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "ServerStat.h"
 #include "RequestGroupMan.h"
@@ -225,9 +224,8 @@ bool AbstractCommand::execute() {
       }
       return executeInternal();
     } else if(errorEventEnabled()) {
-      throw DL_RETRY_EX
-        (StringFormat(MSG_NETWORK_PROBLEM,
-                      socket_->getSocketError().c_str()).str());
+      throw DL_RETRY_EX(fmt(MSG_NETWORK_PROBLEM,
+                            socket_->getSocketError().c_str()));
     } else {
       if(checkPoint_.difference(global::wallclock) >= timeout_) {
         // timeout triggers ServerStat error state.
@@ -653,10 +651,10 @@ bool AbstractCommand::asyncResolveHostname()
         (req_->getHost(), req_->getProtocol())->setError();
     }
     throw DL_ABORT_EX
-      (StringFormat(MSG_NAME_RESOLUTION_FAILED,
+      (fmt(MSG_NAME_RESOLUTION_FAILED,
                     util::itos(getCuid()).c_str(),
                     asyncNameResolver_->getHostname().c_str(),
-                    asyncNameResolver_->getError().c_str()).str());
+                    asyncNameResolver_->getError().c_str()));
   default:
     return false;
   }
@@ -780,7 +778,7 @@ bool AbstractCommand::checkIfConnectionEstablished
           (req_->getHost(), req_->getProtocol())->setError();
       }
       throw DL_RETRY_EX
-        (StringFormat(MSG_ESTABLISHING_CONNECTION_FAILED, error.c_str()).str());
+        (fmt(MSG_ESTABLISHING_CONNECTION_FAILED, error.c_str()));
     }
   }
   return true;

+ 27 - 30
src/AbstractDiskWriter.cc

@@ -49,7 +49,7 @@
 #include "message.h"
 #include "DlAbortEx.h"
 #include "a2io.h"
-#include "StringFormat.h"
+#include "fmt.h"
 #include "DownloadFailureException.h"
 
 namespace aria2 {
@@ -101,10 +101,9 @@ void AbstractDiskWriter::openExistingFile(uint64_t totalLength)
   if(fd_ < 0) {
     int errNum = errno;
     throw DL_ABORT_EX2
-      (errNum,
-       StringFormat(EX_FILE_OPEN,
-                    filename_.c_str(),
-                    util::safeStrerror(errNum).c_str()).str());
+      (errNum, fmt(EX_FILE_OPEN,
+                   filename_.c_str(),
+                   util::safeStrerror(errNum).c_str()));
   }
 }
 
@@ -118,10 +117,9 @@ void AbstractDiskWriter::createFile(int addFlags)
   if(fd_ < 0) {
     int errNum = errno;
     throw DL_ABORT_EX2
-      (errNum,
-       StringFormat(EX_FILE_OPEN,
-                    filename_.c_str(),
-                    util::safeStrerror(errNum).c_str()).str());
+      (errNum, fmt(EX_FILE_OPEN,
+                   filename_.c_str(),
+                   util::safeStrerror(errNum).c_str()));
   }  
 }
 
@@ -150,10 +148,9 @@ void AbstractDiskWriter::seek(off_t offset)
 {
   if(a2lseek(fd_, offset, SEEK_SET) == (off_t)-1) {
     int errNum = errno;
-    throw DL_ABORT_EX
-      (StringFormat(EX_FILE_SEEK,
-                    filename_.c_str(),
-                    util::safeStrerror(errNum).c_str()).str());
+    throw DL_ABORT_EX(fmt(EX_FILE_SEEK,
+                          filename_.c_str(),
+                          util::safeStrerror(errNum).c_str()));
   }
 }
 
@@ -166,14 +163,14 @@ void AbstractDiskWriter::writeData(const unsigned char* data, size_t len, off_t
     // DownloadFailureException and abort download instantly.
     if(errNum == ENOSPC) {
       throw DOWNLOAD_FAILURE_EXCEPTION
-        (StringFormat(EX_FILE_WRITE,
-                      filename_.c_str(),
-                      util::safeStrerror(errNum).c_str()).str());
+        (fmt(EX_FILE_WRITE,
+             filename_.c_str(),
+             util::safeStrerror(errNum).c_str()));
     } else {
       throw DL_ABORT_EX
-        (StringFormat(EX_FILE_WRITE,
-                      filename_.c_str(),
-                      util::safeStrerror(errNum).c_str()).str());
+        (fmt(EX_FILE_WRITE,
+             filename_.c_str(),
+             util::safeStrerror(errNum).c_str()));
     }
   }
 }
@@ -185,9 +182,9 @@ ssize_t AbstractDiskWriter::readData(unsigned char* data, size_t len, off_t offs
   if((ret = readDataInternal(data, len)) < 0) {
     int errNum = errno;
     throw DL_ABORT_EX
-      (StringFormat(EX_FILE_READ,
-                    filename_.c_str(),
-                    util::safeStrerror(errNum).c_str()).str());
+      (fmt(EX_FILE_READ,
+           filename_.c_str(),
+           util::safeStrerror(errNum).c_str()));
   }
   return ret;
 }
@@ -203,14 +200,14 @@ void AbstractDiskWriter::truncate(uint64_t length)
   HANDLE handle = LongToHandle(_get_osfhandle(fd_));
   seek(length);
   if(SetEndOfFile(handle) == 0) {
-    throw DL_ABORT_EX(StringFormat("SetEndOfFile failed. cause: %s",
-                                   GetLastError()).str());
+    throw DL_ABORT_EX(fmt("SetEndOfFile failed. cause: %s",
+                          GetLastError()));
   }
 #else
   if(ftruncate(fd_, length) == -1) {
     int errNum = errno;
-    throw DL_ABORT_EX(StringFormat("ftruncate failed. cause: %s",
-                                   util::safeStrerror(errNum).c_str()).str());
+    throw DL_ABORT_EX(fmt("ftruncate failed. cause: %s",
+                          util::safeStrerror(errNum).c_str()));
   }
 #endif
 }
@@ -228,14 +225,14 @@ void AbstractDiskWriter::allocate(off_t offset, uint64_t length)
   while((r = fallocate(fd_, 0, offset, length)) == -1 && errno == EINTR);
   int errNum = errno;
   if(r == -1) {
-    throw DL_ABORT_EX(StringFormat("fallocate failed. cause: %s",
-                                   util::safeStrerror(errNum).c_str()).str());
+    throw DL_ABORT_EX(fmt("fallocate failed. cause: %s",
+                          util::safeStrerror(errNum).c_str()));
   }
 # elif HAVE_POSIX_FALLOCATE
   int r = posix_fallocate(fd_, offset, length);
   if(r != 0) {
-    throw DL_ABORT_EX(StringFormat("posix_fallocate failed. cause: %s",
-                                   util::safeStrerror(r).c_str()).str());
+    throw DL_ABORT_EX(fmt("posix_fallocate failed. cause: %s",
+                          util::safeStrerror(r).c_str()));
   }
 # else
 #  error "no *_fallocate function available."

+ 3 - 3
src/BtAllowedFastMessage.cc

@@ -35,7 +35,7 @@
 #include "BtAllowedFastMessage.h"
 #include "DlAbortEx.h"
 #include "Peer.h"
-#include "StringFormat.h"
+#include "fmt.h"
 
 namespace aria2 {
 
@@ -53,8 +53,8 @@ SharedHandle<BtAllowedFastMessage> BtAllowedFastMessage::create
 void BtAllowedFastMessage::doReceivedAction() {
   if(!getPeer()->isFastExtensionEnabled()) {
     throw DL_ABORT_EX
-      (StringFormat("%s received while fast extension is disabled",
-                    toString().c_str()).str());
+      (fmt("%s received while fast extension is disabled",
+           toString().c_str()));
   }
   if(isMetadataGetMode()) {
     return;

+ 0 - 1
src/BtBitfieldMessage.cc

@@ -41,7 +41,6 @@
 #include "DlAbortEx.h"
 #include "message.h"
 #include "Peer.h"
-#include "StringFormat.h"
 #include "PieceStorage.h"
 #include "a2functional.h"
 

+ 2 - 3
src/BtDependency.cc

@@ -47,7 +47,6 @@
 #include "File.h"
 #include "bittorrent_helper.h"
 #include "DlAbortEx.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "FileEntry.h"
 
@@ -131,8 +130,8 @@ bool BtDependency::resolve()
           }
           if(d == ctxFilesEnd) {
             throw DL_ABORT_EX
-              (StringFormat("No entry %s in torrent file",
-                            (*s)->getOriginalName().c_str()).str());
+              (fmt("No entry %s in torrent file",
+                   (*s)->getOriginalName().c_str()));
           }
           copyValues(*d, *s);
         }

+ 0 - 1
src/BtExtendedMessage.cc

@@ -44,7 +44,6 @@
 #include "DlAbortEx.h"
 #include "message.h"
 #include "util.h"
-#include "StringFormat.h"
 #include "a2functional.h"
 
 namespace aria2 {

+ 10 - 10
src/BtHandshakeMessageValidator.cc

@@ -38,8 +38,8 @@
 
 #include "BtHandshakeMessage.h"
 #include "util.h"
-#include "StringFormat.h"
 #include "DlAbortEx.h"
+#include "fmt.h"
 
 namespace aria2 {
 
@@ -55,21 +55,21 @@ BtHandshakeMessageValidator::~BtHandshakeMessageValidator() {}
 void BtHandshakeMessageValidator::validate()
 {
   if(message_->getPstrlen() != 19) {
-    throw DL_ABORT_EX(StringFormat("invalid handshake pstrlen=%u",
-                                   message_->getPstrlen()).str());
+    throw DL_ABORT_EX(fmt("invalid handshake pstrlen=%u",
+                          message_->getPstrlen()));
   }
   if(memcmp(BtHandshakeMessage::BT_PSTR, message_->getPstr(), 19) != 0) {
     throw DL_ABORT_EX
-      (StringFormat("invalid handshake pstr=%s",
-                    util::percentEncode
-                    (message_->getPstr(), 19).c_str()).str());
+      (fmt("invalid handshake pstr=%s",
+           util::percentEncode
+           (message_->getPstr(), 19).c_str()));
   }
   if(memcmp(infoHash_, message_->getInfoHash(), sizeof(infoHash_)) != 0) {
     throw DL_ABORT_EX
-      (StringFormat("invalid handshake info hash: expected:%s, actual:%s",
-                    util::toHex(infoHash_, sizeof(infoHash_)).c_str(),
-                    util::toHex(message_->getInfoHash(),
-                                INFO_HASH_LENGTH).c_str()).str());
+      (fmt("invalid handshake info hash: expected:%s, actual:%s",
+           util::toHex(infoHash_, sizeof(infoHash_)).c_str(),
+           util::toHex(message_->getInfoHash(),
+                       INFO_HASH_LENGTH).c_str()));
   }
 }
 

+ 3 - 3
src/BtHaveAllMessage.cc

@@ -35,7 +35,7 @@
 #include "BtHaveAllMessage.h"
 #include "DlAbortEx.h"
 #include "Peer.h"
-#include "StringFormat.h"
+#include "fmt.h"
 #include "PieceStorage.h"
 #include "message.h"
 
@@ -55,8 +55,8 @@ void BtHaveAllMessage::doReceivedAction()
 {
   if(!getPeer()->isFastExtensionEnabled()) {
     throw DL_ABORT_EX
-      (StringFormat("%s received while fast extension is disabled",
-                    toString().c_str()).str());
+      (fmt("%s received while fast extension is disabled",
+           toString().c_str()));
   }
   if(isMetadataGetMode()) {
     return;

+ 3 - 3
src/BtHaveNoneMessage.cc

@@ -35,7 +35,7 @@
 #include "BtHaveNoneMessage.h"
 #include "DlAbortEx.h"
 #include "Peer.h"
-#include "StringFormat.h"
+#include "fmt.h"
 
 namespace aria2 {
 
@@ -53,8 +53,8 @@ void BtHaveNoneMessage::doReceivedAction()
 {
   if(!getPeer()->isFastExtensionEnabled()) {
     throw DL_ABORT_EX
-      (StringFormat("%s received while fast extension is disabled",
-                    toString().c_str()).str());
+      (fmt("%s received while fast extension is disabled",
+           toString().c_str()));
   }
 }
 

+ 0 - 1
src/BtPieceMessage.cc

@@ -53,7 +53,6 @@
 #include "BtMessageFactory.h"
 #include "BtRequestFactory.h"
 #include "PeerConnection.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "DownloadContext.h"
 

+ 0 - 1
src/BtPortMessage.cc

@@ -45,7 +45,6 @@
 #include "DHTTaskQueue.h"
 #include "DHTTaskFactory.h"
 #include "DHTTask.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "a2functional.h"
 

+ 3 - 3
src/BtRejectMessage.cc

@@ -37,7 +37,7 @@
 #include "Peer.h"
 #include "RequestSlot.h"
 #include "BtMessageDispatcher.h"
-#include "StringFormat.h"
+#include "fmt.h"
 
 namespace aria2 {
 
@@ -57,8 +57,8 @@ void BtRejectMessage::doReceivedAction()
 {
   if(!getPeer()->isFastExtensionEnabled()) {
     throw DL_ABORT_EX
-      (StringFormat("%s received while fast extension is disabled.",
-                    toString().c_str()).str());
+      (fmt("%s received while fast extension is disabled.",
+           toString().c_str()));
   }
   if(isMetadataGetMode()) {
     return;

+ 0 - 1
src/ChunkedDecodingStreamFilter.cc

@@ -39,7 +39,6 @@
 #include "util.h"
 #include "message.h"
 #include "DlAbortEx.h"
-#include "StringFormat.h"
 #include "A2STR.h"
 
 namespace aria2 {

+ 0 - 1
src/CookieStorage.cc

@@ -42,7 +42,6 @@
 #include "LogFactory.h"
 #include "Logger.h"
 #include "DlAbortEx.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "NsCookieParser.h"
 #include "File.h"

+ 5 - 5
src/DHTAnnouncePeerMessage.cc

@@ -46,7 +46,7 @@
 #include "DHTTokenTracker.h"
 #include "DlAbortEx.h"
 #include "BtConstants.h"
-#include "StringFormat.h"
+#include "fmt.h"
 #include "a2functional.h"
 
 namespace aria2 {
@@ -109,10 +109,10 @@ void DHTAnnouncePeerMessage::validate() const
                                    getRemoteNode()->getIPAddress(),
                                    getRemoteNode()->getPort())) {
     throw DL_ABORT_EX
-      (StringFormat("Invalid token=%s from %s:%u",
-                    util::toHex(token_).c_str(),
-                    getRemoteNode()->getIPAddress().c_str(),
-                    getRemoteNode()->getPort()).str());
+      (fmt("Invalid token=%s from %s:%u",
+           util::toHex(token_).c_str(),
+           getRemoteNode()->getIPAddress().c_str(),
+           getRemoteNode()->getPort()));
   }
 }
 

+ 2 - 3
src/DHTAutoSaveCommand.cc

@@ -53,7 +53,6 @@
 #include "a2functional.h"
 #include "FileEntry.h"
 #include "DlAbortEx.h"
-#include "StringFormat.h"
 #include "fmt.h"
 
 namespace aria2 {
@@ -115,8 +114,8 @@ void DHTAutoSaveCommand::save()
                       std::ios::out|std::ios::binary);
       if(!o) {
         throw DL_ABORT_EX
-          (StringFormat("Failed to save DHT routing table to %s.",
-                        dhtFile.c_str()).str());
+          (fmt("Failed to save DHT routing table to %s.",
+               dhtFile.c_str()));
       }
       serializer.serialize(o);
     }

+ 4 - 5
src/DHTEntryPointNameResolveCommand.cc

@@ -48,7 +48,6 @@
 #include "RequestGroupMan.h"
 #include "Logger.h"
 #include "LogFactory.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #ifdef ENABLE_ASYNC_DNS
 #include "AsyncNameResolver.h"
@@ -180,10 +179,10 @@ bool DHTEntryPointNameResolveCommand::resolveHostname
     break;
   case AsyncNameResolver::STATUS_ERROR:
     throw DL_ABORT_EX
-      (StringFormat(MSG_NAME_RESOLUTION_FAILED,
-                    util::itos(getCuid()).c_str(),
-                    hostname.c_str(),
-                    resolver->getError().c_str()).str());
+      (fmt(MSG_NAME_RESOLUTION_FAILED,
+           util::itos(getCuid()).c_str(),
+           hostname.c_str(),
+           resolver->getError().c_str()));
   default:
     return false;
   }

+ 0 - 1
src/DHTMessageDispatcherImpl.cc

@@ -41,7 +41,6 @@
 #include "LogFactory.h"
 #include "Logger.h"
 #include "DHTConstants.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "DHTNode.h"
 

+ 20 - 21
src/DHTMessageFactoryImpl.cc

@@ -60,7 +60,6 @@
 #include "util.h"
 #include "Peer.h"
 #include "Logger.h"
-#include "StringFormat.h"
 #include "fmt.h"
 
 namespace aria2 {
@@ -97,7 +96,7 @@ const Dict* getDictionary(const Dict* dict, const std::string& key)
     return d;
   } else {
     throw DL_ABORT_EX
-      (StringFormat("Malformed DHT message. Missing %s", key.c_str()).str());
+      (fmt("Malformed DHT message. Missing %s", key.c_str()));
   }
 }
 } // namespace
@@ -110,7 +109,7 @@ const String* getString(const Dict* dict, const std::string& key)
     return c;
   } else {
     throw DL_ABORT_EX
-      (StringFormat("Malformed DHT message. Missing %s", key.c_str()).str());
+      (fmt("Malformed DHT message. Missing %s", key.c_str()));
   }
 }
 } // namespace
@@ -123,7 +122,7 @@ const Integer* getInteger(const Dict* dict, const std::string& key)
     return c;
   } else {
     throw DL_ABORT_EX
-      (StringFormat("Malformed DHT message. Missing %s", key.c_str()).str());
+      (fmt("Malformed DHT message. Missing %s", key.c_str()));
   }
 }
 } // namespace
@@ -136,8 +135,8 @@ const String* getString(const List* list, size_t index)
     return c;
   } else {
     throw DL_ABORT_EX
-      (StringFormat("Malformed DHT message. element[%lu] is not String.",
-                    static_cast<unsigned long>(index)).str());
+      (fmt("Malformed DHT message. element[%lu] is not String.",
+           static_cast<unsigned long>(index)));
   }
 }
 } // namespace
@@ -150,8 +149,8 @@ const Integer* getInteger(const List* list, size_t index)
     return c;
   } else {
     throw DL_ABORT_EX
-      (StringFormat("Malformed DHT message. element[%lu] is not Integer.",
-                    static_cast<unsigned long>(index)).str());
+      (fmt("Malformed DHT message. element[%lu] is not Integer.",
+           static_cast<unsigned long>(index)));
   }
 }
 } // namespace
@@ -164,7 +163,7 @@ const List* getList(const Dict* dict, const std::string& key)
     return l;
   } else {
     throw DL_ABORT_EX
-      (StringFormat("Malformed DHT message. Missing %s", key.c_str()).str());
+      (fmt("Malformed DHT message. Missing %s", key.c_str()));
   }
 }
 } // namespace
@@ -173,10 +172,10 @@ void DHTMessageFactoryImpl::validateID(const String* id) const
 {
   if(id->s().size() != DHT_ID_LENGTH) {
     throw DL_ABORT_EX
-      (StringFormat("Malformed DHT message. Invalid ID length."
-                    " Expected:%lu, Actual:%lu",
-                    static_cast<unsigned long>(DHT_ID_LENGTH),
-                    static_cast<unsigned long>(id->s().size())).str());
+      (fmt("Malformed DHT message. Invalid ID length."
+           " Expected:%lu, Actual:%lu",
+           static_cast<unsigned long>(DHT_ID_LENGTH),
+           static_cast<unsigned long>(id->s().size())));
   }
 }
 
@@ -184,8 +183,8 @@ void DHTMessageFactoryImpl::validatePort(const Integer* port) const
 {
   if(!(0 < port->i() && port->i() < UINT16_MAX)) {
     throw DL_ABORT_EX
-      (StringFormat("Malformed DHT message. Invalid port=%s",
-                    util::itos(port->i()).c_str()).str());
+      (fmt("Malformed DHT message. Invalid port=%s",
+           util::itos(port->i()).c_str()));
   }
 }
 
@@ -237,8 +236,8 @@ SharedHandle<DHTQueryMessage> DHTMessageFactoryImpl::createQueryMessage
                                     static_cast<uint16_t>(port->i()),
                                     token->s(), transactionID->s());
   } else {
-    throw DL_ABORT_EX(StringFormat("Unsupported message type: %s",
-                                   messageType->s().c_str()).str());
+    throw DL_ABORT_EX(fmt("Unsupported message type: %s",
+                          messageType->s().c_str()));
   }
   setVersion(msg, dict);
   return msg;
@@ -266,8 +265,8 @@ DHTMessageFactoryImpl::createResponseMessage
     throw DL_ABORT_EX("Received Error DHT message.");
   } else if(y->s() != DHTResponseMessage::R) {
     throw DL_ABORT_EX
-      (StringFormat("Malformed DHT message. y != r: y=%s",
-                    util::percentEncode(y->s()).c_str()).str());
+      (fmt("Malformed DHT message. y != r: y=%s",
+           util::percentEncode(y->s()).c_str()));
   }
   const Dict* rDict = getDictionary(dict, DHTResponseMessage::R);
   const String* id = getString(rDict, DHTMessage::ID);
@@ -284,7 +283,7 @@ DHTMessageFactoryImpl::createResponseMessage
     msg = createAnnouncePeerReplyMessage(remoteNode, transactionID->s());
   } else {
     throw DL_ABORT_EX
-      (StringFormat("Unsupported message type: %s", messageType.c_str()).str());
+      (fmt("Unsupported message type: %s", messageType.c_str()));
   }
   setVersion(msg, dict);
   return msg;
@@ -368,7 +367,7 @@ void DHTMessageFactoryImpl::extractNodes
   int unit = bittorrent::getCompactLength(family_)+20;
   if(length%unit != 0) {
     throw DL_ABORT_EX
-      (StringFormat("Nodes length is not multiple of %d", unit).str());
+      (fmt("Nodes length is not multiple of %d", unit));
   }
   for(size_t offset = 0; offset < length; offset += unit) {
     SharedHandle<DHTNode> node(new DHTNode(src+offset));

+ 2 - 3
src/DHTMessageTracker.cc

@@ -47,7 +47,6 @@
 #include "Logger.h"
 #include "DlAbortEx.h"
 #include "DHTConstants.h"
-#include "StringFormat.h"
 #include "fmt.h"
 
 namespace aria2 {
@@ -68,8 +67,8 @@ DHTMessageTracker::messageArrived
 {
   const String* tid = asString(dict->get(DHTMessage::T));
   if(!tid) {
-    throw DL_ABORT_EX(StringFormat("Malformed DHT message. From:%s:%u",
-                                   ipaddr.c_str(), port).str());
+    throw DL_ABORT_EX(fmt("Malformed DHT message. From:%s:%u",
+                          ipaddr.c_str(), port));
   }
   A2_LOG_DEBUG(fmt("Searching tracker entry for TransactionID=%s, Remote=%s:%u",
                    util::toHex(tid->s()).c_str(),

+ 6 - 6
src/DHTRoutingTableDeserializer.cc

@@ -45,7 +45,7 @@
 #include "DlAbortEx.h"
 #include "Logger.h"
 #include "a2netcompat.h"
-#include "StringFormat.h"
+#include "fmt.h"
 #include "util.h"
 #include "array_fun.h"
 
@@ -68,8 +68,8 @@ void readBytes(unsigned char* buf, size_t buflen,
 #define CHECK_STREAM(in, length)                                        \
   if(in.gcount() != length) {                                           \
     throw DL_ABORT_EX                                                   \
-      (StringFormat("Failed to load DHT routing table. cause:%s",       \
-                    "Unexpected EOF").str());                           \
+      (fmt("Failed to load DHT routing table. cause:%s",                \
+           "Unexpected EOF"));                                          \
   }                                                                     \
   if(!in) {                                                             \
     throw DL_ABORT_EX("Failed to load DHT routing table.");             \
@@ -117,10 +117,10 @@ void DHTRoutingTableDeserializer::deserialize(std::istream& in)
     version = 2;
   } else {
     throw DL_ABORT_EX
-      (StringFormat("Failed to load DHT routing table. cause:%s",
-                    "bad header").str());
+      (fmt("Failed to load DHT routing table. cause:%s",
+           "bad header"));
   }
-
+  
   uint32_t temp32;
   uint64_t temp64;
   // time

+ 0 - 1
src/DHTRoutingTableSerializer.cc

@@ -43,7 +43,6 @@
 #include "bittorrent_helper.h"
 #include "Logger.h"
 #include "a2netcompat.h"
-#include "StringFormat.h"
 #include "util.h"
 #include "TimeA2.h"
 

+ 3 - 3
src/DHTTokenTracker.cc

@@ -42,7 +42,7 @@
 #include "DHTConstants.h"
 #include "MessageDigest.h"
 #include "MessageDigestHelper.h"
-#include "StringFormat.h"
+#include "fmt.h"
 
 namespace aria2 {
 
@@ -70,8 +70,8 @@ std::string DHTTokenTracker::generateToken
   int compactlen = bittorrent::packcompact(src+DHT_ID_LENGTH, ipaddr, port);
   if(compactlen == 0) {
     throw DL_ABORT_EX
-      (StringFormat("Token generation failed: ipaddr=%s, port=%u",
-                    ipaddr.c_str(), port).str());
+      (fmt("Token generation failed: ipaddr=%s, port=%u",
+           ipaddr.c_str(), port));
   }
   memcpy(src, infoHash, DHT_ID_LENGTH);
   memcpy(src+DHT_ID_LENGTH+COMPACT_LEN_IPV6, secret, SECRET_SIZE);

+ 1 - 2
src/DefaultBtAnnounce.cc

@@ -46,7 +46,6 @@
 #include "PeerStorage.h"
 #include "Peer.h"
 #include "Option.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "A2STR.h"
 #include "bencode2.h"
@@ -228,7 +227,7 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
   const String* failure = asString(dict->get(BtAnnounce::FAILURE_REASON));
   if(failure) {
     throw DL_ABORT_EX
-      (StringFormat(EX_TRACKER_FAILURE, failure->s().c_str()).str());
+      (fmt(EX_TRACKER_FAILURE, failure->s().c_str()));
   }
   const String* warn = asString(dict->get(BtAnnounce::WARNING_MESSAGE));
   if(warn) {

+ 9 - 12
src/DefaultBtInteractive.cc

@@ -66,7 +66,6 @@
 #include "PeerConnection.h"
 #include "Logger.h"
 #include "LogFactory.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "RequestGroup.h"
 #include "RequestGroupMan.h"
@@ -118,9 +117,8 @@ BtMessageHandle DefaultBtInteractive::receiveHandshake(bool quickReply) {
   if(memcmp(message->getPeerId(), bittorrent::getStaticPeerId(),
             PEER_ID_LENGTH) == 0) {
     throw DL_ABORT_EX
-      (StringFormat
-       ("CUID#%s - Drop connection from the same Peer ID",
-        util::itos(cuid_).c_str()).str());
+      (fmt("CUID#%s - Drop connection from the same Peer ID",
+           util::itos(cuid_).c_str()));
   }
   std::vector<SharedHandle<Peer> > activePeers;
   peerStorage_->getActivePeers(activePeers);
@@ -128,9 +126,8 @@ BtMessageHandle DefaultBtInteractive::receiveHandshake(bool quickReply) {
         eoi = activePeers.end(); i != eoi; ++i) {
     if(memcmp((*i)->getPeerId(), message->getPeerId(), PEER_ID_LENGTH) == 0) {
       throw DL_ABORT_EX
-        (StringFormat
-         ("CUID#%s - Same Peer ID has been already seen.",
-          util::itos(cuid_).c_str()).str());
+        (fmt("CUID#%s - Same Peer ID has been already seen.",
+             util::itos(cuid_).c_str()));
     }
   }
 
@@ -447,9 +444,9 @@ void DefaultBtInteractive::checkActiveInteraction()
       peer_->setDisconnectedGracefully(true);
       // TODO change the message
       throw DL_ABORT_EX
-        (StringFormat("Disconnect peer because we are not interested each other"
-                      " after %ld second(s).",
-                      static_cast<long int>(interval)).str());
+        (fmt("Disconnect peer because we are not interested each other"
+             " after %ld second(s).",
+             static_cast<long int>(interval)));
     }
   }
   // Since the peers which are *just* connected and do nothing to improve
@@ -460,8 +457,8 @@ void DefaultBtInteractive::checkActiveInteraction()
     if(inactiveTime >= interval) {
       peer_->setDisconnectedGracefully(true);
       throw DL_ABORT_EX
-        (StringFormat(EX_DROP_INACTIVE_CONNECTION,
-                      static_cast<long int>(interval)).str());
+        (fmt(EX_DROP_INACTIVE_CONNECTION,
+             static_cast<long int>(interval)));
     }
   }
 }

+ 2 - 2
src/DefaultBtMessageFactory.cc

@@ -64,7 +64,7 @@
 #include "DownloadContext.h"
 #include "PieceStorage.h"
 #include "PeerStorage.h"
-#include "StringFormat.h"
+#include "fmt.h"
 #include "ExtensionMessageFactory.h"
 #include "bittorrent_helper.h"
 
@@ -245,7 +245,7 @@ DefaultBtMessageFactory::createBtMessage
       break;
     }
     default:
-      throw DL_ABORT_EX(StringFormat("Invalid message ID. id=%u", id).str());
+      throw DL_ABORT_EX(fmt("Invalid message ID. id=%u", id));
     }
   }
   setCommonProperty(msg);

+ 27 - 29
src/DefaultBtProgressInfoFile.cc

@@ -51,7 +51,6 @@
 #include "util.h"
 #include "a2io.h"
 #include "DownloadFailureException.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "array_fun.h"
 #include "DownloadContext.h"
@@ -111,7 +110,7 @@ void DefaultBtProgressInfoFile::save()
     std::ofstream o(filenameTemp.c_str(), std::ios::out|std::ios::binary);
     if(!o) {
       throw DL_ABORT_EX
-        (StringFormat(EX_SEGMENT_FILE_WRITE, filename_.c_str()).str());
+        (fmt(EX_SEGMENT_FILE_WRITE, filename_.c_str()));
     }
 #ifdef ENABLE_BITTORRENT
     bool torrentDownload = isTorrentDownload();
@@ -199,25 +198,24 @@ void DefaultBtProgressInfoFile::save()
     o.flush();
     if(!o) {
       throw DL_ABORT_EX
-        (StringFormat(EX_SEGMENT_FILE_WRITE, filename_.c_str()).str());
+        (fmt(EX_SEGMENT_FILE_WRITE, filename_.c_str()));
     }
     A2_LOG_INFO(MSG_SAVED_SEGMENT_FILE);
   }
   if(!File(filenameTemp).renameTo(filename_)) {
     throw DL_ABORT_EX
-      (StringFormat(EX_SEGMENT_FILE_WRITE, filename_.c_str()).str());
+      (fmt(EX_SEGMENT_FILE_WRITE, filename_.c_str()));
   }
 }
 
 #define CHECK_STREAM(in, length)                                        \
   if(in.gcount() != length) {                                           \
-  throw DL_ABORT_EX(StringFormat("Failed to read segment file %s."      \
-                                 " Unexpected EOF.",                    \
-                                 filename_.c_str()).str());             \
+    throw DL_ABORT_EX(fmt("Failed to read segment file %s."             \
+                          " Unexpected EOF.",                           \
+                          filename_.c_str()));                          \
   }                                                                     \
   if(!in) {                                                             \
-    throw DL_ABORT_EX                                                   \
-      (StringFormat(EX_SEGMENT_FILE_READ, filename_.c_str()).str());    \
+    throw DL_ABORT_EX(fmt(EX_SEGMENT_FILE_READ, filename_.c_str()));    \
   }
 
 // It is assumed that integers are saved as:
@@ -229,7 +227,7 @@ void DefaultBtProgressInfoFile::load()
   std::ifstream in(filename_.c_str(), std::ios::in|std::ios::binary);
   if(!in) {
     throw DL_ABORT_EX
-      (StringFormat(EX_SEGMENT_FILE_READ, filename_.c_str()).str());
+      (fmt(EX_SEGMENT_FILE_READ, filename_.c_str()));
   }
   unsigned char versionBuf[2];
   in.read(reinterpret_cast<char*>(versionBuf), sizeof(versionBuf));
@@ -242,8 +240,8 @@ void DefaultBtProgressInfoFile::load()
     version = 1;
   } else {
     throw DL_ABORT_EX
-      (StringFormat("Unsupported ctrl file version: %s",
-                    versionHex.c_str()).str());
+      (fmt("Unsupported ctrl file version: %s",
+           versionHex.c_str()));
   }
   unsigned char extension[4];
   in.read(reinterpret_cast<char*>(extension), sizeof(extension));
@@ -263,7 +261,7 @@ void DefaultBtProgressInfoFile::load()
   if((infoHashLength < 0) ||
      ((infoHashLength == 0) && infoHashCheckEnabled)) {
     throw DL_ABORT_EX
-      (StringFormat("Invalid info hash length: %d", infoHashLength).str());
+      (fmt("Invalid info hash length: %d", infoHashLength));
   }
   if(infoHashLength > 0) {
     array_ptr<unsigned char> savedInfoHash(new unsigned char[infoHashLength]);
@@ -276,10 +274,10 @@ void DefaultBtProgressInfoFile::load()
       if(infoHashLength != INFO_HASH_LENGTH ||
          memcmp(savedInfoHash, infoHash, INFO_HASH_LENGTH) != 0) {
         throw DL_ABORT_EX
-          (StringFormat("info hash mismatch. expected: %s, actual: %s",
-                        util::toHex(infoHash, INFO_HASH_LENGTH).c_str(),
-                        util::toHex(savedInfoHash, infoHashLength).c_str()
-                        ).str());
+          (fmt("info hash mismatch. expected: %s, actual: %s",
+               util::toHex(infoHash, INFO_HASH_LENGTH).c_str(),
+               util::toHex(savedInfoHash, infoHashLength).c_str()
+               ));
       }
     }
 #endif // ENABLE_BITTORRENT
@@ -300,9 +298,9 @@ void DefaultBtProgressInfoFile::load()
   }
   if(totalLength != dctx_->getTotalLength()) {
     throw DL_ABORT_EX
-      (StringFormat("total length mismatch. expected: %s, actual: %s",
-                    util::itos(dctx_->getTotalLength()).c_str(),
-                    util::itos(totalLength).c_str()).str());
+      (fmt("total length mismatch. expected: %s, actual: %s",
+           util::itos(dctx_->getTotalLength()).c_str(),
+           util::itos(totalLength).c_str()));
   }
   uint64_t uploadLength;
   in.read(reinterpret_cast<char*>(&uploadLength), sizeof(uploadLength));
@@ -326,9 +324,9 @@ void DefaultBtProgressInfoFile::load()
     ((totalLength+pieceLength-1)/pieceLength+7)/8;
   if(expectedBitfieldLength != bitfieldLength) {
     throw DL_ABORT_EX
-      (StringFormat("bitfield length mismatch. expected: %d, actual: %d",
-                    expectedBitfieldLength,
-                    bitfieldLength).str());
+      (fmt("bitfield length mismatch. expected: %d, actual: %d",
+           expectedBitfieldLength,
+           bitfieldLength));
   }
 
   array_ptr<unsigned char> savedBitfield(new unsigned char[bitfieldLength]);
@@ -356,7 +354,7 @@ void DefaultBtProgressInfoFile::load()
       }
       if(!(index < dctx_->getNumPieces())) {
         throw DL_ABORT_EX
-          (StringFormat("piece index out of range: %u", index).str());
+          (fmt("piece index out of range: %u", index));
       }
       uint32_t length;
       in.read(reinterpret_cast<char*>(&length), sizeof(length));
@@ -366,7 +364,7 @@ void DefaultBtProgressInfoFile::load()
       }
       if(!(length <=dctx_->getPieceLength())) {
         throw DL_ABORT_EX
-          (StringFormat("piece length out of range: %u", length).str());
+          (fmt("piece length out of range: %u", length));
       }
       SharedHandle<Piece> piece(new Piece(index, length));
       uint32_t bitfieldLength;
@@ -378,10 +376,10 @@ void DefaultBtProgressInfoFile::load()
       }
       if(piece->getBitfieldLength() != bitfieldLength) {
         throw DL_ABORT_EX
-          (StringFormat("piece bitfield length mismatch."
-                        " expected: %lu actual: %u",
-                        static_cast<unsigned long>(piece->getBitfieldLength()),
-                        bitfieldLength).str());
+          (fmt("piece bitfield length mismatch."
+               " expected: %lu actual: %u",
+               static_cast<unsigned long>(piece->getBitfieldLength()),
+               bitfieldLength));
       }
       array_ptr<unsigned char> pieceBitfield
         (new unsigned char[bitfieldLength]);

+ 11 - 11
src/DefaultExtensionMessageFactory.cc

@@ -37,7 +37,7 @@
 #include "DlAbortEx.h"
 #include "HandshakeExtensionMessage.h"
 #include "UTPexExtensionMessage.h"
-#include "StringFormat.h"
+#include "fmt.h"
 #include "PeerStorage.h"
 #include "ExtensionMessageRegistry.h"
 #include "DownloadContext.h"
@@ -84,8 +84,8 @@ DefaultExtensionMessageFactory::createMessage(const unsigned char* data, size_t
     std::string extensionName = registry_->getExtensionName(extensionMessageID);
     if(extensionName.empty()) {
       throw DL_ABORT_EX
-        (StringFormat("No extension registered for extended message ID %u",
-                      extensionMessageID).str());
+        (fmt("No extension registered for extended message ID %u",
+             extensionMessageID));
     }
     if(extensionName == "ut_pex") {
       // uTorrent compatible Peer-Exchange
@@ -96,9 +96,9 @@ DefaultExtensionMessageFactory::createMessage(const unsigned char* data, size_t
     } else if(extensionName == "ut_metadata") {
       if(length == 0) {
         throw DL_ABORT_EX
-          (StringFormat(MSG_TOO_SMALL_PAYLOAD_SIZE,
-                        "ut_metadata",
-                        static_cast<unsigned long>(length)).str());
+          (fmt(MSG_TOO_SMALL_PAYLOAD_SIZE,
+               "ut_metadata",
+               static_cast<unsigned long>(length)));
       }
       size_t end;
       SharedHandle<ValueBase> decoded = bencode2::decode(data+1, length-1, end);
@@ -152,14 +152,14 @@ DefaultExtensionMessageFactory::createMessage(const unsigned char* data, size_t
       }
       default:
         throw DL_ABORT_EX
-          (StringFormat("Bad ut_metadata: unknown msg_type=%u",
-                        static_cast<unsigned int>(msgType->i())).str());
+          (fmt("Bad ut_metadata: unknown msg_type=%u",
+               static_cast<unsigned int>(msgType->i())));
       }
     } else {
       throw DL_ABORT_EX
-        (StringFormat("Unsupported extension message received."
-                      " extensionMessageID=%u, extensionName=%s",
-                      extensionMessageID, extensionName.c_str()).str());
+        (fmt("Unsupported extension message received."
+             " extensionMessageID=%u, extensionName=%s",
+             extensionMessageID, extensionName.c_str()));
     }
   }
 }

+ 0 - 1
src/DefaultPieceStorage.cc

@@ -54,7 +54,6 @@
 #include "util.h"
 #include "a2functional.h"
 #include "Option.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "RarestPieceSelector.h"
 #include "array_fun.h"

+ 6 - 7
src/DownloadCommand.cc

@@ -56,7 +56,6 @@
 #include "Socket.h"
 #include "message.h"
 #include "prefs.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "RequestGroupMan.h"
 #include "wallclock.h"
@@ -259,10 +258,10 @@ void DownloadCommand::checkLowestDownloadSpeed() const
      startupIdleTime_) {
     unsigned int nowSpeed = peerStat_->calculateDownloadSpeed();
     if(nowSpeed <= lowestDownloadSpeedLimit_) {
-      throw DL_ABORT_EX2(StringFormat(EX_TOO_SLOW_DOWNLOAD_SPEED,
-                                      nowSpeed,
-                                      lowestDownloadSpeedLimit_,
-                                      getRequest()->getHost().c_str()).str(),
+      throw DL_ABORT_EX2(fmt(EX_TOO_SLOW_DOWNLOAD_SPEED,
+                             nowSpeed,
+                             lowestDownloadSpeedLimit_,
+                             getRequest()->getHost().c_str()),
                          downloadresultcode::TOO_SLOW_DOWNLOAD_SPEED);
     }
   }
@@ -348,8 +347,8 @@ void DownloadCommand::validatePieceHash(const SharedHandle<Segment>& segment,
     segment->clear();
     getSegmentMan()->cancelSegment(getCuid());
     throw DL_RETRY_EX
-      (StringFormat("Invalid checksum index=%lu",
-                    static_cast<unsigned long>(segment->getIndex())).str());
+      (fmt("Invalid checksum index=%lu",
+           static_cast<unsigned long>(segment->getIndex())));
   }
 }
 

+ 4 - 4
src/DownloadContext.cc

@@ -37,7 +37,7 @@
 #include <algorithm>
 
 #include "FileEntry.h"
-#include "StringFormat.h"
+#include "fmt.h"
 #include "util.h"
 #include "wallclock.h"
 #include "DlAbortEx.h"
@@ -123,8 +123,8 @@ void DownloadContext::setFilePathWithIndex
     // We don't escape path because path may come from users.
     fileEntries_[index-1]->setPath(path);
   } else {
-    throw DL_ABORT_EX(StringFormat("No such file with index=%u",
-                                   static_cast<unsigned int>(index)).str());
+    throw DL_ABORT_EX(fmt("No such file with index=%u",
+                          static_cast<unsigned int>(index)));
   }
 }
 
@@ -165,7 +165,7 @@ const SharedHandle<ContextAttribute>& DownloadContext::getAttribute
   std::map<std::string, SharedHandle<ContextAttribute> >::const_iterator itr =
     attrs_.find(key);
   if(itr == attrs_.end()) {
-    throw DL_ABORT_EX(StringFormat("No attribute named %s", key.c_str()).str());
+    throw DL_ABORT_EX(fmt("No attribute named %s", key.c_str()));
   } else {
     return (*itr).second;
   }

+ 2 - 3
src/FtpConnection.cc

@@ -52,7 +52,6 @@
 #include "DlAbortEx.h"
 #include "Socket.h"
 #include "A2STR.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "AuthConfig.h"
 #include "a2functional.h"
@@ -374,8 +373,8 @@ bool FtpConnection::bulkReceiveResponse
     }
     if(strbuf_.size()+size > MAX_RECV_BUFFER) {
       throw DL_RETRY_EX
-        (StringFormat("Max FTP recv buffer reached. length=%lu",
-                      static_cast<unsigned long>(strbuf_.size()+size)).str());
+        (fmt("Max FTP recv buffer reached. length=%lu",
+             static_cast<unsigned long>(strbuf_.size()+size)));
     }
     strbuf_.append(&buf[0], &buf[size]);
   }

+ 0 - 1
src/FtpFinishDownloadCommand.cc

@@ -42,7 +42,6 @@
 #include "Option.h"
 #include "FtpConnection.h"
 #include "message.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "DlAbortEx.h"
 #include "SocketCore.h"

+ 15 - 16
src/FtpNegotiationCommand.cc

@@ -59,7 +59,6 @@
 #include "RequestGroupMan.h"
 #include "DownloadFailureException.h"
 #include "Socket.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "DiskAdaptor.h"
 #include "SegmentMan.h"
@@ -184,7 +183,7 @@ bool FtpNegotiationCommand::recvUser() {
     sequence_ = SEQ_SEND_PASS;
     break;
   default:
-    throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
+    throw DL_ABORT_EX(fmt(EX_BAD_STATUS, status));
   }
   return true;
 }
@@ -205,7 +204,7 @@ bool FtpNegotiationCommand::recvPass() {
     return false;
   }
   if(status != 230) {
-    throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
+    throw DL_ABORT_EX(fmt(EX_BAD_STATUS, status));
   }
   sequence_ = SEQ_SEND_TYPE;
   return true;
@@ -227,7 +226,7 @@ bool FtpNegotiationCommand::recvType() {
     return false;
   }
   if(status != 200) {
-    throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
+    throw DL_ABORT_EX(fmt(EX_BAD_STATUS, status));
   }
   sequence_ = SEQ_SEND_PWD;
   return true;
@@ -252,7 +251,7 @@ bool FtpNegotiationCommand::recvPwd()
     return false;
   }
   if(status != 257) {
-    throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
+    throw DL_ABORT_EX(fmt(EX_BAD_STATUS, status));
   }
   ftp_->setBaseWorkingDir(pwd);
   A2_LOG_INFO(fmt("CUID#%s - base working directory is '%s'",
@@ -296,7 +295,7 @@ bool FtpNegotiationCommand::recvCwd()
       throw DL_ABORT_EX2(MSG_RESOURCE_NOT_FOUND,
                          downloadresultcode::RESOURCE_NOT_FOUND);
     else
-      throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
+      throw DL_ABORT_EX(fmt(EX_BAD_STATUS, status));
   }
   cwdDirs_.pop_front();
   if(cwdDirs_.empty()) {
@@ -369,8 +368,8 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
   if(getDownloadEngine()->getRequestGroupMan()->
      isSameFileBeingDownloaded(getRequestGroup())) {
     throw DOWNLOAD_FAILURE_EXCEPTION
-      (StringFormat(EX_DUPLICATE_FILE_DOWNLOAD,
-                    getRequestGroup()->getFirstFilePath().c_str()).str());
+      (fmt(EX_DUPLICATE_FILE_DOWNLOAD,
+           getRequestGroup()->getFirstFilePath().c_str()));
   }
   if(totalLength == 0) {
 
@@ -462,8 +461,8 @@ bool FtpNegotiationCommand::recvSize() {
 
     if(size > INT64_MAX) {
       throw DL_ABORT_EX
-        (StringFormat(EX_TOO_LARGE_FILE,
-                      util::uitos(size, true).c_str()).str());
+        (fmt(EX_TOO_LARGE_FILE,
+             util::uitos(size, true).c_str()));
     }
     if(!getPieceStorage()) {
 
@@ -563,7 +562,7 @@ bool FtpNegotiationCommand::recvPort() {
     return false;
   }
   if(status != 200) {
-    throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
+    throw DL_ABORT_EX(fmt(EX_BAD_STATUS, status));
   }
   sequence_ = SEQ_SEND_REST;
   return true;
@@ -624,7 +623,7 @@ bool FtpNegotiationCommand::recvPasv() {
     return false;
   }
   if(status != 227) {
-    throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
+    throw DL_ABORT_EX(fmt(EX_BAD_STATUS, status));
   }
   dataConnAddr_ = dest;
 
@@ -688,8 +687,8 @@ bool FtpNegotiationCommand::sendTunnelRequest()
           getDownloadEngine()->removeCachedIPAddress(proxyReq->getHost(),
                                                      proxyReq->getPort());
           throw DL_RETRY_EX
-            (StringFormat(MSG_ESTABLISHING_CONNECTION_FAILED,
-                          error.c_str()).str());
+            (fmt(MSG_ESTABLISHING_CONNECTION_FAILED,
+                 error.c_str()));
         } else {
           A2_LOG_INFO(fmt(MSG_CONNECT_FAILED_AND_RETRY,
                           util::itos(getCuid()).c_str(),
@@ -745,7 +744,7 @@ bool FtpNegotiationCommand::sendRestPasv(const SharedHandle<Segment>& segment) {
   if(dataSocket_->isReadable(0)) {
     std::string error = dataSocket_->getSocketError();
     throw DL_ABORT_EX
-      (StringFormat(MSG_ESTABLISHING_CONNECTION_FAILED, error.c_str()).str());
+      (fmt(MSG_ESTABLISHING_CONNECTION_FAILED, error.c_str()));
   }
   setReadCheckSocket(getSocket());
   disableWriteCheckSocket();
@@ -800,7 +799,7 @@ bool FtpNegotiationCommand::recvRetr() {
       throw DL_ABORT_EX2(MSG_RESOURCE_NOT_FOUND,
                          downloadresultcode::RESOURCE_NOT_FOUND);
     else
-      throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
+      throw DL_ABORT_EX(fmt(EX_BAD_STATUS, status));
   }
   if(getOption()->getAsBool(PREF_FTP_PASV)) {
     sequence_ = SEQ_NEGOTIATION_COMPLETED;

+ 3 - 3
src/GZipDecoder.cc

@@ -33,7 +33,7 @@
  */
 /* copyright --> */
 #include "GZipDecoder.h"
-#include "StringFormat.h"
+#include "fmt.h"
 #include "DlAbortEx.h"
 
 namespace aria2 {
@@ -94,8 +94,8 @@ std::string GZipDecoder::decode(const unsigned char* in, size_t length)
     if(ret == Z_STREAM_END) {
       finished_ = true;
     } else if(ret != Z_OK) {
-      throw DL_ABORT_EX(StringFormat("libz::inflate() failed. cause:%s",
-                                     strm_->msg).str());
+      throw DL_ABORT_EX(fmt("libz::inflate() failed. cause:%s",
+                            strm_->msg));
     }
 
     size_t produced = OUTBUF_LENGTH-strm_->avail_out;

+ 3 - 3
src/GZipDecodingStreamFilter.cc

@@ -36,7 +36,7 @@
 
 #include <cassert>
 
-#include "StringFormat.h"
+#include "fmt.h"
 #include "DlAbortEx.h"
 
 namespace aria2 {
@@ -102,8 +102,8 @@ ssize_t GZipDecodingStreamFilter::transform
     if(ret == Z_STREAM_END) {
       finished_ = true;
     } else if(ret != Z_OK) {
-      throw DL_ABORT_EX(StringFormat("libz::inflate() failed. cause:%s",
-                                     strm_->msg).str());
+      throw DL_ABORT_EX(fmt("libz::inflate() failed. cause:%s",
+                            strm_->msg));
     }
 
     size_t produced = OUTBUF_LENGTH-strm_->avail_out;

+ 3 - 3
src/GZipEncoder.cc

@@ -36,7 +36,7 @@
 
 #include <cstring>
 
-#include "StringFormat.h"
+#include "fmt.h"
 #include "DlAbortEx.h"
 #include "util.h"
 
@@ -97,8 +97,8 @@ std::string GZipEncoder::encode
     if(ret == Z_STREAM_END) {
       finished_ = true;
     } else if(ret != Z_OK) {
-      throw DL_ABORT_EX(StringFormat("libz::deflate() failed. cause:%s",
-                                     strm_->msg).str());
+      throw DL_ABORT_EX(fmt("libz::deflate() failed. cause:%s",
+                            strm_->msg));
     }
 
     size_t produced = OUTBUF_LENGTH-strm_->avail_out;

+ 3 - 4
src/HandshakeExtensionMessage.cc

@@ -39,7 +39,6 @@
 #include "LogFactory.h"
 #include "Logger.h"
 #include "message.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "bencode2.h"
 #include "DownloadContext.h"
@@ -171,9 +170,9 @@ HandshakeExtensionMessage::create(const unsigned char* data, size_t length)
 {
   if(length < 1) {
     throw DL_ABORT_EX
-      (StringFormat(MSG_TOO_SMALL_PAYLOAD_SIZE,
-                    EXTENSION_NAME.c_str(),
-                    static_cast<unsigned long>(length)).str());
+      (fmt(MSG_TOO_SMALL_PAYLOAD_SIZE,
+           EXTENSION_NAME.c_str(),
+           static_cast<unsigned long>(length)));
   }
   HandshakeExtensionMessageHandle msg(new HandshakeExtensionMessage());
   A2_LOG_DEBUG(fmt("Creating HandshakeExtensionMessage from %s",

+ 2 - 2
src/HashFuncEntry.h

@@ -41,7 +41,7 @@
 #include <algorithm>
 
 #include "DlAbortEx.h"
-#include "StringFormat.h"
+#include "fmt.h"
 
 namespace aria2 {
 
@@ -79,7 +79,7 @@ const typename HashFuncEntry::HashFuncType& getHashFunc
                  (hashType));
   if(e == last) {
     throw DL_ABORT_EX
-      (StringFormat("Hash type %s is not supported.", hashType.c_str()).str());
+      (fmt("Hash type %s is not supported.", hashType.c_str()));
   }
   return e->hashFunc;
 }

+ 12 - 16
src/HttpResponse.cc

@@ -44,7 +44,6 @@
 #include "message.h"
 #include "DlAbortEx.h"
 #include "DlRetryEx.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "A2STR.h"
 #include "CookieStorage.h"
@@ -78,8 +77,7 @@ void HttpResponse::validateResponse() const
             statusCode == 303 ||
             statusCode == 307) {
     if(!httpHeader_->defined(HttpHeader::LOCATION)) {
-      throw DL_ABORT_EX
-        (StringFormat(EX_LOCATION_HEADER_REQUIRED, statusCode).str());
+      throw DL_ABORT_EX(fmt(EX_LOCATION_HEADER_REQUIRED, statusCode));
     }
     return;
   } else if(statusCode == 200 || statusCode == 206) {
@@ -88,20 +86,18 @@ void HttpResponse::validateResponse() const
       RangeHandle responseRange = httpHeader_->getRange();
       if(!httpRequest_->isRangeSatisfied(responseRange)) {
         throw DL_ABORT_EX2
-          (StringFormat
-           (EX_INVALID_RANGE_HEADER,
-            util::itos(httpRequest_->getStartByte(), true).c_str(),
-            util::itos(httpRequest_->getEndByte(), true).c_str(),
-            util::uitos(httpRequest_->getEntityLength(), true).c_str(),
-            util::itos(responseRange->getStartByte(), true).c_str(),
-            util::itos(responseRange->getEndByte(), true).c_str(),
-            util::uitos(responseRange->getEntityLength(), true).c_str()).str(),
+          (fmt(EX_INVALID_RANGE_HEADER,
+               util::itos(httpRequest_->getStartByte(), true).c_str(),
+               util::itos(httpRequest_->getEndByte(), true).c_str(),
+               util::uitos(httpRequest_->getEntityLength(), true).c_str(),
+               util::itos(responseRange->getStartByte(), true).c_str(),
+               util::itos(responseRange->getEndByte(), true).c_str(),
+               util::uitos(responseRange->getEntityLength(), true).c_str()),
            downloadresultcode::CANNOT_RESUME);
       }
     }
   } else {
-    throw DL_ABORT_EX
-      (StringFormat("Unexpected status %d", statusCode).str());
+    throw DL_ABORT_EX(fmt("Unexpected status %d", statusCode));
   }
 }
 
@@ -155,9 +151,9 @@ void HttpResponse::processRedirect()
                     httpRequest_->getRequest()->getCurrentUri().c_str()));
   } else {
     throw DL_RETRY_EX
-      (StringFormat("CUID#%s - Redirect to %s failed. It may not be a valid"
-                    " URI.", util::itos(cuid_).c_str(),
-                    httpRequest_->getRequest()->getCurrentUri().c_str()).str());
+      (fmt("CUID#%s - Redirect to %s failed. It may not be a valid URI.",
+           util::itos(cuid_).c_str(),
+           httpRequest_->getRequest()->getCurrentUri().c_str()));
   }
 }
 

+ 4 - 5
src/HttpResponseCommand.cc

@@ -57,7 +57,6 @@
 #include "Socket.h"
 #include "message.h"
 #include "prefs.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "HttpSkipResponseCommand.h"
 #include "HttpHeader.h"
@@ -88,8 +87,8 @@ SharedHandle<StreamFilter> getTransferEncodingStreamFilter
     filter = httpResponse->getTransferEncodingStreamFilter();
     if(!filter) {
       throw DL_ABORT_EX
-        (StringFormat(EX_TRANSFER_ENCODING_NOT_SUPPORTED,
-                      httpResponse->getTransferEncoding().c_str()).str());
+        (fmt(EX_TRANSFER_ENCODING_NOT_SUPPORTED,
+             httpResponse->getTransferEncoding().c_str()));
     }
     filter->init();
     filter->installDelegate(delegate);
@@ -215,8 +214,8 @@ bool HttpResponseCommand::executeInternal()
     if(getDownloadEngine()->getRequestGroupMan()->
        isSameFileBeingDownloaded(getRequestGroup())) {
       throw DOWNLOAD_FAILURE_EXCEPTION
-        (StringFormat(EX_DUPLICATE_FILE_DOWNLOAD,
-                      getRequestGroup()->getFirstFilePath().c_str()).str());
+        (fmt(EX_DUPLICATE_FILE_DOWNLOAD,
+             getRequestGroup()->getFirstFilePath().c_str()));
     }
     // update last modified time
     updateLastModifiedTime(httpResponse->getLastModifiedTime());

+ 2 - 4
src/HttpSkipResponseCommand.cc

@@ -45,7 +45,6 @@
 #include "HttpRequest.h"
 #include "Segment.h"
 #include "util.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "DlAbortEx.h"
 #include "HttpHeader.h"
@@ -176,8 +175,7 @@ bool HttpSkipResponseCommand::processResponse()
     unsigned int rnum =
       httpResponse_->getHttpRequest()->getRequest()->getRedirectCount();
     if(rnum >= Request::MAX_REDIRECT) {
-      throw DL_ABORT_EX
-        (StringFormat("Too many redirects: count=%u", rnum).str());
+      throw DL_ABORT_EX(fmt("Too many redirects: count=%u", rnum));
     }
     httpResponse_->processRedirect();
     return prepareForRetry(0);
@@ -195,7 +193,7 @@ bool HttpSkipResponseCommand::processResponse()
       throw DL_ABORT_EX2(MSG_RESOURCE_NOT_FOUND,
                          downloadresultcode::RESOURCE_NOT_FOUND);
     } else {
-      throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, statusCode).str());
+      throw DL_ABORT_EX(fmt(EX_BAD_STATUS, statusCode));
     }
   } else {
     return prepareForRetry(0);

+ 5 - 5
src/InitiateConnectionCommandFactory.cc

@@ -39,7 +39,7 @@
 #include "RequestGroup.h"
 #include "DownloadEngine.h"
 #include "DlAbortEx.h"
-#include "StringFormat.h"
+#include "fmt.h"
 #include "Option.h"
 #include "prefs.h"
 #include "SocketCore.h"
@@ -73,16 +73,16 @@ InitiateConnectionCommandFactory::createInitiateConnectionCommand
   } else if(req->getProtocol() == Request::PROTO_FTP) {
     if(req->getFile().empty()) {
       throw DL_ABORT_EX
-        (StringFormat("FTP URI %s doesn't contain file path.",
-                      req->getUri().c_str()).str());
+        (fmt("FTP URI %s doesn't contain file path.",
+             req->getUri().c_str()));
     }
     return
       new FtpInitiateConnectionCommand(cuid, req, fileEntry, requestGroup, e);
   } else {
     // these protocols are not supported yet
     throw DL_ABORT_EX
-      (StringFormat("%s is not supported yet.",
-                    req->getProtocol().c_str()).str());
+      (fmt("%s is not supported yet.",
+           req->getProtocol().c_str()));
   }
 }
 

+ 2 - 3
src/IteratableChunkChecksumValidator.cc

@@ -49,7 +49,6 @@
 #include "LogFactory.h"
 #include "Logger.h"
 #include "MessageDigest.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "DlAbortEx.h"
 
@@ -158,8 +157,8 @@ std::string IteratableChunkChecksumValidator::digest(off_t offset, size_t length
                                                          curoffset);
     if(r == 0 || r < static_cast<size_t>(woffset)) {
       throw DL_ABORT_EX
-        (StringFormat(EX_FILE_READ, dctx_->getBasePath().c_str(),
-                      "data is too short").str());
+        (fmt(EX_FILE_READ, dctx_->getBasePath().c_str(),
+             "data is too short"));
     }
     size_t wlength;
     if(max < static_cast<off_t>(curoffset+r)) {

+ 3 - 3
src/LibgcryptARC4Context.cc

@@ -34,7 +34,7 @@
 /* copyright --> */
 #include "LibgcryptARC4Context.h"
 #include "DlAbortEx.h"
-#include "StringFormat.h"
+#include "fmt.h"
 
 namespace aria2 {
 
@@ -42,8 +42,8 @@ namespace {
 void handleError(gcry_error_t err)
 {
   throw DL_ABORT_EX
-    (StringFormat("Exception in libgcrypt routine(ARC4Context class): %s",
-                  gcry_strerror(err)).str());
+    (fmt("Exception in libgcrypt routine(ARC4Context class): %s",
+         gcry_strerror(err)));
 }
 } // namespace
 

+ 3 - 3
src/LibgcryptARC4Decryptor.cc

@@ -37,7 +37,7 @@
 #include <gcrypt.h>
 
 #include "DlAbortEx.h"
-#include "StringFormat.h"
+#include "fmt.h"
 
 namespace aria2 {
 
@@ -45,8 +45,8 @@ namespace {
 void handleError(gcry_error_t err)
 {
   throw DL_ABORT_EX
-    (StringFormat("Exception in libgcrypt routine(ARC4Decryptor class): %s",
-                  gcry_strerror(err)).str());
+    (fmt("Exception in libgcrypt routine(ARC4Decryptor class): %s",
+         gcry_strerror(err)));
 }
 } // namespace
 

+ 3 - 3
src/LibgcryptARC4Encryptor.cc

@@ -37,7 +37,7 @@
 #include <gcrypt.h>
 
 #include "DlAbortEx.h"
-#include "StringFormat.h"
+#include "fmt.h"
 
 namespace aria2 {
 
@@ -45,8 +45,8 @@ namespace {
 void handleError(gcry_error_t err)
 {
   throw DL_ABORT_EX
-    (StringFormat("Exception in libgcrypt routine(ARC4Encryptor class): %s",
-                  gcry_strerror(err)).str());
+    (fmt("Exception in libgcrypt routine(ARC4Encryptor class): %s",
+         gcry_strerror(err)));
 }
 } // namespace
 

+ 9 - 10
src/LibgcryptDHKeyExchange.cc

@@ -34,7 +34,7 @@
 /* copyright --> */
 #include "LibgcryptDHKeyExchange.h"
 #include "DlAbortEx.h"
-#include "StringFormat.h"
+#include "fmt.h"
 
 namespace aria2 {
 
@@ -42,8 +42,8 @@ namespace {
 void handleError(gcry_error_t err)
 {
   throw DL_ABORT_EX
-    (StringFormat("Exception in libgcrypt routine(DHKeyExchange class): %s",
-                  gcry_strerror(err)).str());
+    (fmt("Exception in libgcrypt routine(DHKeyExchange class): %s",
+         gcry_strerror(err)));
 }
 } // namespace
 
@@ -100,10 +100,9 @@ size_t DHKeyExchange::getPublicKey(unsigned char* out, size_t outLength) const
 {
   if(outLength < keyLength_) {
     throw DL_ABORT_EX
-      (StringFormat
-       ("Insufficient buffer for public key. expect:%lu, actual:%lu",
-        static_cast<unsigned long>(keyLength_),
-        static_cast<unsigned long>(outLength)).str());
+      (fmt("Insufficient buffer for public key. expect:%lu, actual:%lu",
+           static_cast<unsigned long>(keyLength_),
+           static_cast<unsigned long>(outLength)));
   }
   memset(out, 0, outLength);
   size_t publicKeyBytes = (gcry_mpi_get_nbits(publicKey_)+7)/8;
@@ -128,9 +127,9 @@ size_t DHKeyExchange::computeSecret(unsigned char* out, size_t outLength,
 {
   if(outLength < keyLength_) {
     throw DL_ABORT_EX
-      (StringFormat("Insufficient buffer for secret. expect:%lu, actual:%lu",
-                    static_cast<unsigned long>(keyLength_),
-                    static_cast<unsigned long>(outLength)).str());
+      (fmt("Insufficient buffer for secret. expect:%lu, actual:%lu",
+           static_cast<unsigned long>(keyLength_),
+           static_cast<unsigned long>(outLength)));
   }
   gcry_mpi_t peerPublicKey;
   {

+ 0 - 1
src/LibgnutlsTLSContext.cc

@@ -40,7 +40,6 @@
 
 #include "LogFactory.h"
 #include "Logger.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "message.h"
 

+ 3 - 3
src/LibsslARC4Context.cc

@@ -37,7 +37,7 @@
 #include <openssl/err.h>
 
 #include "DlAbortEx.h"
-#include "StringFormat.h"
+#include "fmt.h"
 
 namespace aria2 {
 
@@ -45,8 +45,8 @@ namespace {
 void handleError()
 {
   throw DL_ABORT_EX
-    (StringFormat("Exception in libssl routine(ARC4Context class): %s",
-                  ERR_error_string(ERR_get_error(), 0)).str());
+    (fmt("Exception in libssl routine(ARC4Context class): %s",
+         ERR_error_string(ERR_get_error(), 0)));
 }
 } // namespace
 

+ 3 - 3
src/LibsslARC4Decryptor.cc

@@ -37,7 +37,7 @@
 #include <openssl/err.h>
 
 #include "DlAbortEx.h"
-#include "StringFormat.h"
+#include "fmt.h"
 
 namespace aria2 {
 
@@ -45,8 +45,8 @@ namespace {
 void handleError()
 {
   throw DL_ABORT_EX
-    (StringFormat("Exception in libssl routine(ARC4Decryptor class): %s",
-                  ERR_error_string(ERR_get_error(), 0)).str());
+    (fmt("Exception in libssl routine(ARC4Decryptor class): %s",
+         ERR_error_string(ERR_get_error(), 0)));
 }
 } // namespace
 

+ 3 - 3
src/LibsslARC4Encryptor.cc

@@ -37,7 +37,7 @@
 #include <openssl/err.h>
 
 #include "DlAbortEx.h"
-#include "StringFormat.h"
+#include "fmt.h"
 
 namespace aria2 {
 
@@ -45,8 +45,8 @@ namespace {
 void handleError()
 {
   throw DL_ABORT_EX
-    (StringFormat("Exception in libssl routine(ARC4Encryptor class): %s",
-                  ERR_error_string(ERR_get_error(), 0)).str());
+    (fmt("Exception in libssl routine(ARC4Encryptor class): %s",
+         ERR_error_string(ERR_get_error(), 0)));
 }
 } // namespace
 

+ 17 - 20
src/LibsslDHKeyExchange.cc

@@ -40,7 +40,7 @@
 #include <openssl/err.h>
 
 #include "DlAbortEx.h"
-#include "StringFormat.h"
+#include "fmt.h"
 
 namespace aria2 {
 
@@ -48,8 +48,8 @@ namespace {
 void handleError(const std::string& funName)
 {
   throw DL_ABORT_EX
-    (StringFormat("Exception in libssl routine %s(DHKeyExchange class): %s",
-                  funName.c_str(), ERR_error_string(ERR_get_error(), 0)).str());
+    (fmt("Exception in libssl routine %s(DHKeyExchange class): %s",
+         funName.c_str(), ERR_error_string(ERR_get_error(), 0)));
 }
 } // namespace
 
@@ -113,10 +113,9 @@ size_t DHKeyExchange::getPublicKey
 {
   if(outLength < keyLength_) {
     throw DL_ABORT_EX
-      (StringFormat
-       ("Insufficient buffer for public key. expect:%lu, actual:%lu",
-        static_cast<unsigned long>(keyLength_),
-        static_cast<unsigned long>(outLength)).str());
+      (fmt("Insufficient buffer for public key. expect:%lu, actual:%lu",
+           static_cast<unsigned long>(keyLength_),
+           static_cast<unsigned long>(outLength)));
   }
   memset(out, 0, outLength);
   size_t publicKeyBytes = BN_num_bytes(publicKey_);
@@ -124,11 +123,10 @@ size_t DHKeyExchange::getPublicKey
   size_t nwritten = BN_bn2bin(publicKey_, out+offset);
   if(nwritten != publicKeyBytes) {
     throw DL_ABORT_EX
-      (StringFormat
-       ("BN_bn2bin in DHKeyExchange::getPublicKey, %lu bytes written,"
-        " but %lu bytes expected.",
-        static_cast<unsigned long>(nwritten),
-        static_cast<unsigned long>(publicKeyBytes)).str());
+      (fmt("BN_bn2bin in DHKeyExchange::getPublicKey, %lu bytes written,"
+           " but %lu bytes expected.",
+           static_cast<unsigned long>(nwritten),
+           static_cast<unsigned long>(publicKeyBytes)));
   }
   return nwritten;
 }
@@ -146,9 +144,9 @@ size_t DHKeyExchange::computeSecret(unsigned char* out, size_t outLength,
 {
   if(outLength < keyLength_) {
     throw DL_ABORT_EX
-      (StringFormat("Insufficient buffer for secret. expect:%lu, actual:%lu",
-                    static_cast<unsigned long>(keyLength_),
-                    static_cast<unsigned long>(outLength)).str());
+      (fmt("Insufficient buffer for secret. expect:%lu, actual:%lu",
+           static_cast<unsigned long>(keyLength_),
+           static_cast<unsigned long>(outLength)));
   }
 
 
@@ -168,11 +166,10 @@ size_t DHKeyExchange::computeSecret(unsigned char* out, size_t outLength,
   BN_free(secret);
   if(nwritten != secretBytes) {
     throw DL_ABORT_EX
-      (StringFormat
-       ("BN_bn2bin in DHKeyExchange::getPublicKey, %lu bytes written,"
-        " but %lu bytes expected.",
-        static_cast<unsigned long>(nwritten),
-        static_cast<unsigned long>(secretBytes)).str());
+      (fmt("BN_bn2bin in DHKeyExchange::getPublicKey, %lu bytes written,"
+           " but %lu bytes expected.",
+           static_cast<unsigned long>(nwritten),
+           static_cast<unsigned long>(secretBytes)));
   }
   return nwritten;
 }

+ 0 - 1
src/LibsslMessageDigestImpl.cc

@@ -36,7 +36,6 @@
 
 #include <algorithm>
 
-#include "StringFormat.h"
 #include "array_fun.h"
 #include "HashFuncEntry.h"
 

+ 0 - 1
src/LibsslTLSContext.cc

@@ -38,7 +38,6 @@
 
 #include "LogFactory.h"
 #include "Logger.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "message.h"
 

+ 6 - 7
src/MSEHandshake.cc

@@ -54,7 +54,6 @@
 #include "DownloadContext.h"
 #include "prefs.h"
 #include "Option.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "bittorrent_helper.h"
 
@@ -376,8 +375,8 @@ bool MSEHandshake::receiveInitiatorCryptoSelectAndPadDLength()
     }
     if(negotiatedCryptoType_ == CRYPTO_NONE) {
       throw DL_ABORT_EX
-        (StringFormat("CUID#%s - No supported crypto type selected.",
-                      util::itos(cuid_).c_str()).str());
+        (fmt("CUID#%s - No supported crypto type selected.",
+             util::itos(cuid_).c_str()));
     }
   }
   // padD length
@@ -499,8 +498,8 @@ bool MSEHandshake::receiveReceiverHashAndPadCLength
     }
     if(negotiatedCryptoType_ == CRYPTO_NONE) {
       throw DL_ABORT_EX
-        (StringFormat("CUID#%s - No supported crypto type provided.",
-                      util::itos(cuid_).c_str()).str());
+        (fmt("CUID#%s - No supported crypto type provided.",
+             util::itos(cuid_).c_str()));
     }
   }
   // decrypt PadC length
@@ -584,7 +583,7 @@ uint16_t MSEHandshake::verifyPadLength(const unsigned char* padlenbuf, const cha
                    util::itos(cuid_).c_str(), padName, padLength));
   if(padLength > 512) {
     throw DL_ABORT_EX
-      (StringFormat("Too large %s length: %u", padName, padLength).str());
+      (fmt("Too large %s length: %u", padName, padLength));
   }
   return padLength;
 }
@@ -596,7 +595,7 @@ void MSEHandshake::verifyVC(const unsigned char* vcbuf)
   decryptor_->decrypt(vc, sizeof(vc), vcbuf, sizeof(vc));
   if(memcmp(VC, vc, sizeof(VC)) != 0) {
     throw DL_ABORT_EX
-      (StringFormat("Invalid VC: %s", util::toHex(vc, VC_LENGTH).c_str()).str());
+      (fmt("Invalid VC: %s", util::toHex(vc, VC_LENGTH).c_str()));
   }
 }
 

+ 0 - 1
src/Makefile.am

@@ -166,7 +166,6 @@ SRCS =  Socket.h\
 	usage_text.h\
 	ProtocolDetector.cc ProtocolDetector.h\
 	NullStatCalc.h\
-	StringFormat.cc StringFormat.h\
 	HttpSkipResponseCommand.cc HttpSkipResponseCommand.h\
 	InitiateConnectionCommand.cc InitiateConnectionCommand.h\
 	FtpFinishDownloadCommand.cc FtpFinishDownloadCommand.h\

+ 13 - 15
src/Makefile.in

@@ -428,12 +428,12 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
 	TrueRequestGroupCriteria.h a2algo.h a2functional.h a2io.h \
 	a2netcompat.h a2time.h array_fun.h help_tags.h prefs.cc \
 	prefs.h usage_text.h ProtocolDetector.cc ProtocolDetector.h \
-	NullStatCalc.h StringFormat.cc StringFormat.h \
-	HttpSkipResponseCommand.cc HttpSkipResponseCommand.h \
-	InitiateConnectionCommand.cc InitiateConnectionCommand.h \
-	FtpFinishDownloadCommand.cc FtpFinishDownloadCommand.h \
-	A2STR.cc A2STR.h RarestPieceSelector.cc RarestPieceSelector.h \
-	Decoder.h Signature.cc Signature.h ServerStat.cc ServerStat.h \
+	NullStatCalc.h HttpSkipResponseCommand.cc \
+	HttpSkipResponseCommand.h InitiateConnectionCommand.cc \
+	InitiateConnectionCommand.h FtpFinishDownloadCommand.cc \
+	FtpFinishDownloadCommand.h A2STR.cc A2STR.h \
+	RarestPieceSelector.cc RarestPieceSelector.h Decoder.h \
+	Signature.cc Signature.h ServerStat.cc ServerStat.h \
 	ServerStatMan.cc ServerStatMan.h URISelector.h \
 	AdaptiveURISelector.cc AdaptiveURISelector.h \
 	InOrderURISelector.cc InOrderURISelector.h \
@@ -933,8 +933,7 @@ am__objects_32 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
 	ByteArrayDiskWriterFactory.$(OBJEXT) DownloadContext.$(OBJEXT) \
 	TimedHaltCommand.$(OBJEXT) CUIDCounter.$(OBJEXT) \
 	DNSCache.$(OBJEXT) DownloadResult.$(OBJEXT) prefs.$(OBJEXT) \
-	ProtocolDetector.$(OBJEXT) StringFormat.$(OBJEXT) \
-	HttpSkipResponseCommand.$(OBJEXT) \
+	ProtocolDetector.$(OBJEXT) HttpSkipResponseCommand.$(OBJEXT) \
 	InitiateConnectionCommand.$(OBJEXT) \
 	FtpFinishDownloadCommand.$(OBJEXT) A2STR.$(OBJEXT) \
 	RarestPieceSelector.$(OBJEXT) Signature.$(OBJEXT) \
@@ -1275,12 +1274,12 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \
 	TrueRequestGroupCriteria.h a2algo.h a2functional.h a2io.h \
 	a2netcompat.h a2time.h array_fun.h help_tags.h prefs.cc \
 	prefs.h usage_text.h ProtocolDetector.cc ProtocolDetector.h \
-	NullStatCalc.h StringFormat.cc StringFormat.h \
-	HttpSkipResponseCommand.cc HttpSkipResponseCommand.h \
-	InitiateConnectionCommand.cc InitiateConnectionCommand.h \
-	FtpFinishDownloadCommand.cc FtpFinishDownloadCommand.h \
-	A2STR.cc A2STR.h RarestPieceSelector.cc RarestPieceSelector.h \
-	Decoder.h Signature.cc Signature.h ServerStat.cc ServerStat.h \
+	NullStatCalc.h HttpSkipResponseCommand.cc \
+	HttpSkipResponseCommand.h InitiateConnectionCommand.cc \
+	InitiateConnectionCommand.h FtpFinishDownloadCommand.cc \
+	FtpFinishDownloadCommand.h A2STR.cc A2STR.h \
+	RarestPieceSelector.cc RarestPieceSelector.h Decoder.h \
+	Signature.cc Signature.h ServerStat.cc ServerStat.h \
 	ServerStatMan.cc ServerStatMan.h URISelector.h \
 	AdaptiveURISelector.cc AdaptiveURISelector.h \
 	InOrderURISelector.cc InOrderURISelector.h \
@@ -1729,7 +1728,6 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StreamCheckIntegrityEntry.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StreamFileAllocationEntry.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StreamFilter.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StringFormat.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TimeA2.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TimeBasedCommand.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TimeSeedCriteria.Po@am__quote@

+ 7 - 10
src/MessageDigestHelper.cc

@@ -42,7 +42,7 @@
 #include "message.h"
 #include "DefaultDiskWriter.h"
 #include "util.h"
-#include "StringFormat.h"
+#include "fmt.h"
 
 namespace aria2 {
 
@@ -79,8 +79,7 @@ std::string MessageDigestHelper::hexDigest
   for(uint64_t i = 0; i < iteration; ++i) {
     ssize_t readLength = bs->readData(BUF, BUFSIZE, offset);
     if((size_t)readLength != BUFSIZE) {
-      throw DL_ABORT_EX
-        (StringFormat(EX_FILE_READ, "n/a", "data is too short").str());
+      throw DL_ABORT_EX(fmt(EX_FILE_READ, "n/a", "data is too short"));
     }
     ctx->update(BUF, readLength);
     offset += readLength;
@@ -88,8 +87,7 @@ std::string MessageDigestHelper::hexDigest
   if(tail) {
     ssize_t readLength = bs->readData(BUF, tail, offset);
     if((size_t)readLength != tail) {
-      throw DL_ABORT_EX
-        (StringFormat(EX_FILE_READ, "n/a", "data is too short").str());
+      throw DL_ABORT_EX(fmt(EX_FILE_READ, "n/a", "data is too short"));
     }
     ctx->update(BUF, readLength);
   }
@@ -103,11 +101,10 @@ void MessageDigestHelper::digest
   size_t reqLength = ctx->getDigestLength();
   if(mdLength < reqLength) {
     throw DL_ABORT_EX
-      (StringFormat
-       ("Insufficient space for storing message digest:"
-        " %lu required, but only %lu is allocated",
-        static_cast<unsigned long>(reqLength),
-        static_cast<unsigned long>(mdLength)).str());
+      (fmt("Insufficient space for storing message digest:"
+           " %lu required, but only %lu is allocated",
+           static_cast<unsigned long>(reqLength),
+           static_cast<unsigned long>(mdLength)));
   }
   ctx->update(data, length);
   ctx->digest(md);

+ 5 - 6
src/MultiDiskAdaptor.cc

@@ -46,7 +46,6 @@
 #include "DefaultDiskWriterFactory.h"
 #include "DlAbortEx.h"
 #include "File.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "Logger.h"
 #include "LogFactory.h"
@@ -382,8 +381,8 @@ DiskWriterEntries::const_iterator findFirstDiskWriterEntry
   // In case when offset is out-of-range
   if(!isInRange(*first, offset)) {
     throw DL_ABORT_EX
-      (StringFormat(EX_FILE_OFFSET_OUT_OF_RANGE,
-                    util::itos(offset, true).c_str()).str());
+      (fmt(EX_FILE_OFFSET_OUT_OF_RANGE,
+           util::itos(offset, true).c_str()));
   }
   return first;
 }
@@ -394,9 +393,9 @@ void throwOnDiskWriterNotOpened(const SharedHandle<DiskWriterEntry>& e,
                                 off_t offset)
 {
   throw DL_ABORT_EX
-    (StringFormat("DiskWriter for offset=%s, filename=%s is not opened.",
-                  util::itos(offset).c_str(),
-                  e->getFilePath().c_str()).str());  
+    (fmt("DiskWriter for offset=%s, filename=%s is not opened.",
+         util::itos(offset).c_str(),
+         e->getFilePath().c_str()));  
 }
 } // namespace
 

+ 3 - 3
src/NameResolver.cc

@@ -38,7 +38,7 @@
 
 #include "DlAbortEx.h"
 #include "message.h"
-#include "StringFormat.h"
+#include "fmt.h"
 #include "util.h"
 #include "SocketCore.h"
 
@@ -53,8 +53,8 @@ void NameResolver::resolve(std::vector<std::string>& resolvedAddresses,
   int s;
   s = callGetaddrinfo(&res, hostname.c_str(), 0, family_, socktype_, 0, 0);
   if(s) {
-    throw DL_ABORT_EX(StringFormat(EX_RESOLVE_HOSTNAME,
-                                   hostname.c_str(), gai_strerror(s)).str());
+    throw DL_ABORT_EX(fmt(EX_RESOLVE_HOSTNAME,
+                          hostname.c_str(), gai_strerror(s)));
   }
   WSAAPI_AUTO_DELETE<struct addrinfo*> resDeleter(res, freeaddrinfo);
   struct addrinfo* rp;

+ 4 - 5
src/Netrc.cc

@@ -38,7 +38,7 @@
 #include <algorithm>
 
 #include "DlAbortEx.h"
-#include "StringFormat.h"
+#include "fmt.h"
 #include "A2STR.h"
 #include "util.h"
 
@@ -145,8 +145,7 @@ void Netrc::parse(const std::string& path)
   std::ifstream f(path.c_str(), std::ios::binary);
   
   if(!f) {
-    throw DL_ABORT_EX
-      (StringFormat("File not found: %s", path.c_str()).str());
+    throw DL_ABORT_EX(fmt("File not found: %s", path.c_str()));
   }
 
   enum STATE {
@@ -180,8 +179,8 @@ void Netrc::parse(const std::string& path)
         } else {
           if(!authenticator) {
             throw DL_ABORT_EX
-              (StringFormat("Netrc:parse error. %s encounterd where 'machine'"
-                            " or 'default' expected.", token.c_str()).str());
+              (fmt("Netrc:parse error. %s encounterd where 'machine'"
+                   " or 'default' expected.", token.c_str()));
           }
           if(token == Netrc::A2_LOGIN) {
             state = SET_LOGIN;

+ 2 - 3
src/NsCookieParser.cc

@@ -40,7 +40,7 @@
 #include "util.h"
 #include "A2STR.h"
 #include "DlAbortEx.h"
-#include "StringFormat.h"
+#include "fmt.h"
 #include "Cookie.h"
 #include "cookie_helper.h"
 
@@ -96,8 +96,7 @@ std::vector<Cookie> NsCookieParser::parse
 {
   std::ifstream s(filename.c_str(), std::ios::binary);
   if(!s) {
-    throw DL_ABORT_EX
-      (StringFormat("Failed to open file %s", filename.c_str()).str());
+    throw DL_ABORT_EX(fmt("Failed to open file %s", filename.c_str()));
   }
   std::string line;
   std::vector<Cookie> cookies;

+ 3 - 3
src/OptionHandlerException.cc

@@ -33,7 +33,7 @@
  */
 /* copyright --> */
 #include "OptionHandlerException.h"
-#include "StringFormat.h"
+#include "fmt.h"
 
 namespace aria2 {
 
@@ -43,14 +43,14 @@ const std::string OptionHandlerException::MESSAGE
 OptionHandlerException::OptionHandlerException(const char* file, int line,
                                                const std::string& optName):
   RecoverableException
-  (file, line, StringFormat(MESSAGE.c_str(), optName.c_str()).str()),
+  (file, line, fmt(MESSAGE.c_str(), optName.c_str())),
   optName_(optName) {}
 
 OptionHandlerException::OptionHandlerException(const char* file, int line,
                                                const std::string& optName,
                                                const Exception& cause):
   RecoverableException
-  (file, line, StringFormat(MESSAGE.c_str(), optName.c_str()).str(), cause),
+  (file, line, fmt(MESSAGE.c_str(), optName.c_str()), cause),
   optName_(optName) {}
 
 OptionHandlerException::OptionHandlerException(const char* file, int line,

+ 19 - 18
src/OptionHandlerFactory.cc

@@ -40,7 +40,7 @@
 #include "A2STR.h"
 #include "util.h"
 #include "help_tags.h"
-#include "StringFormat.h"
+#include "a2functional.h"
 #include "File.h"
 
 namespace aria2 {
@@ -1652,27 +1652,28 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
   }
   // Help Option
   {
+    static std::string tags[] = {
+      TAG_BASIC,
+      TAG_ADVANCED,
+      TAG_HTTP,
+      TAG_HTTPS,
+      TAG_FTP,
+      TAG_METALINK,
+      TAG_BITTORRENT,
+      TAG_COOKIE,
+      TAG_HOOK,
+      TAG_FILE,
+      TAG_XML_RPC,
+      TAG_EXPERIMENTAL,
+      TAG_HELP,
+      TAG_ALL
+    };
+    static std::string tagsStr = strjoin(vbegin(tags), vend(tags), ", ");
     SharedHandle<OptionHandler> op(new DefaultOptionHandler
                                    ("help",
                                     TEXT_HELP,
                                     TAG_BASIC,
-                                    StringFormat
-                                    ("%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, "
-                                     "%s, %s, %s, %s",
-                                     TAG_BASIC,
-                                     TAG_ADVANCED,
-                                     TAG_HTTP,
-                                     TAG_HTTPS,
-                                     TAG_FTP,
-                                     TAG_METALINK,
-                                     TAG_BITTORRENT,
-                                     TAG_COOKIE,
-                                     TAG_HOOK,
-                                     TAG_FILE,
-                                     TAG_XML_RPC,
-                                     TAG_EXPERIMENTAL,
-                                     TAG_HELP,
-                                     TAG_ALL).str(),
+                                    tagsStr,
                                     OptionHandler::OPT_ARG,
                                     'h'));
     op->addTag(TAG_BASIC);

+ 14 - 18
src/OptionHandlerImpl.cc

@@ -47,7 +47,7 @@
 #include "DlAbortEx.h"
 #include "prefs.h"
 #include "Option.h"
-#include "StringFormat.h"
+#include "fmt.h"
 #include "A2STR.h"
 #include "Request.h"
 #include "a2functional.h"
@@ -171,8 +171,8 @@ void IntegerRangeOptionHandler::parseArg
       std::string msg = optName_;
       strappend(msg, " ", _("must be between %s and %s."));
       throw DL_ABORT_EX
-        (StringFormat(msg.c_str(), util::itos(min_).c_str(),
-                      util::itos(max_).c_str()).str());
+        (fmt(msg.c_str(), util::itos(min_).c_str(),
+             util::itos(max_).c_str()));
     }
     option.put(optName_, optarg);
   }
@@ -212,15 +212,15 @@ void NumberOptionHandler::parseArg(Option& option, int64_t number)
     std::string msg = optName_;
     msg += " ";
     if(min_ == -1 && max_ != -1) {
-      msg += StringFormat(_("must be smaller than or equal to %s."),
-                          util::itos(max_).c_str()).str();
+      msg += fmt(_("must be smaller than or equal to %s."),
+                 util::itos(max_).c_str());
     } else if(min_ != -1 && max_ != -1) {
-      msg += StringFormat(_("must be between %s and %s."),
-                          util::itos(min_).c_str(),
-                          util::itos(max_).c_str()).str();
+      msg += fmt(_("must be between %s and %s."),
+                 util::itos(min_).c_str(),
+                 util::itos(max_).c_str());
     } else if(min_ != -1 && max_ == -1) {
-      msg += StringFormat(_("must be greater than or equal to %s."),
-                          util::itos(min_).c_str()).str();
+      msg += fmt(_("must be greater than or equal to %s."),
+                 util::itos(min_).c_str());
     } else {
       msg += _("must be a number.");
     }
@@ -290,14 +290,11 @@ void FloatNumberOptionHandler::parseArg
     std::string msg = optName_;
     msg += " ";
     if(min_ < 0 && max_ >= 0) {
-      msg += StringFormat(_("must be smaller than or equal to %.1f."),
-                          max_).str();
+      msg += fmt(_("must be smaller than or equal to %.1f."), max_);
     } else if(min_ >= 0 && max_ >= 0) {
-      msg += StringFormat(_("must be between %.1f and %.1f."),
-                          min_, max_).str();
+      msg += fmt(_("must be between %.1f and %.1f."), min_, max_);
     } else if(min_ >= 0 && max_ < 0) {
-      msg += StringFormat(_("must be greater than or equal to %.1f."),
-                          min_).str();
+      msg += fmt(_("must be greater than or equal to %.1f."), min_);
     } else {
       msg += _("must be a number.");
     }
@@ -688,8 +685,7 @@ void LocalFilePathOptionHandler::parseArg
   } else {
     File f(optarg);
     if(!f.exists() || f.isDir()) {
-      throw DL_ABORT_EX
-        (StringFormat(MSG_NOT_FILE, optarg.c_str()).str());
+      throw DL_ABORT_EX(fmt(MSG_NOT_FILE, optarg.c_str()));
     }
     option.put(optName_, optarg);
   }

+ 2 - 3
src/PeerAbstractCommand.cc

@@ -43,7 +43,6 @@
 #include "message.h"
 #include "prefs.h"
 #include "DownloadFailureException.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "wallclock.h"
 #include "util.h"
@@ -97,8 +96,8 @@ bool PeerAbstractCommand::execute()
       checkPoint_ = global::wallclock;
     } else if(errorEventEnabled()) {
       throw DL_ABORT_EX
-        (StringFormat(MSG_NETWORK_PROBLEM,
-                      socket_->getSocketError().c_str()).str());
+        (fmt(MSG_NETWORK_PROBLEM,
+             socket_->getSocketError().c_str()));
     }
     if(checkPoint_.difference(global::wallclock) >= timeout_) {
       throw DL_ABORT_EX(EX_TIME_OUT);

+ 1 - 2
src/PeerConnection.cc

@@ -47,7 +47,6 @@
 #include "a2netcompat.h"
 #include "ARC4Encryptor.h"
 #include "ARC4Decryptor.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "util.h"
 #include "Peer.h"
@@ -139,7 +138,7 @@ bool PeerConnection::receiveMessage(unsigned char* data, size_t& dataLength) {
     memcpy(&payloadLength, lenbuf_, sizeof(payloadLength));
     payloadLength = ntohl(payloadLength);
     if(payloadLength > MAX_PAYLOAD_LEN) {
-      throw DL_ABORT_EX(StringFormat(EX_TOO_LONG_PAYLOAD, payloadLength).str());
+      throw DL_ABORT_EX(fmt(EX_TOO_LONG_PAYLOAD, payloadLength));
     }
     currentPayloadLength_ = payloadLength;
   }

+ 4 - 5
src/PeerReceiveHandshakeCommand.cc

@@ -53,7 +53,6 @@
 #include "prefs.h"
 #include "Option.h"
 #include "RequestGroupMan.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "RequestGroup.h"
 
@@ -97,8 +96,8 @@ bool PeerReceiveHandshakeCommand::executeInternal()
       getDownloadEngine()->getBtRegistry()->getDownloadContext(infoHash);
     if(!downloadContext) {
       throw DL_ABORT_EX
-        (StringFormat("Unknown info hash %s",
-                      util::toHex(infoHash).c_str()).str());
+        (fmt("Unknown info hash %s",
+             util::toHex(infoHash).c_str()));
     }
     BtObject btObject = getDownloadEngine()->getBtRegistry()->get
       (downloadContext->getOwnerRequestGroup()->getGID());
@@ -107,8 +106,8 @@ bool PeerReceiveHandshakeCommand::executeInternal()
     SharedHandle<PeerStorage> peerStorage = btObject.peerStorage_;
     if(!btRuntime->ready()) {
       throw DL_ABORT_EX
-        (StringFormat("Unknown info hash %s",
-                      util::toHex(infoHash).c_str()).str());
+        (fmt("Unknown info hash %s",
+             util::toHex(infoHash).c_str()));
     }
     if(btRuntime->isHalt()) {
       A2_LOG_DEBUG("Info hash found but the download is over."

+ 2 - 2
src/Request.cc

@@ -38,7 +38,7 @@
 #include <utility>
 
 #include "util.h"
-#include "StringFormat.h"
+#include "fmt.h"
 #include "A2STR.h"
 #include "uri.h"
 #include "PeerStat.h"
@@ -101,7 +101,7 @@ std::string percentEncode(const std::string& src)
           result.replace(index, 1, "%25");
         }
       } else {
-        result.replace(index, 1, StringFormat("%%%02X", c).str());
+        result.replace(index, 1, fmt("%%%02X", c));
       }
     }
   }

+ 24 - 29
src/RequestGroup.cc

@@ -68,7 +68,6 @@
 #include "FileEntry.h"
 #include "Request.h"
 #include "FileAllocationIterator.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "A2STR.h"
 #include "URISelector.h"
@@ -299,9 +298,8 @@ void RequestGroup::createInitialCommand
         // TODO If metadataGetMode == false and each FileEntry has
         // URI, then go without BT.
         throw DOWNLOAD_FAILURE_EXCEPTION
-          (StringFormat
-           ("InfoHash %s is already registered.",
-            bittorrent::getInfoHashString(downloadContext_).c_str()).str());
+          (fmt("InfoHash %s is already registered.",
+               bittorrent::getInfoHashString(downloadContext_).c_str()));
       }
       if(metadataGetMode) {
         // Use UnknownLengthPieceStorage.
@@ -309,8 +307,8 @@ void RequestGroup::createInitialCommand
       } else {
         if(e->getRequestGroupMan()->isSameFileBeingDownloaded(this)) {
           throw DOWNLOAD_FAILURE_EXCEPTION
-            (StringFormat(EX_DUPLICATE_FILE_DOWNLOAD,
-                          downloadContext_->getBasePath().c_str()).str());
+            (fmt(EX_DUPLICATE_FILE_DOWNLOAD,
+                 downloadContext_->getBasePath().c_str()));
         }
         initPieceStorage();
         if(downloadContext_->getFileEntries().size() > 1) {
@@ -415,9 +413,8 @@ void RequestGroup::createInitialCommand
              !option_->getAsBool(PREF_BT_SEED_UNVERIFIED)) {
             // TODO we need this->haltRequested = true?
             throw DOWNLOAD_FAILURE_EXCEPTION
-              (StringFormat
-               (MSG_FILE_ALREADY_EXISTS,
-                downloadContext_->getBasePath().c_str()).str());
+              (fmt(MSG_FILE_ALREADY_EXISTS,
+                   downloadContext_->getBasePath().c_str()));
           } else {
             pieceStorage_->getDiskAdaptor()->openFile();
           }
@@ -480,8 +477,8 @@ void RequestGroup::createInitialCommand
     } else {
       if(e->getRequestGroupMan()->isSameFileBeingDownloaded(this)) {
         throw DOWNLOAD_FAILURE_EXCEPTION
-          (StringFormat(EX_DUPLICATE_FILE_DOWNLOAD,
-                        downloadContext_->getBasePath().c_str()).str());
+          (fmt(EX_DUPLICATE_FILE_DOWNLOAD,
+               downloadContext_->getBasePath().c_str()));
       }
       SharedHandle<BtProgressInfoFile> progressInfoFile
         (new DefaultBtProgressInfoFile
@@ -506,8 +503,8 @@ void RequestGroup::createInitialCommand
     // DownloadContext.
     if(e->getRequestGroupMan()->isSameFileBeingDownloaded(this)) {
       throw DOWNLOAD_FAILURE_EXCEPTION
-        (StringFormat(EX_DUPLICATE_FILE_DOWNLOAD,
-                      downloadContext_->getBasePath().c_str()).str());
+        (fmt(EX_DUPLICATE_FILE_DOWNLOAD,
+             downloadContext_->getBasePath().c_str()));
     }
     initPieceStorage();
     if(downloadContext_->getFileEntries().size() > 1) {
@@ -529,9 +526,8 @@ void RequestGroup::createInitialCommand
            !option_->getAsBool(PREF_ALLOW_OVERWRITE)) {
           // TODO we need this->haltRequested = true?
           throw DOWNLOAD_FAILURE_EXCEPTION
-            (StringFormat
-             (MSG_FILE_ALREADY_EXISTS,
-              downloadContext_->getBasePath().c_str()).str());
+            (fmt(MSG_FILE_ALREADY_EXISTS,
+                 downloadContext_->getBasePath().c_str()));
         } else {
           pieceStorage_->getDiskAdaptor()->openFile();
         }
@@ -750,8 +746,7 @@ void RequestGroup::loadAndOpenFile(const BtProgressInfoFileHandle& progressInfoF
     }
     setProgressInfoFile(progressInfoFile);
   } catch(RecoverableException& e) {
-    throw DOWNLOAD_FAILURE_EXCEPTION2
-      (StringFormat(EX_DOWNLOAD_ABORTED).str(), e);
+    throw DOWNLOAD_FAILURE_EXCEPTION2(fmt(EX_DOWNLOAD_ABORTED), e);
   }
 }
 
@@ -768,13 +763,13 @@ void RequestGroup::shouldCancelDownloadForSafety()
         A2_LOG_NOTICE(fmt(MSG_FILE_RENAMED, getFirstFilePath().c_str()));
       } else {
         throw DOWNLOAD_FAILURE_EXCEPTION
-          (StringFormat("File renaming failed: %s",
-                        getFirstFilePath().c_str()).str());
+          (fmt("File renaming failed: %s",
+               getFirstFilePath().c_str()));
       }
     } else {
       throw DOWNLOAD_FAILURE_EXCEPTION
-        (StringFormat(MSG_FILE_ALREADY_EXISTS,
-                      getFirstFilePath().c_str()).str());
+        (fmt(MSG_FILE_ALREADY_EXISTS,
+             getFirstFilePath().c_str()));
     }
   }
 }
@@ -892,9 +887,9 @@ void RequestGroup::validateFilename(const std::string& expectedFilename,
     return;
   }
   if(expectedFilename != actualFilename) {
-    throw DL_ABORT_EX(StringFormat(EX_FILENAME_MISMATCH,
-                                   expectedFilename.c_str(),
-                                   actualFilename.c_str()).str());
+    throw DL_ABORT_EX(fmt(EX_FILENAME_MISMATCH,
+                          expectedFilename.c_str(),
+                          actualFilename.c_str()));
   }
 }
 
@@ -906,9 +901,9 @@ void RequestGroup::validateTotalLength(uint64_t expectedTotalLength,
   }
   if(expectedTotalLength != actualTotalLength) {
     throw DL_ABORT_EX
-      (StringFormat(EX_SIZE_MISMATCH,
-                    util::itos(expectedTotalLength, true).c_str(),
-                    util::itos(actualTotalLength, true).c_str()).str());
+      (fmt(EX_SIZE_MISMATCH,
+           util::itos(expectedTotalLength, true).c_str(),
+           util::itos(actualTotalLength, true).c_str()));
   }
 }
 
@@ -1256,7 +1251,7 @@ void RequestGroup::increaseAndValidateFileNotFoundCount()
      (!segmentMan_ ||
       segmentMan_->calculateSessionDownloadLength() == 0)) {
     throw DOWNLOAD_FAILURE_EXCEPTION2
-      (StringFormat("Reached max-file-not-found count=%u", maxCount).str(),
+      (fmt("Reached max-file-not-found count=%u", maxCount),
        downloadresultcode::MAX_FILE_NOT_FOUND);
   }
 }

+ 2 - 3
src/RequestGroupMan.cc

@@ -66,7 +66,6 @@
 #include "util.h"
 #include "Command.h"
 #include "FileEntry.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "FileAllocationEntry.h"
 #include "CheckIntegrityEntry.h"
@@ -212,8 +211,8 @@ size_t RequestGroupMan::changeReservedGroupPosition
     findByGID(reservedGroups_.begin(), reservedGroups_.end(), gid);
   if(i == reservedGroups_.end()) {
     throw DL_ABORT_EX
-      (StringFormat("GID#%s not found in the waiting queue.",
-                    util::itos(gid).c_str()).str());
+      (fmt("GID#%s not found in the waiting queue.",
+           util::itos(gid).c_str()));
   }
   SharedHandle<RequestGroup> rg = *i;
   const size_t maxPos = reservedGroups_.size()-1;

+ 2 - 3
src/SocketBuffer.cc

@@ -40,7 +40,7 @@
 #include "SocketCore.h"
 #include "DlAbortEx.h"
 #include "message.h"
-#include "StringFormat.h"
+#include "fmt.h"
 
 namespace aria2 {
 
@@ -85,8 +85,7 @@ ssize_t SocketBuffer::send()
     }
     ssize_t slen = socket_->writeData(data+offset_, r);
     if(slen == 0 && !socket_->wantRead() && !socket_->wantWrite()) {
-      throw DL_ABORT_EX(StringFormat(EX_SOCKET_SEND,
-                                     "Connection closed.").str());
+      throw DL_ABORT_EX(fmt(EX_SOCKET_SEND, "Connection closed."));
     }
     totalslen += slen;
     if(slen < r) {

+ 69 - 90
src/SocketCore.cc

@@ -49,7 +49,6 @@
 #include "message.h"
 #include "DlRetryEx.h"
 #include "DlAbortEx.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "util.h"
 #include "TimeA2.h"
@@ -180,8 +179,8 @@ void SocketCore::create(int family, int protocol)
   errNum = SOCKET_ERRNO;
   if(fd == (sock_t) -1) {
     throw DL_ABORT_EX
-      (StringFormat
-       ("Failed to create socket. Cause:%s", errorMsg(errNum).c_str()).str());
+      (fmt("Failed to create socket. Cause:%s",
+           errorMsg(errNum).c_str()));
   }
   int sockopt = 1;
   if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
@@ -189,8 +188,8 @@ void SocketCore::create(int family, int protocol)
     errNum = SOCKET_ERRNO;
     CLOSE(fd);
     throw DL_ABORT_EX
-      (StringFormat
-       ("Failed to create socket. Cause:%s", errorMsg(errNum).c_str()).str());
+      (fmt("Failed to create socket. Cause:%s",
+           errorMsg(errNum).c_str()));
   }
   sockfd_ = fd;
 }
@@ -264,7 +263,7 @@ void SocketCore::bindWithFamily(uint16_t port, int family, int flags)
   std::string error;
   sock_t fd = bindTo(0, port, family, sockType_, flags, error);
   if(fd == (sock_t) -1) {
-    throw DL_ABORT_EX(StringFormat(EX_SOCKET_BIND, error.c_str()).str());
+    throw DL_ABORT_EX(fmt(EX_SOCKET_BIND, error.c_str()));
   } else {
     sockfd_ = fd;
   }
@@ -312,7 +311,7 @@ void SocketCore::bind
     }
   }
   if(sockfd_ == (sock_t) -1) {
-    throw DL_ABORT_EX(StringFormat(EX_SOCKET_BIND, error.c_str()).str());
+    throw DL_ABORT_EX(fmt(EX_SOCKET_BIND, error.c_str()));
   }
 }
 
@@ -329,7 +328,7 @@ void SocketCore::bind(const struct sockaddr* addr, socklen_t addrlen)
   if(fd != (sock_t)-1) {
     sockfd_ = fd;
   } else {
-    throw DL_ABORT_EX(StringFormat(EX_SOCKET_BIND, error.c_str()).str());
+    throw DL_ABORT_EX(fmt(EX_SOCKET_BIND, error.c_str()));
   }
 }
 
@@ -337,8 +336,7 @@ void SocketCore::beginListen()
 {
   if(listen(sockfd_, 1) == -1) {
     int errNum = SOCKET_ERRNO;
-    throw DL_ABORT_EX(StringFormat
-                      (EX_SOCKET_LISTEN, errorMsg(errNum).c_str()).str());
+    throw DL_ABORT_EX(fmt(EX_SOCKET_LISTEN, errorMsg(errNum).c_str()));
   }
 }
 
@@ -352,8 +350,7 @@ SocketCore* SocketCore::acceptConnection() const
         SOCKET_ERRNO == A2_EINTR);
   int errNum = SOCKET_ERRNO;
   if(fd == (sock_t) -1) {
-    throw DL_ABORT_EX(StringFormat
-                      (EX_SOCKET_ACCEPT, errorMsg(errNum).c_str()).str());
+    throw DL_ABORT_EX(fmt(EX_SOCKET_ACCEPT, errorMsg(errNum).c_str()));
   }
   return new SocketCore(fd, sockType_);
 }
@@ -373,8 +370,7 @@ void SocketCore::getAddrInfo
   struct sockaddr* addrp = reinterpret_cast<struct sockaddr*>(&sockaddr);
   if(getsockname(sockfd_, addrp, &len) == -1) {
     int errNum = SOCKET_ERRNO;
-    throw DL_ABORT_EX(StringFormat
-                      (EX_SOCKET_GET_NAME, errorMsg(errNum).c_str()).str());
+    throw DL_ABORT_EX(fmt(EX_SOCKET_GET_NAME, errorMsg(errNum).c_str()));
   }
 }
 
@@ -393,8 +389,7 @@ void SocketCore::getPeerInfo(std::pair<std::string, uint16_t>& peerinfo) const
   struct sockaddr* addrp = reinterpret_cast<struct sockaddr*>(&sockaddr);
   if(getpeername(sockfd_, addrp, &len) == -1) {
     int errNum = SOCKET_ERRNO;
-    throw DL_ABORT_EX(StringFormat
-                      (EX_SOCKET_GET_NAME, errorMsg(errNum).c_str()).str());
+    throw DL_ABORT_EX(fmt(EX_SOCKET_GET_NAME, errorMsg(errNum).c_str()));
   }
   peerinfo = util::getNumericNameInfo(addrp, len);
 }
@@ -408,8 +403,9 @@ void SocketCore::establishConnection(const std::string& host, uint16_t port)
   s = callGetaddrinfo(&res, host.c_str(), util::uitos(port).c_str(),
                       protocolFamily_, sockType_, 0, 0);
   if(s) {
-    throw DL_ABORT_EX(StringFormat(EX_RESOLVE_HOSTNAME,
-                                   host.c_str(), gai_strerror(s)).str());
+    throw DL_ABORT_EX(fmt(EX_RESOLVE_HOSTNAME,
+                          host.c_str(),
+                          gai_strerror(s)));
   }
   WSAAPI_AUTO_DELETE<struct addrinfo*> resDeleter(res, freeaddrinfo);
   struct addrinfo* rp;
@@ -466,8 +462,10 @@ void SocketCore::establishConnection(const std::string& host, uint16_t port)
     break;
   }
   if(sockfd_ == (sock_t) -1) {
-    throw DL_ABORT_EX(StringFormat(EX_SOCKET_CONNECT, host.c_str(),
-                                   error.c_str()).str());
+    throw DL_ABORT_EX
+      (fmt(EX_SOCKET_CONNECT,
+           host.c_str(),
+           error.c_str()));
   }
 }
 
@@ -476,8 +474,7 @@ void SocketCore::setSockOpt
 {
   if(setsockopt(sockfd_, level, optname, (a2_sockopt_t)optval, optlen) < 0) {
     int errNum = SOCKET_ERRNO;
-    throw DL_ABORT_EX(StringFormat
-                      (EX_SOCKET_SET_OPT, errorMsg(errNum).c_str()).str());
+    throw DL_ABORT_EX(fmt(EX_SOCKET_SET_OPT, errorMsg(errNum).c_str()));
   }
 }   
 
@@ -488,8 +485,7 @@ void SocketCore::setMulticastInterface(const std::string& localAddr)
     addr.s_addr = htonl(INADDR_ANY);
   } else {
     if(inet_aton(localAddr.c_str(), &addr) == 0) {
-      throw DL_ABORT_EX
-        (StringFormat("inet_aton failed for %s", localAddr.c_str()).str());
+      throw DL_ABORT_EX(fmt("inet_aton failed for %s", localAddr.c_str()));
     }
   }
   setSockOpt(IPPROTO_IP, IP_MULTICAST_IF, &addr, sizeof(addr));
@@ -511,16 +507,14 @@ void SocketCore::joinMulticastGroup
 {
   in_addr multiAddr;
   if(inet_aton(multicastAddr.c_str(), &multiAddr) == 0) {
-    throw DL_ABORT_EX
-      (StringFormat("inet_aton failed for %s", multicastAddr.c_str()).str());
+    throw DL_ABORT_EX(fmt("inet_aton failed for %s", multicastAddr.c_str()));
   }
   in_addr ifAddr;
   if(localAddr.empty()) {
     ifAddr.s_addr = htonl(INADDR_ANY);
   } else {
     if(inet_aton(localAddr.c_str(), &ifAddr) == 0) {
-      throw DL_ABORT_EX
-        (StringFormat("inet_aton failed for %s", localAddr.c_str()).str());
+      throw DL_ABORT_EX(fmt("inet_aton failed for %s", localAddr.c_str()));
     }
   }
   struct ip_mreq mreq;
@@ -536,8 +530,7 @@ void SocketCore::setNonBlockingMode()
   static u_long flag = 1;
   if (::ioctlsocket(sockfd_, FIONBIO, &flag) == -1) {
     int errNum = SOCKET_ERRNO;
-    throw DL_ABORT_EX(StringFormat
-                      (EX_SOCKET_NONBLOCKING, errorMsg(errNum).c_str()).str());
+    throw DL_ABORT_EX(fmt(EX_SOCKET_NONBLOCKING, errorMsg(errNum).c_str()));
   }
 #else
   int flags;
@@ -554,8 +547,7 @@ void SocketCore::setBlockingMode()
   static u_long flag = 0;
   if (::ioctlsocket(sockfd_, FIONBIO, &flag) == -1) {
     int errNum = SOCKET_ERRNO;
-    throw DL_ABORT_EX(StringFormat
-                      (EX_SOCKET_BLOCKING, errorMsg(errNum).c_str()).str());
+    throw DL_ABORT_EX(fmt(EX_SOCKET_BLOCKING, errorMsg(errNum).c_str()));
   }
 #else
   int flags;
@@ -619,8 +611,7 @@ bool SocketCore::isWritable(time_t timeout)
   } else if(r == 0) {
     return false;
   } else {
-    throw DL_RETRY_EX
-      (StringFormat(EX_SOCKET_CHECK_WRITABLE, errorMsg(errNum).c_str()).str());
+    throw DL_RETRY_EX(fmt(EX_SOCKET_CHECK_WRITABLE, errorMsg(errNum).c_str()));
   }
 #else // !HAVE_POLL
 # ifndef __MINGW32__
@@ -646,8 +637,8 @@ bool SocketCore::isWritable(time_t timeout)
       return false;
     } else {
       throw DL_RETRY_EX
-        (StringFormat(EX_SOCKET_CHECK_WRITABLE,
-                      errorMsg(errNum).c_str()).str());
+        (fmt(EX_SOCKET_CHECK_WRITABLE,
+             errorMsg(errNum).c_str()));
     }
   }
 #endif // !HAVE_POLL
@@ -672,8 +663,7 @@ bool SocketCore::isReadable(time_t timeout)
   } else if(r == 0) {
     return false;
   } else {
-    throw DL_RETRY_EX
-      (StringFormat(EX_SOCKET_CHECK_READABLE, errorMsg(errNum).c_str()).str());
+    throw DL_RETRY_EX(fmt(EX_SOCKET_CHECK_READABLE, errorMsg(errNum).c_str()));
   }
 #else // !HAVE_POLL
 # ifndef __MINGW32__
@@ -699,8 +689,8 @@ bool SocketCore::isReadable(time_t timeout)
       return false;
     } else {
       throw DL_RETRY_EX
-        (StringFormat(EX_SOCKET_CHECK_READABLE,
-                      errorMsg(errNum).c_str()).str());
+        (fmt(EX_SOCKET_CHECK_READABLE,
+             errorMsg(errNum).c_str()));
     }
   }
 #endif // !HAVE_POLL
@@ -748,8 +738,7 @@ ssize_t SocketCore::writeData(const char* data, size_t len)
         wantWrite_ = true;
         ret = 0;
       } else {
-        throw DL_RETRY_EX(StringFormat(EX_SOCKET_SEND,
-                                       errorMsg(errNum).c_str()).str());
+        throw DL_RETRY_EX(fmt(EX_SOCKET_SEND, errorMsg(errNum).c_str()));
       }
     }
   } else {
@@ -760,8 +749,8 @@ ssize_t SocketCore::writeData(const char* data, size_t len)
     }
     if(ret < 0) {
       throw DL_RETRY_EX
-        (StringFormat
-         (EX_SOCKET_SEND, ERR_error_string(SSL_get_error(ssl, ret), 0)).str());
+        (fmt(EX_SOCKET_SEND,
+             ERR_error_string(SSL_get_error(ssl, ret), 0)));
     }
 #endif // HAVE_LIBSSL
 #ifdef HAVE_LIBGNUTLS
@@ -771,7 +760,7 @@ ssize_t SocketCore::writeData(const char* data, size_t len)
       gnutlsRecordCheckDirection();
       ret = 0;
     } else if(ret < 0) {
-      throw DL_RETRY_EX(StringFormat(EX_SOCKET_SEND, gnutls_strerror(ret)).str());
+      throw DL_RETRY_EX(fmt(EX_SOCKET_SEND, gnutls_strerror(ret)));
     }
 #endif // HAVE_LIBGNUTLS
   }
@@ -794,8 +783,7 @@ void SocketCore::readData(char* data, size_t& len)
         wantRead_ = true;
         ret = 0;
       } else {
-        throw DL_RETRY_EX(StringFormat(EX_SOCKET_RECV,
-                                       errorMsg(errNum).c_str()).str());
+        throw DL_RETRY_EX(fmt(EX_SOCKET_RECV, errorMsg(errNum).c_str()));
       }
     }
   } else {
@@ -808,8 +796,8 @@ void SocketCore::readData(char* data, size_t& len)
     }
     if(ret < 0) {
       throw DL_RETRY_EX
-        (StringFormat
-         (EX_SOCKET_RECV, ERR_error_string(SSL_get_error(ssl, ret), 0)).str());
+        (fmt(EX_SOCKET_RECV,
+             ERR_error_string(SSL_get_error(ssl, ret), 0)));
     }
 #endif // HAVE_LIBSSL
 #ifdef HAVE_LIBGNUTLS
@@ -818,8 +806,7 @@ void SocketCore::readData(char* data, size_t& len)
       gnutlsRecordCheckDirection();
       ret = 0;
     } else if(ret < 0) {
-      throw DL_RETRY_EX
-        (StringFormat(EX_SOCKET_RECV, gnutls_strerror(ret)).str());
+      throw DL_RETRY_EX(fmt(EX_SOCKET_RECV, gnutls_strerror(ret)));
     }
 #endif // HAVE_LIBGNUTLS
   }
@@ -842,8 +829,7 @@ void SocketCore::peekData(char* data, size_t& len)
         wantRead_ = true;
         ret = 0;
       } else {
-        throw DL_RETRY_EX(StringFormat(EX_SOCKET_PEEK,
-                                       errorMsg(errNum).c_str()).str());
+        throw DL_RETRY_EX(fmt(EX_SOCKET_PEEK, errorMsg(errNum).c_str()));
       }
     }
   } else {
@@ -856,8 +842,8 @@ void SocketCore::peekData(char* data, size_t& len)
     }
     if(ret < 0) {
       throw DL_RETRY_EX
-        (StringFormat(EX_SOCKET_PEEK,
-                      ERR_error_string(SSL_get_error(ssl, ret), 0)).str());
+        (fmt(EX_SOCKET_PEEK,
+             ERR_error_string(SSL_get_error(ssl, ret), 0)));
     }
 #endif // HAVE_LIBSSL
 #ifdef HAVE_LIBGNUTLS
@@ -866,8 +852,7 @@ void SocketCore::peekData(char* data, size_t& len)
       gnutlsRecordCheckDirection();
       ret = 0;
     } else if(ret < 0) {
-      throw DL_RETRY_EX(StringFormat(EX_SOCKET_PEEK,
-                                     gnutls_strerror(ret)).str());
+      throw DL_RETRY_EX(fmt(EX_SOCKET_PEEK, gnutls_strerror(ret)));
     }
 #endif // HAVE_LIBGNUTLS
   }
@@ -912,8 +897,7 @@ static ssize_t GNUTLS_RECORD_RECV_NO_INTERRUPT
   while((ret = gnutls_record_recv(sslSession, data, len)) ==
         GNUTLS_E_INTERRUPTED);
   if(ret < 0 && ret != GNUTLS_E_AGAIN) {
-    throw DL_RETRY_EX
-      (StringFormat(EX_SOCKET_RECV, gnutls_strerror(ret)).str());
+    throw DL_RETRY_EX(fmt(EX_SOCKET_RECV, gnutls_strerror(ret)));
   }
   return ret;
 }
@@ -959,13 +943,13 @@ void SocketCore::prepareSecureConnection()
     ssl = SSL_new(tlsContext_->getSSLCtx());
     if(!ssl) {
       throw DL_ABORT_EX
-        (StringFormat(EX_SSL_INIT_FAILURE,
-                      ERR_error_string(ERR_get_error(), 0)).str());
+        (fmt(EX_SSL_INIT_FAILURE,
+             ERR_error_string(ERR_get_error(), 0)));
     }
     if(SSL_set_fd(ssl, sockfd_) == 0) {
       throw DL_ABORT_EX
-        (StringFormat(EX_SSL_INIT_FAILURE,
-                      ERR_error_string(ERR_get_error(), 0)).str());
+        (fmt(EX_SSL_INIT_FAILURE,
+             ERR_error_string(ERR_get_error(), 0)));
     }
 #endif // HAVE_LIBSSL
 #ifdef HAVE_LIBGNUTLS
@@ -978,8 +962,7 @@ void SocketCore::prepareSecureConnection()
     // understand TLS1.1.
     r = gnutls_priority_set_direct(sslSession_, "NORMAL:!VERS-TLS1.1", &err);
     if(r != GNUTLS_E_SUCCESS) {
-      throw DL_ABORT_EX
-        (StringFormat(EX_SSL_INIT_FAILURE, gnutls_strerror(r)).str());
+      throw DL_ABORT_EX(fmt(EX_SSL_INIT_FAILURE, gnutls_strerror(r)));
     }
     // put the x509 credentials to the current session
     gnutls_credentials_set(sslSession_, GNUTLS_CRD_CERTIFICATE,
@@ -1013,8 +996,7 @@ bool SocketCore::initiateSecureConnection(const std::string& hostname)
       case SSL_ERROR_WANT_X509_LOOKUP:
       case SSL_ERROR_ZERO_RETURN:
         if (blocking_) {
-          throw DL_ABORT_EX
-            (StringFormat(EX_SSL_CONNECT_ERROR, ssl_error).str());
+          throw DL_ABORT_EX(fmt(EX_SSL_CONNECT_ERROR, ssl_error));
         }
         break;
 
@@ -1025,8 +1007,7 @@ bool SocketCore::initiateSecureConnection(const std::string& hostname)
         throw DL_ABORT_EX(EX_SSL_PROTOCOL_ERROR);
 
       default:
-        throw DL_ABORT_EX
-          (StringFormat(EX_SSL_UNKNOWN_ERROR, ssl_error).str());
+        throw DL_ABORT_EX(fmt(EX_SSL_UNKNOWN_ERROR, ssl_error));
       }
     }
     if(tlsContext_->peerVerificationEnabled()) {
@@ -1040,8 +1021,8 @@ bool SocketCore::initiateSecureConnection(const std::string& hostname)
       long verifyResult = SSL_get_verify_result(ssl);
       if(verifyResult != X509_V_OK) {
         throw DL_ABORT_EX
-          (StringFormat(MSG_CERT_VERIFICATION_FAILED,
-                        X509_verify_cert_error_string(verifyResult)).str());
+          (fmt(MSG_CERT_VERIFICATION_FAILED,
+               X509_verify_cert_error_string(verifyResult)));
       }
       X509_NAME* name = X509_get_subject_name(peerCert);
       if(!name) {
@@ -1079,8 +1060,7 @@ bool SocketCore::initiateSecureConnection(const std::string& hostname)
       gnutlsRecordCheckDirection();
       return false;
     } else if(ret < 0) {
-      throw DL_ABORT_EX
-        (StringFormat(EX_SSL_INIT_FAILURE, gnutls_strerror(ret)).str());
+      throw DL_ABORT_EX(fmt(EX_SSL_INIT_FAILURE, gnutls_strerror(ret)));
     }
 
     if(tlsContext_->peerVerificationEnabled()) {
@@ -1089,8 +1069,8 @@ bool SocketCore::initiateSecureConnection(const std::string& hostname)
       ret = gnutls_certificate_verify_peers2(sslSession_, &status);
       if(ret < 0) {
         throw DL_ABORT_EX
-          (StringFormat("gnutls_certificate_verify_peer2() failed. Cause: %s",
-                        gnutls_strerror(ret)).str());
+          (fmt("gnutls_certificate_verify_peer2() failed. Cause: %s",
+               gnutls_strerror(ret)));
       }
       if(status) {
         std::string errors;
@@ -1104,8 +1084,7 @@ bool SocketCore::initiateSecureConnection(const std::string& hostname)
           errors += " `issuer is not known'";
         }
         if(!errors.empty()) {
-          throw DL_ABORT_EX
-            (StringFormat(MSG_CERT_VERIFICATION_FAILED, errors.c_str()).str());
+          throw DL_ABORT_EX(fmt(MSG_CERT_VERIFICATION_FAILED, errors.c_str()));
         }
       }
       // certificate type: only X509 is allowed.
@@ -1125,16 +1104,16 @@ bool SocketCore::initiateSecureConnection(const std::string& hostname)
         ret = gnutls_x509_crt_init(&cert);
         if(ret < 0) {
           throw DL_ABORT_EX
-            (StringFormat("gnutls_x509_crt_init() failed. Cause: %s",
-                          gnutls_strerror(ret)).str());
+            (fmt("gnutls_x509_crt_init() failed. Cause: %s",
+                 gnutls_strerror(ret)));
         }
         auto_delete<gnutls_x509_crt_t> certDeleter
           (cert, gnutls_x509_crt_deinit);
         ret = gnutls_x509_crt_import(cert, &peerCerts[i], GNUTLS_X509_FMT_DER);
         if(ret < 0) {
           throw DL_ABORT_EX
-            (StringFormat("gnutls_x509_crt_import() failed. Cause: %s",
-                          gnutls_strerror(ret)).str());
+            (fmt("gnutls_x509_crt_import() failed. Cause: %s",
+                 gnutls_strerror(ret)));
         }
         if(i == 0) {
           if(!gnutls_x509_crt_check_hostname(cert, hostname.c_str())) {
@@ -1177,7 +1156,7 @@ ssize_t SocketCore::writeData(const char* data, size_t len,
   s = callGetaddrinfo(&res, host.c_str(), util::uitos(port).c_str(),
                       protocolFamily_, sockType_, 0, 0);
   if(s) {
-    throw DL_ABORT_EX(StringFormat(EX_SOCKET_SEND, gai_strerror(s)).str());
+    throw DL_ABORT_EX(fmt(EX_SOCKET_SEND, gai_strerror(s)));
   }
   WSAAPI_AUTO_DELETE<struct addrinfo*> resDeleter(res, freeaddrinfo);
   struct addrinfo* rp;
@@ -1197,8 +1176,7 @@ ssize_t SocketCore::writeData(const char* data, size_t len,
     }
   }
   if(r == -1) {
-    throw DL_ABORT_EX(StringFormat(EX_SOCKET_SEND,
-                                   errorMsg(errNum).c_str()).str());
+    throw DL_ABORT_EX(fmt(EX_SOCKET_SEND, errorMsg(errNum).c_str()));
   }
   return r;
 }
@@ -1221,8 +1199,7 @@ ssize_t SocketCore::readDataFrom(char* data, size_t len,
       wantRead_ = true;
       r = 0;
     } else {
-      throw DL_RETRY_EX(StringFormat(EX_SOCKET_RECV,
-                                     errorMsg(errNum).c_str()).str());
+      throw DL_RETRY_EX(fmt(EX_SOCKET_RECV, errorMsg(errNum).c_str()));
     }
   } else {
     sender = util::getNumericNameInfo(addrp, sockaddrlen);
@@ -1239,8 +1216,9 @@ std::string SocketCore::getSocketError() const
   if(getsockopt(sockfd_, SOL_SOCKET, SO_ERROR,
                 (a2_sockopt_t) &error, &optlen) == -1) {
     int errNum = SOCKET_ERRNO;
-    throw DL_ABORT_EX(StringFormat("Failed to get socket error: %s",
-                                   errorMsg(errNum).c_str()).str());
+    throw DL_ABORT_EX
+      (fmt("Failed to get socket error: %s",
+           errorMsg(errNum).c_str()));
   }
   if(error != 0) {
     return errorMsg(error);
@@ -1265,8 +1243,9 @@ void SocketCore::bindAddress(const std::string& iface)
   getInterfaceAddress(bindAddrs, iface, protocolFamily_);
   if(bindAddrs.empty()) {
     throw DL_ABORT_EX
-      (StringFormat(MSG_INTERFACE_NOT_FOUND,
-                    iface.c_str(), "not available").str());
+      (fmt(MSG_INTERFACE_NOT_FOUND,
+           iface.c_str(),
+           "not available"));
   } else {
     bindAddrs_ = bindAddrs;
     for(std::vector<std::pair<struct sockaddr_storage, socklen_t> >::

+ 5 - 4
src/Sqlite3CookieParser.cc

@@ -39,7 +39,7 @@
 
 #include "DlAbortEx.h"
 #include "util.h"
-#include "StringFormat.h"
+#include "fmt.h"
 #include "A2STR.h"
 #include "cookie_helper.h"
 #ifndef HAVE_SQLITE3_OPEN_V2
@@ -138,7 +138,7 @@ int cookieRowMapper(void* data, int columns, char** values, char** names)
 void Sqlite3CookieParser::parse(std::vector<Cookie>& cookies)
 {
   if(!db_) {
-    throw DL_ABORT_EX(StringFormat("SQLite3 database is not opened.").str());
+    throw DL_ABORT_EX(fmt("SQLite3 database is not opened."));
   }
   std::vector<Cookie> tcookies;
   char* sqlite3ErrMsg = 0;
@@ -150,8 +150,9 @@ void Sqlite3CookieParser::parse(std::vector<Cookie>& cookies)
     sqlite3_free(sqlite3ErrMsg);
   }
   if(SQLITE_OK != ret) {
-    throw DL_ABORT_EX(StringFormat("Failed to read SQLite3 database: %s",
-                                   errMsg.c_str()).str());
+    throw DL_ABORT_EX
+      (fmt("Failed to read SQLite3 database: %s",
+           errMsg.c_str()));
   }
   cookies.swap(tcookies);
 }

+ 0 - 68
src/StringFormat.cc

@@ -1,68 +0,0 @@
-/* <!-- copyright */
-/*
- * aria2 - The high speed download utility
- *
- * Copyright (C) 2006 Tatsuhiro Tsujikawa
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * In addition, as a special exception, the copyright holders give
- * permission to link the code of portions of this program with the
- * OpenSSL library under certain conditions as described in each
- * individual source file, and distribute linked combinations
- * including the two.
- * You must obey the GNU General Public License in all respects
- * for all of the code used other than OpenSSL.  If you modify
- * file(s) with this exception, you may extend this exception to your
- * version of the file(s), but you are not obligated to do so.  If you
- * do not wish to do so, delete this exception statement from your
- * version.  If you delete this exception statement from all source
- * files in the program, then also delete it here.
- */
-/* copyright --> */
-#include "StringFormat.h"
-#include <ostream>
-#include <cstring>
-#include <cstdio>
-#include <cstdarg>
-#include <cstdlib>
-
-namespace aria2 {
-
-StringFormat::StringFormat(const char* fmt, ...)
-{
-  va_list ap;
-  va_start(ap, fmt);
-  char buf[1024];
-  if(vsnprintf(buf, sizeof(buf), fmt, ap) > 0) {
-    msg_ = buf;
-  }
-  va_end(ap);
-}
-
-StringFormat::~StringFormat() {}
-
-const std::string& StringFormat::str() const
-{
-  return msg_;
-}
-
-std::ostream& operator<<(std::ostream& o, const StringFormat& fmt)
-{
-  o << fmt.str();
-  return o;
-}
-
-} // namespace aria2

+ 0 - 61
src/StringFormat.h

@@ -1,61 +0,0 @@
-/* <!-- copyright */
-/*
- * aria2 - The high speed download utility
- *
- * Copyright (C) 2006 Tatsuhiro Tsujikawa
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * In addition, as a special exception, the copyright holders give
- * permission to link the code of portions of this program with the
- * OpenSSL library under certain conditions as described in each
- * individual source file, and distribute linked combinations
- * including the two.
- * You must obey the GNU General Public License in all respects
- * for all of the code used other than OpenSSL.  If you modify
- * file(s) with this exception, you may extend this exception to your
- * version of the file(s), but you are not obligated to do so.  If you
- * do not wish to do so, delete this exception statement from your
- * version.  If you delete this exception statement from all source
- * files in the program, then also delete it here.
- */
-/* copyright --> */
-#ifndef D_STRING_FORMAT_H
-#define D_STRING_FORMAT_H
-
-#include "common.h"
-
-#include <string>
-#include <iosfwd>
-#include <cstdarg>
-
-namespace aria2 {
-
-class StringFormat {
-private:
-  std::string msg_;
-public:
-  StringFormat(const char* fmt, ...)
-    __attribute__ ((format (printf, 2, 3)));
-  ~StringFormat();
-
-  const std::string& str() const;
-};
-
-std::ostream& operator<<(std::ostream& o, const StringFormat& fmt);
-
-} // namespace aria2
-
-#endif // D_STRING_FORMAT_H

+ 3 - 4
src/UTMetadataRequestExtensionMessage.cc

@@ -38,7 +38,7 @@
 #include "a2functional.h"
 #include "bittorrent_helper.h"
 #include "DlAbortEx.h"
-#include "StringFormat.h"
+#include "fmt.h"
 #include "BtMessageFactory.h"
 #include "BtMessageDispatcher.h"
 #include "Peer.h"
@@ -98,9 +98,8 @@ void UTMetadataRequestExtensionMessage::doReceivedAction()
     dispatcher_->addMessageToQueue(msg);
   } else {
     throw DL_ABORT_EX
-      (StringFormat
-       ("Metadata piece index is too big. piece=%lu",
-        static_cast<unsigned long>(getIndex())).str());
+      (fmt("Metadata piece index is too big. piece=%lu",
+           static_cast<unsigned long>(getIndex())));
   }
 }
 

+ 4 - 4
src/UTPexExtensionMessage.cc

@@ -39,7 +39,7 @@
 #include "PeerStorage.h"
 #include "DlAbortEx.h"
 #include "message.h"
-#include "StringFormat.h"
+#include "fmt.h"
 #include "bencode2.h"
 #include "a2functional.h"
 #include "wallclock.h"
@@ -175,9 +175,9 @@ UTPexExtensionMessageHandle
 UTPexExtensionMessage::create(const unsigned char* data, size_t len)
 {
   if(len < 1) {
-    throw DL_ABORT_EX(StringFormat(MSG_TOO_SMALL_PAYLOAD_SIZE,
-                                   EXTENSION_NAME.c_str(),
-                                   static_cast<unsigned long>(len)).str());
+    throw DL_ABORT_EX(fmt(MSG_TOO_SMALL_PAYLOAD_SIZE,
+                          EXTENSION_NAME.c_str(),
+                          static_cast<unsigned long>(len)));
   }
   UTPexExtensionMessageHandle msg(new UTPexExtensionMessage(*data));
 

+ 4 - 7
src/XmlRpcMethod.cc

@@ -45,7 +45,6 @@
 #include "XmlRpcRequest.h"
 #include "XmlRpcResponse.h"
 #include "prefs.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "DlAbortEx.h"
 
@@ -91,17 +90,15 @@ void gatherOption
     const std::string& optionName = (*first).first;
     if(allowedOptions.count(optionName) == 0) {
       throw DL_ABORT_EX
-        (StringFormat
-         ("%s option cannot be used in this context.",
-          optionName.c_str()).str());
+        (fmt("%s option cannot be used in this context.",
+             optionName.c_str()));
     } else {
       SharedHandle<OptionHandler> optionHandler =
         optionParser->findByName(optionName);
       if(!optionHandler) {
         throw DL_ABORT_EX
-          (StringFormat
-           ("We don't know how to deal with %s option",
-            optionName.c_str()).str());
+          (fmt("We don't know how to deal with %s option",
+               optionName.c_str()));
       }
       const String* opval = asString((*first).second);
       if(opval) {

+ 26 - 28
src/XmlRpcMethodImpl.cc

@@ -48,7 +48,6 @@
 #include "download_helper.h"
 #include "util.h"
 #include "RequestGroupMan.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "XmlRpcRequest.h"
 #include "PieceStorage.h"
@@ -321,15 +320,15 @@ SharedHandle<ValueBase> removeDownload
     group = e->getRequestGroupMan()->findReservedGroup(gid);
     if(!group) {
       throw DL_ABORT_EX
-        (StringFormat("Active Download not found for GID#%s",
-                      util::itos(gid).c_str()).str());
+        (fmt("Active Download not found for GID#%s",
+             util::itos(gid).c_str()));
     }
     if(group->isDependencyResolved()) {
       e->getRequestGroupMan()->removeReservedGroup(gid);
     } else {
       throw DL_ABORT_EX
-        (StringFormat("GID#%s cannot be removed now",
-                      util::itos(gid).c_str()).str());
+        (fmt("GID#%s cannot be removed now",
+             util::itos(gid).c_str()));
     }
   } else {
     if(forceRemove) {
@@ -397,8 +396,8 @@ SharedHandle<ValueBase> pauseDownload
     return createGIDResponse(gid);
   } else {
     throw DL_ABORT_EX
-      (StringFormat("GID#%s cannot be paused now",
-                    util::itos(gid).c_str()).str());
+      (fmt("GID#%s cannot be paused now",
+           util::itos(gid).c_str()));
   }
 }
 } // namespace
@@ -461,8 +460,8 @@ SharedHandle<ValueBase> UnpauseXmlRpcMethod::process
     e->getRequestGroupMan()->findReservedGroup(gid);
   if(!group || !group->isPauseRequested()) {
     throw DL_ABORT_EX
-      (StringFormat("GID#%s cannot be unpaused now",
-                    util::itos(gid).c_str()).str());
+      (fmt("GID#%s cannot be unpaused now",
+           util::itos(gid).c_str()));
   } else {
     group->setPauseRequested(false);
     e->getRequestGroupMan()->requestQueueCheck();    
@@ -823,8 +822,8 @@ SharedHandle<ValueBase> GetFilesXmlRpcMethod::process
       e->getRequestGroupMan()->findDownloadResult(gid);
     if(!dr) {
       throw DL_ABORT_EX
-        (StringFormat("No file data is available for GID#%s",
-                      util::itos(gid).c_str()).str());
+        (fmt("No file data is available for GID#%s",
+             util::itos(gid).c_str()));
     } else {
       createFileEntry(files, dr->fileEntries.begin(), dr->fileEntries.end());
     }
@@ -844,8 +843,8 @@ SharedHandle<ValueBase> GetUrisXmlRpcMethod::process
     findRequestGroup(e->getRequestGroupMan(), gid);
   if(!group) {
     throw DL_ABORT_EX
-      (StringFormat("No URI data is available for GID#%s",
-                    util::itos(gid).c_str()).str());
+      (fmt("No URI data is available for GID#%s",
+           util::itos(gid).c_str()));
   }
   SharedHandle<List> uriList = List::g();
   // TODO Current implementation just returns first FileEntry's URIs.
@@ -865,8 +864,8 @@ SharedHandle<ValueBase> GetPeersXmlRpcMethod::process
     findRequestGroup(e->getRequestGroupMan(), gid);
   if(!group) {
     throw DL_ABORT_EX
-      (StringFormat("No peer data is available for GID#%s",
-                    util::itos(gid).c_str()).str());
+      (fmt("No peer data is available for GID#%s",
+           util::itos(gid).c_str()));
   }
   SharedHandle<List> peers = List::g();
   BtObject btObject = e->getBtRegistry()->get(group->getGID());
@@ -898,8 +897,8 @@ SharedHandle<ValueBase> TellStatusXmlRpcMethod::process
         e->getRequestGroupMan()->findDownloadResult(gid);
       if(!ds) {
         throw DL_ABORT_EX
-          (StringFormat("No such download for GID#%s",
-                        util::itos(gid).c_str()).str());
+          (fmt("No such download for GID#%s",
+               util::itos(gid).c_str()));
       }
       gatherStoppedDownload(entryDict, ds, keys);
     } else {
@@ -995,8 +994,8 @@ SharedHandle<ValueBase> ChangeOptionXmlRpcMethod::process
     findRequestGroup(e->getRequestGroupMan(), gid);
   if(!group) {
     throw DL_ABORT_EX
-      (StringFormat("Cannot change option for GID#%s",
-                    util::itos(gid).c_str()).str());
+      (fmt("Cannot change option for GID#%s",
+           util::itos(gid).c_str()));
   }
   SharedHandle<Option> option(new Option());
   const Dict* optionsParam = req.getDictParam(1);
@@ -1102,8 +1101,8 @@ SharedHandle<ValueBase> GetOptionXmlRpcMethod::process
     findRequestGroup(e->getRequestGroupMan(), gid);
   if(!group) {
     throw DL_ABORT_EX
-      (StringFormat("Cannot get option for GID#%s",
-                    util::itos(gid).c_str()).str());
+      (fmt("Cannot get option for GID#%s",
+           util::itos(gid).c_str()));
   }
   SharedHandle<Dict> result = Dict::g();
   SharedHandle<Option> option = group->getOption();
@@ -1168,8 +1167,8 @@ SharedHandle<ValueBase> GetServersXmlRpcMethod::process
   SharedHandle<RequestGroup> group =
     e->getRequestGroupMan()->findRequestGroup(gid);
   if(!group) {
-    throw DL_ABORT_EX(StringFormat("No active download for GID#%s",
-                                   util::itos(gid).c_str()).str());
+    throw DL_ABORT_EX(fmt("No active download for GID#%s",
+                          util::itos(gid).c_str()));
   }
   const SharedHandle<DownloadContext>& dctx = group->getDownloadContext();
   const std::vector<SharedHandle<FileEntry> >& files = dctx->getFileEntries();
@@ -1219,13 +1218,13 @@ SharedHandle<ValueBase> ChangeUriXmlRpcMethod::process
     findRequestGroup(e->getRequestGroupMan(), gid);
   if(!group) {
     throw DL_ABORT_EX
-      (StringFormat("Cannot remove URIs from GID#%s",
-                    util::itos(gid).c_str()).str());
+      (fmt("Cannot remove URIs from GID#%s",
+           util::itos(gid).c_str()));
   }
   const SharedHandle<DownloadContext>& dctx = group->getDownloadContext();
   const std::vector<SharedHandle<FileEntry> >& files = dctx->getFileEntries();
   if(files.size() <= index) {
-    throw DL_ABORT_EX(StringFormat("fileIndex is out of range").str());
+    throw DL_ABORT_EX(fmt("fileIndex is out of range"));
   }
   SharedHandle<FileEntry> s = files[index];
   size_t delcount = 0;
@@ -1339,8 +1338,7 @@ SharedHandle<ValueBase> SystemMulticallXmlRpcMethod::process
 SharedHandle<ValueBase> NoSuchMethodXmlRpcMethod::process
 (const XmlRpcRequest& req, DownloadEngine* e)
 {
-  throw DL_ABORT_EX
-    (StringFormat("No such method: %s", req.methodName.c_str()).str());
+  throw DL_ABORT_EX(fmt("No such method: %s", req.methodName.c_str()));
 }
 
 } // namespace xmlrpc

+ 9 - 9
src/bencode2.cc

@@ -37,7 +37,7 @@
 #include <fstream>
 #include <sstream>
 
-#include "StringFormat.h"
+#include "fmt.h"
 #include "DlAbortEx.h"
 
 namespace aria2 {
@@ -54,8 +54,8 @@ void checkdelim(std::istream& ss, const char delim = ':')
   char d;
   if(!(ss.get(d) && d == delim)) {
     throw DL_ABORT_EX
-      (StringFormat("Bencode decoding failed: Delimiter '%c' not found.",
-                    delim).str());
+      (fmt("Bencode decoding failed: Delimiter '%c' not found.",
+           delim));
   }
 }
 } // namespace
@@ -77,10 +77,10 @@ std::string decoderawstring(std::istream& ss)
   delete [] buf;
   if(ss.gcount() != static_cast<int>(length)) {
     throw DL_ABORT_EX
-      (StringFormat("Bencode decoding failed:"
-                    " Expected %lu bytes of data, but only %ld read.",
-                    static_cast<unsigned long>(length),
-                    static_cast<long int>(ss.gcount())).str());
+      (fmt("Bencode decoding failed:"
+           " Expected %lu bytes of data, but only %ld read.",
+           static_cast<unsigned long>(length),
+           static_cast<long int>(ss.gcount())));
   }
   return str;
 }
@@ -216,8 +216,8 @@ SharedHandle<ValueBase> decodeFromFile(const std::string& filename)
     return decode(f);
   } else {
     throw DL_ABORT_EX
-      (StringFormat("Bencode decoding failed:"
-                    " Cannot open file '%s'.", filename.c_str()).str());
+      (fmt("Bencode decoding failed: Cannot open file '%s'.",
+           filename.c_str()));
   }
 }
 

+ 32 - 38
src/bittorrent_helper.cc

@@ -43,7 +43,7 @@
 #include "util.h"
 #include "DlAbortEx.h"
 #include "message.h"
-#include "StringFormat.h"
+#include "fmt.h"
 #include "BtConstants.h"
 #include "MessageDigest.h"
 #include "MessageDigestHelper.h"
@@ -210,8 +210,8 @@ void extractFileEntries
       utf8Name = util::encodeNonUtf8(nameData->s());
       if(util::detectDirTraversal(utf8Name)) {
         throw DL_ABORT_EX
-          (StringFormat
-           (MSG_DIR_TRAVERSAL_DETECTED,nameData->s().c_str()).str());
+          (fmt(MSG_DIR_TRAVERSAL_DETECTED,
+               nameData->s().c_str()));
       }
       name = nameData->s();
     } else {
@@ -237,8 +237,7 @@ void extractFileEntries
       }
       const Integer* fileLengthData = asInteger(fileDict->get(C_LENGTH));
       if(!fileLengthData) {
-        throw DL_ABORT_EX(StringFormat(MSG_MISSING_BT_INFO,
-                                       C_LENGTH.c_str()).str());
+        throw DL_ABORT_EX(fmt(MSG_MISSING_BT_INFO, C_LENGTH.c_str()));
       }
       length += fileLengthData->i();
 
@@ -270,8 +269,7 @@ void extractFileEntries
       std::string utf8Path = strjoin(pathelem.begin(), pathelem.end(), '/',
                                      std::ptr_fun(util::encodeNonUtf8));
       if(util::detectDirTraversal(utf8Path)) {
-        throw DL_ABORT_EX
-          (StringFormat(MSG_DIR_TRAVERSAL_DETECTED, utf8Path.c_str()).str());
+        throw DL_ABORT_EX(fmt(MSG_DIR_TRAVERSAL_DETECTED, utf8Path.c_str()));
       }
       std::string pePath =
         strjoin(pathelem.begin(), pathelem.end(), '/',
@@ -291,8 +289,7 @@ void extractFileEntries
     torrent->mode = SINGLE;
     const Integer* lengthData = asInteger(infoDict->get(C_LENGTH));
     if(!lengthData) {
-      throw DL_ABORT_EX(StringFormat(MSG_MISSING_BT_INFO,
-                                     C_LENGTH.c_str()).str());      
+      throw DL_ABORT_EX(fmt(MSG_MISSING_BT_INFO, C_LENGTH.c_str()));      
     }
     uint64_t totalLength = lengthData->i();
 
@@ -398,8 +395,7 @@ void processRootDictionary
   }
   const Dict* infoDict = asDict(rootDict->get(C_INFO));
   if(!infoDict) {
-    throw DL_ABORT_EX(StringFormat(MSG_MISSING_BT_INFO,
-                                   C_INFO.c_str()).str());
+    throw DL_ABORT_EX(fmt(MSG_MISSING_BT_INFO, C_INFO.c_str()));
   }
   SharedHandle<TorrentAttribute> torrent(new TorrentAttribute());
 
@@ -417,8 +413,7 @@ void processRootDictionary
   // calculate the number of pieces
   const String* piecesData = asString(infoDict->get(C_PIECES));
   if(!piecesData) {
-    throw DL_ABORT_EX(StringFormat(MSG_MISSING_BT_INFO,
-                                   C_PIECES.c_str()).str());
+    throw DL_ABORT_EX(fmt(MSG_MISSING_BT_INFO, C_PIECES.c_str()));
   }
   // Commented out To download 0 length torrent.
   //   if(piecesData.s().empty()) {
@@ -432,8 +427,7 @@ void processRootDictionary
   // retrieve piece length
   const Integer* pieceLengthData = asInteger(infoDict->get(C_PIECE_LENGTH));
   if(!pieceLengthData) {
-    throw DL_ABORT_EX(StringFormat(MSG_MISSING_BT_INFO,
-                                   C_PIECE_LENGTH.c_str()).str());
+    throw DL_ABORT_EX(fmt(MSG_MISSING_BT_INFO, C_PIECE_LENGTH.c_str()));
   }
   size_t pieceLength = pieceLengthData->i();
   ctx->setPieceLength(pieceLength);
@@ -742,15 +736,15 @@ uint16_t getShortIntParam(const unsigned char* msg, size_t pos)
 void checkIndex(size_t index, size_t pieces)
 {
   if(!(index < pieces)) {
-    throw DL_ABORT_EX(StringFormat("Invalid index: %lu",
-                                   static_cast<unsigned long>(index)).str());
+    throw DL_ABORT_EX(fmt("Invalid index: %lu",
+                          static_cast<unsigned long>(index)));
   }
 }
 
 void checkBegin(uint32_t begin, size_t pieceLength)
 {
   if(!(begin < pieceLength)) {
-    throw DL_ABORT_EX(StringFormat("Invalid begin: %u", begin).str());
+    throw DL_ABORT_EX(fmt("Invalid begin: %u", begin));
   }  
 }
 
@@ -758,14 +752,14 @@ void checkLength(size_t length)
 {
   if(length > MAX_BLOCK_LENGTH) {
     throw DL_ABORT_EX
-      (StringFormat("Length too long: %lu > %uKB",
-                    static_cast<unsigned long>(length),
-                    MAX_BLOCK_LENGTH/1024).str());
+      (fmt("Length too long: %lu > %uKB",
+           static_cast<unsigned long>(length),
+           MAX_BLOCK_LENGTH/1024));
   }
   if(length == 0) {
     throw DL_ABORT_EX
-      (StringFormat("Invalid length: %lu",
-                    static_cast<unsigned long>(length)).str());
+      (fmt("Invalid length: %lu",
+           static_cast<unsigned long>(length)));
   }
 }
 
@@ -773,16 +767,16 @@ void checkRange(uint32_t begin, size_t length, size_t pieceLength)
 {
   if(!(0 < length)) {
     throw DL_ABORT_EX
-      (StringFormat("Invalid range: begin=%u, length=%lu",
-                    begin,
-                    static_cast<unsigned long>(length)).str());
+      (fmt("Invalid range: begin=%u, length=%lu",
+           begin,
+           static_cast<unsigned long>(length)));
   }
   uint32_t end = begin+length;
   if(!(end <= pieceLength)) {
     throw DL_ABORT_EX
-      (StringFormat("Invalid range: begin=%u, length=%lu",
-                    begin,
-                    static_cast<unsigned long>(length)).str());
+      (fmt("Invalid range: begin=%u, length=%lu",
+           begin,
+           static_cast<unsigned long>(length)));
   }
 }
 
@@ -791,8 +785,8 @@ void checkBitfield
 {
   if(!(bitfieldLength == (pieces+7)/8)) {
     throw DL_ABORT_EX
-      (StringFormat("Invalid bitfield length: %lu",
-                    static_cast<unsigned long>(bitfieldLength)).str());
+      (fmt("Invalid bitfield length: %lu",
+           static_cast<unsigned long>(bitfieldLength)));
   }
   // Check if last byte contains garbage set bit.
   if(bitfield[bitfieldLength-1]&~bitfield::lastByteMask(pieces)) {
@@ -883,8 +877,8 @@ void assertPayloadLengthGreater
 {
   if(actual <= threshold) {
     throw DL_ABORT_EX
-      (StringFormat(MSG_TOO_SMALL_PAYLOAD_SIZE, msgName.c_str(),
-                    static_cast<unsigned long>(actual)).str());
+      (fmt(MSG_TOO_SMALL_PAYLOAD_SIZE, msgName.c_str(),
+           static_cast<unsigned long>(actual)));
   }
 }
 
@@ -893,9 +887,9 @@ void assertPayloadLengthEqual
 {
   if(expected != actual) {
     throw DL_ABORT_EX
-      (StringFormat(EX_INVALID_PAYLOAD_SIZE, msgName.c_str(),
-                    static_cast<unsigned long>(actual),
-                    static_cast<unsigned long>(expected)).str());
+      (fmt(EX_INVALID_PAYLOAD_SIZE, msgName.c_str(),
+           static_cast<unsigned long>(actual),
+           static_cast<unsigned long>(expected)));
   }
 }
 
@@ -905,8 +899,8 @@ void assertID
   uint8_t id = getId(data);
   if(expected != id) {
     throw DL_ABORT_EX
-      (StringFormat(EX_INVALID_BT_MESSAGE_ID, id, msgName.c_str(),
-                    expected).str());
+      (fmt(EX_INVALID_BT_MESSAGE_ID, id, msgName.c_str(),
+           expected));
   }
 }
 

+ 2 - 3
src/download_helper.cc

@@ -51,7 +51,6 @@
 #include "RecoverableException.h"
 #include "DlAbortEx.h"
 #include "message.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "FileEntry.h"
 #include "LogFactory.h"
@@ -518,8 +517,8 @@ void createRequestGroupForUriList
   } else {
     if(!File(option->get(PREF_INPUT_FILE)).isFile()) {
       throw DL_ABORT_EX
-        (StringFormat(EX_FILE_OPEN, option->get(PREF_INPUT_FILE).c_str(),
-                      "No such file").str());
+        (fmt(EX_FILE_OPEN, option->get(PREF_INPUT_FILE).c_str(),
+             "No such file"));
     }
     std::ifstream f(option->get(PREF_INPUT_FILE).c_str(), std::ios::binary);
     createRequestGroupForUriList(result, option, f);

+ 2 - 3
src/option_processing.cc

@@ -51,7 +51,7 @@
 #include "a2io.h"
 #include "help_tags.h"
 #include "File.h"
-#include "StringFormat.h"
+#include "fmt.h"
 #include "OptionHandlerException.h"
 #include "DownloadResultCode.h"
 #include "SimpleRandomizer.h"
@@ -152,8 +152,7 @@ void option_processing(Option& op, std::vector<std::string>& uris,
           exit(downloadresultcode::UNKNOWN_ERROR);
         }
       } else if(!ucfname.empty()) {
-        std::cerr << StringFormat("Configuration file %s is not found.",
-                                  cfname.c_str())
+        std::cerr << fmt("Configuration file %s is not found.", cfname.c_str())
                   << "\n";
         showUsage(TAG_HELP, oparser);
         exit(downloadresultcode::UNKNOWN_ERROR);

+ 34 - 38
src/util.cc

@@ -71,7 +71,6 @@
 #include "DefaultDiskWriter.h"
 #include "FatalException.h"
 #include "FileEntry.h"
-#include "StringFormat.h"
 #include "fmt.h"
 #include "A2STR.h"
 #include "array_fun.h"
@@ -338,7 +337,7 @@ std::string percentEncode(const unsigned char* target, size_t len)
     if(inRFC3986UnreservedChars(target[i])) {
       dest += target[i];
     } else {
-      dest.append(StringFormat("%%%02X", target[i]).str());
+      dest.append(fmt("%%%02X", target[i]));
     }
   }
   return dest;
@@ -356,7 +355,7 @@ std::string torrentPercentEncode(const unsigned char* target, size_t len) {
     if(isAlpha(target[i]) || isDigit(target[i])) {
       dest += target[i];
     } else {
-      dest.append(StringFormat("%%%02X", target[i]).str());
+      dest.append(fmt("%%%02X", target[i]));
     }
   }
   return dest;
@@ -508,8 +507,8 @@ int32_t parseInt(const std::string& s, int32_t base)
 {
   int64_t v = parseLLInt(s, base);
   if(v < INT32_MIN || INT32_MAX < v) {
-    throw DL_ABORT_EX(StringFormat(MSG_STRING_INTEGER_CONVERSION_FAILURE,
-                                   s.c_str()).str());
+    throw DL_ABORT_EX(fmt(MSG_STRING_INTEGER_CONVERSION_FAILURE,
+                          s.c_str()));
   }
   return v;
 }
@@ -538,8 +537,8 @@ uint32_t parseUInt(const std::string& s, int base)
 {
   uint64_t v = parseULLInt(s, base);
   if(UINT32_MAX < v) {
-    throw DL_ABORT_EX(StringFormat(MSG_STRING_INTEGER_CONVERSION_FAILURE,
-                                   s.c_str()).str());
+    throw DL_ABORT_EX(fmt(MSG_STRING_INTEGER_CONVERSION_FAILURE,
+                          s.c_str()));
   }
   return v;
 }
@@ -571,18 +570,18 @@ int64_t parseLLInt(const std::string& s, int32_t base)
 {
   std::string trimed = strip(s);
   if(trimed.empty()) {
-    throw DL_ABORT_EX(StringFormat(MSG_STRING_INTEGER_CONVERSION_FAILURE,
-                                   "empty string").str());
+    throw DL_ABORT_EX(fmt(MSG_STRING_INTEGER_CONVERSION_FAILURE,
+                          "empty string"));
   }
   char* stop;
   errno = 0;
   int64_t v = strtoll(trimed.c_str(), &stop, base);
   if(*stop != '\0') {
-    throw DL_ABORT_EX(StringFormat(MSG_STRING_INTEGER_CONVERSION_FAILURE,
-                                   trimed.c_str()).str());
+    throw DL_ABORT_EX(fmt(MSG_STRING_INTEGER_CONVERSION_FAILURE,
+                          trimed.c_str()));
   } else if(((v == INT64_MIN) || (v == INT64_MAX)) && (errno == ERANGE)) {
-    throw DL_ABORT_EX(StringFormat(MSG_STRING_INTEGER_CONVERSION_FAILURE,
-                                   trimed.c_str()).str());
+    throw DL_ABORT_EX(fmt(MSG_STRING_INTEGER_CONVERSION_FAILURE,
+                          trimed.c_str()));
   }
   return v;
 }
@@ -610,23 +609,23 @@ uint64_t parseULLInt(const std::string& s, int base)
 {
   std::string trimed = strip(s);
   if(trimed.empty()) {
-    throw DL_ABORT_EX(StringFormat(MSG_STRING_INTEGER_CONVERSION_FAILURE,
-                                   "empty string").str());
+    throw DL_ABORT_EX(fmt(MSG_STRING_INTEGER_CONVERSION_FAILURE,
+                          "empty string"));
   }
   // We don't allow negative number.
   if(trimed[0] == '-') {
-    throw DL_ABORT_EX(StringFormat(MSG_STRING_INTEGER_CONVERSION_FAILURE,
-                                   trimed.c_str()).str());
+    throw DL_ABORT_EX(fmt(MSG_STRING_INTEGER_CONVERSION_FAILURE,
+                          trimed.c_str()));
   }
   char* stop;
   errno = 0;
   uint64_t v = strtoull(trimed.c_str(), &stop, base);
   if(*stop != '\0') {
-    throw DL_ABORT_EX(StringFormat(MSG_STRING_INTEGER_CONVERSION_FAILURE,
-                                   trimed.c_str()).str());
+    throw DL_ABORT_EX(fmt(MSG_STRING_INTEGER_CONVERSION_FAILURE,
+                          trimed.c_str()));
   } else if((v == ULLONG_MAX) && (errno == ERANGE)) {
-    throw DL_ABORT_EX(StringFormat(MSG_STRING_INTEGER_CONVERSION_FAILURE,
-                                   trimed.c_str()).str());
+    throw DL_ABORT_EX(fmt(MSG_STRING_INTEGER_CONVERSION_FAILURE,
+                          trimed.c_str()));
   }
   return v;
 }
@@ -649,8 +648,7 @@ IntSequence parseIntRange(const std::string& src)
       std::pair<std::string, std::string> vp;
       divide(vp, p.first.c_str(), '-');
       if(vp.first.empty() || vp.second.empty()) {
-        throw DL_ABORT_EX
-          (StringFormat(MSG_INCOMPLETE_RANGE, p.first.c_str()).str());
+        throw DL_ABORT_EX(fmt(MSG_INCOMPLETE_RANGE, p.first.c_str()));
       }
       int32_t v1 = parseInt(vp.first.c_str());
       int32_t v2 = parseInt(vp.second.c_str());
@@ -737,8 +735,7 @@ void parsePrioritizePieceRange
       computeTailPieces(indexes, fileEntries, pieceLength,
                         std::max((int64_t)0, getRealSize(sizestr)));
     } else {
-      throw DL_ABORT_EX
-        (StringFormat("Unrecognized token %s", (*i).c_str()).str());
+      throw DL_ABORT_EX(fmt("Unrecognized token %s", (*i).c_str()));
     }
   }
   std::sort(indexes.begin(), indexes.end());
@@ -1009,11 +1006,10 @@ int64_t getRealSize(const std::string& sizeWithUnit)
   int64_t v = parseLLInt(size);
 
   if(v < 0) {
-    throw DL_ABORT_EX
-      (StringFormat("Negative value detected: %s", sizeWithUnit.c_str()).str());
+    throw DL_ABORT_EX(fmt("Negative value detected: %s", sizeWithUnit.c_str()));
   } else if(INT64_MAX/mult < v) {
-    throw DL_ABORT_EX(StringFormat(MSG_STRING_INTEGER_CONVERSION_FAILURE,
-                                   "overflow/underflow").str());
+    throw DL_ABORT_EX(fmt(MSG_STRING_INTEGER_CONVERSION_FAILURE,
+                          "overflow/underflow"));
   }
   return v*mult;
 }
@@ -1156,8 +1152,8 @@ void mkdirs(const std::string& dirpath)
     int errNum = errno;
     if(!dir.isDir()) {
       throw DL_ABORT_EX
-        (StringFormat(EX_MAKE_DIR, dir.getPath().c_str(),
-                      safeStrerror(errNum).c_str()).str());
+        (fmt(EX_MAKE_DIR, dir.getPath().c_str(),
+             safeStrerror(errNum).c_str()));
     }
   }
 }
@@ -1198,8 +1194,8 @@ void* allocateAlignedMemory(size_t alignment, size_t size)
   int res;
   if((res = posix_memalign(&buffer, alignment, size)) != 0) {
     throw FATAL_EXCEPTION
-      (StringFormat("Error in posix_memalign: %s",
-                    util::safeStrerror(res).c_str()).str());
+      (fmt("Error in posix_memalign: %s",
+           util::safeStrerror(res).c_str()));
   }
   return buffer;
 }
@@ -1213,8 +1209,8 @@ getNumericNameInfo(const struct sockaddr* sockaddr, socklen_t len)
   int s = getnameinfo(sockaddr, len, host, NI_MAXHOST, service, NI_MAXSERV,
                       NI_NUMERICHOST|NI_NUMERICSERV);
   if(s != 0) {
-    throw DL_ABORT_EX(StringFormat("Failed to get hostname and port. cause: %s",
-                                   gai_strerror(s)).str());
+    throw DL_ABORT_EX(fmt("Failed to get hostname and port. cause: %s",
+                          gai_strerror(s)));
   }
   return std::pair<std::string, uint16_t>(host, atoi(service)); // TODO
 }
@@ -1249,8 +1245,8 @@ parseIndexPath(const std::string& line)
   divide(p, line, '=');
   size_t index = parseUInt(p.first);
   if(p.second.empty()) {
-    throw DL_ABORT_EX(StringFormat("Path with index=%u is empty.",
-                                   static_cast<unsigned int>(index)).str());
+    throw DL_ABORT_EX(fmt("Path with index=%u is empty.",
+                          static_cast<unsigned int>(index)));
   }
   return std::map<size_t, std::string>::value_type(index, p.second);
 }
@@ -1400,7 +1396,7 @@ std::string escapePath(const std::string& s)
 
 #endif // __MINGW32__
        ){
-      d += StringFormat("%%%02X", c).str();
+      d += fmt("%%%02X", c);
     } else {
       d += *i;
     }

+ 11 - 11
src/version_usage.cc

@@ -46,7 +46,7 @@
 #endif // ENABLE_MESSAGE_DIGEST
 #include "help_tags.h"
 #include "prefs.h"
-#include "StringFormat.h"
+#include "fmt.h"
 #include "OptionParser.h"
 #include "OptionHandler.h"
 #include "util.h"
@@ -77,7 +77,7 @@ void showVersion() {
             << MessageDigest::getSupportedHashTypeString() << "\n"
 #endif // ENABLE_MESSAGE_DIGEST
             << "\n"
-            << StringFormat(_("Report bugs to %s"), PACKAGE_BUGREPORT) << "\n"
+            << fmt(_("Report bugs to %s"), PACKAGE_BUGREPORT) << "\n"
             << "Visit " << PACKAGE_URL << std::endl;
 }
 
@@ -91,13 +91,13 @@ void showUsage(const std::string& keyword, const OptionParser& oparser) {
     if(keyword == TAG_ALL) {
       std::cout << _("Printing all options.");
     } else {
-      std::cout << StringFormat(_("Printing options tagged with '%s'."),
-                                keyword.c_str());
+      std::cout << fmt(_("Printing options tagged with '%s'."),
+                       keyword.c_str());
       std::cout << "\n";
       SharedHandle<OptionHandler> help = oparser.findByName("help");
-      std::cout << StringFormat(_("See -h option to know other command-line"
-                                  " options(%s)."),
-                                help->createPossibleValuesString().c_str());
+      std::cout << fmt(_("See -h option to know other command-line"
+                         " options(%s)."),
+                       help->createPossibleValuesString().c_str());
     }
     std::cout << "\n"
               << _("Options:") << "\n";
@@ -109,8 +109,8 @@ void showUsage(const std::string& keyword, const OptionParser& oparser) {
     std::vector<SharedHandle<OptionHandler> > handlers =
       oparser.findByNameSubstring(keyword);
     if(!handlers.empty()) {
-      std::cout << StringFormat(_("Printing options whose name includes"
-                                  " '%s'."), keyword.c_str())
+      std::cout << fmt(_("Printing options whose name includes '%s'."),
+                       keyword.c_str())
                 << "\n"
                 << _("Options:") << "\n";
       for(std::vector<SharedHandle<OptionHandler> >::const_iterator i =
@@ -118,8 +118,8 @@ void showUsage(const std::string& keyword, const OptionParser& oparser) {
         std::cout << *(*i) << "\n\n";
       }
     } else {
-      std::cout << StringFormat(_("No option matching with '%s'."),
-                                keyword.c_str())
+      std::cout << fmt(_("No option matching with '%s'."),
+                       keyword.c_str())
                 << "\n" << *oparser.findByName("help") << "\n";
     }
   }

+ 0 - 1
test/DefaultExtensionMessageFactoryTest.cc

@@ -17,7 +17,6 @@
 #include "MockBtMessageFactory.h"
 #include "DownloadContext.h"
 #include "BtHandshakeMessage.h"
-#include "StringFormat.h"
 #include "UTMetadataRequestExtensionMessage.h"
 #include "UTMetadataDataExtensionMessage.h"
 #include "UTMetadataRejectExtensionMessage.h"

+ 28 - 0
test/FmtTest.cc

@@ -0,0 +1,28 @@
+#include "fmt.h"
+
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace aria2 {
+
+class FmtTest:public CppUnit::TestFixture {
+
+  CPPUNIT_TEST_SUITE(FmtTest);
+  CPPUNIT_TEST(testFmt);
+  CPPUNIT_TEST_SUITE_END();
+public:
+  void testFmt();
+};
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION(FmtTest);
+
+void FmtTest::testFmt()
+{
+  int major = 1;
+  int minor = 0;
+  int release = 7;
+  CPPUNIT_ASSERT_EQUAL(std::string("aria2-1.0.7-beta"),
+                       fmt("aria2-%d.%d.%d-%s", major, minor, release, "beta"));
+}
+
+} // namespace aria2

+ 1 - 1
test/Makefile.am

@@ -44,8 +44,8 @@ aria2c_SOURCES = AllTest.cc\
 	MultiFileAllocationIteratorTest.cc\
 	FixedNumberRandomizer.h\
 	ProtocolDetectorTest.cc\
-	StringFormatTest.cc\
 	ExceptionTest.cc\
+	FmtTest.cc\
 	DownloadHandlerFactoryTest.cc\
 	SignatureTest.cc\
 	ServerStatManTest.cc\

+ 5 - 5
test/Makefile.in

@@ -203,7 +203,7 @@ am__aria2c_SOURCES_DIST = AllTest.cc TestUtil.cc TestUtil.h \
 	OptionTest.cc DefaultDiskWriterTest.cc FeatureConfigTest.cc \
 	SpeedCalcTest.cc MultiDiskAdaptorTest.cc \
 	MultiFileAllocationIteratorTest.cc FixedNumberRandomizer.h \
-	ProtocolDetectorTest.cc StringFormatTest.cc ExceptionTest.cc \
+	ProtocolDetectorTest.cc ExceptionTest.cc FmtTest.cc \
 	DownloadHandlerFactoryTest.cc SignatureTest.cc \
 	ServerStatManTest.cc FeedbackURISelectorTest.cc \
 	InOrderURISelectorTest.cc ServerStatTest.cc \
@@ -398,8 +398,8 @@ am_aria2c_OBJECTS = AllTest.$(OBJEXT) TestUtil.$(OBJEXT) \
 	FeatureConfigTest.$(OBJEXT) SpeedCalcTest.$(OBJEXT) \
 	MultiDiskAdaptorTest.$(OBJEXT) \
 	MultiFileAllocationIteratorTest.$(OBJEXT) \
-	ProtocolDetectorTest.$(OBJEXT) StringFormatTest.$(OBJEXT) \
-	ExceptionTest.$(OBJEXT) DownloadHandlerFactoryTest.$(OBJEXT) \
+	ProtocolDetectorTest.$(OBJEXT) ExceptionTest.$(OBJEXT) \
+	FmtTest.$(OBJEXT) DownloadHandlerFactoryTest.$(OBJEXT) \
 	SignatureTest.$(OBJEXT) ServerStatManTest.$(OBJEXT) \
 	FeedbackURISelectorTest.$(OBJEXT) \
 	InOrderURISelectorTest.$(OBJEXT) ServerStatTest.$(OBJEXT) \
@@ -638,7 +638,7 @@ aria2c_SOURCES = AllTest.cc TestUtil.cc TestUtil.h SocketCoreTest.cc \
 	OptionTest.cc DefaultDiskWriterTest.cc FeatureConfigTest.cc \
 	SpeedCalcTest.cc MultiDiskAdaptorTest.cc \
 	MultiFileAllocationIteratorTest.cc FixedNumberRandomizer.h \
-	ProtocolDetectorTest.cc StringFormatTest.cc ExceptionTest.cc \
+	ProtocolDetectorTest.cc ExceptionTest.cc FmtTest.cc \
 	DownloadHandlerFactoryTest.cc SignatureTest.cc \
 	ServerStatManTest.cc FeedbackURISelectorTest.cc \
 	InOrderURISelectorTest.cc ServerStatTest.cc \
@@ -833,6 +833,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FeedbackURISelectorTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FileEntryTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FileTest.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FmtTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FtpConnectionTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/GZipDecoderTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/GZipDecodingStreamFilterTest.Po@am__quote@
@@ -895,7 +896,6 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SocketCoreTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SpeedCalcTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Sqlite3CookieParserTest.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StringFormatTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TestUtil.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TimeSeedCriteriaTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TimeTest.Po@am__quote@

+ 32 - 32
test/MetalinkProcessorTest.cc

@@ -18,7 +18,7 @@
 # include "Checksum.h"
 #endif // ENABLE_MESSAGE_DIGEST
 #include "Signature.h"
-#include "StringFormat.h"
+#include "fmt.h"
 #include "RecoverableException.h"
 
 namespace aria2 {
@@ -162,12 +162,12 @@ void MetalinkProcessorTest::testParseFileV4_attrs()
       "<url>http://example.org</url>"
       "</file>"
       "</metalink>";
-    dw->setString(StringFormat(tmpl, "foo").str());
+    dw->setString(fmt(tmpl, "foo"));
     m = proc.parseFromBinaryStream(dw);
     CPPUNIT_ASSERT_EQUAL((size_t)1, m->getEntries().size());
 
     // empty name
-    dw->setString(StringFormat(tmpl, "").str());
+    dw->setString(fmt(tmpl, ""));
     try {
       m = proc.parseFromBinaryStream(dw);
       CPPUNIT_FAIL("exception must be thrown.");
@@ -176,7 +176,7 @@ void MetalinkProcessorTest::testParseFileV4_attrs()
     }
 
     // dir traversing
-    dw->setString(StringFormat(tmpl, "../doughnuts").str());
+    dw->setString(fmt(tmpl, "../doughnuts"));
     try {
       m = proc.parseFromBinaryStream(dw);
       CPPUNIT_FAIL("exception must be thrown.");
@@ -192,7 +192,7 @@ void MetalinkProcessorTest::testParseFileV4_attrs()
       "<url priority=\"%s\">http://example.org</url>"
       "</file>"
       "</metalink>";
-    dw->setString(StringFormat(tmpl, "0").str());
+    dw->setString(fmt(tmpl, "0"));
     try {
       m = proc.parseFromBinaryStream(dw);
       CPPUNIT_FAIL("exception must be thrown.");
@@ -200,26 +200,26 @@ void MetalinkProcessorTest::testParseFileV4_attrs()
       // success
     }
 
-    dw->setString(StringFormat(tmpl, "1").str());
+    dw->setString(fmt(tmpl, "1"));
     m = proc.parseFromBinaryStream(dw);
     CPPUNIT_ASSERT_EQUAL((size_t)1, m->getEntries().size());
 
-    dw->setString(StringFormat(tmpl, "100").str());
+    dw->setString(fmt(tmpl, "100"));
     m = proc.parseFromBinaryStream(dw);
     CPPUNIT_ASSERT_EQUAL((size_t)1, m->getEntries().size());
 
-    dw->setString(StringFormat(tmpl, "999999").str());
+    dw->setString(fmt(tmpl, "999999"));
     m = proc.parseFromBinaryStream(dw);
     CPPUNIT_ASSERT_EQUAL((size_t)1, m->getEntries().size());
 
-    dw->setString(StringFormat(tmpl, "1000000").str());
+    dw->setString(fmt(tmpl, "1000000"));
     try {
       m = proc.parseFromBinaryStream(dw);
       CPPUNIT_FAIL("exception must be thrown.");
     } catch(RecoverableException& e) {
       // success
     }
-    dw->setString(StringFormat(tmpl, "A").str());
+    dw->setString(fmt(tmpl, "A"));
     try {
       m = proc.parseFromBinaryStream(dw);
       CPPUNIT_FAIL("exception must be thrown.");
@@ -234,7 +234,7 @@ void MetalinkProcessorTest::testParseFileV4_attrs()
       "<metaurl priority=\"%s\" mediatype=\"torrent\">http://example.org</metaurl>"
       "</file>"
       "</metalink>";
-    dw->setString(StringFormat(tmpl, "0").str());
+    dw->setString(fmt(tmpl, "0"));
     try {
       m = proc.parseFromBinaryStream(dw);
       CPPUNIT_FAIL("exception must be thrown.");
@@ -242,26 +242,26 @@ void MetalinkProcessorTest::testParseFileV4_attrs()
       // success
     }
 
-    dw->setString(StringFormat(tmpl, "1").str());
+    dw->setString(fmt(tmpl, "1"));
     m = proc.parseFromBinaryStream(dw);
     CPPUNIT_ASSERT_EQUAL((size_t)1, m->getEntries().size());
 
-    dw->setString(StringFormat(tmpl, "100").str());
+    dw->setString(fmt(tmpl, "100"));
     m = proc.parseFromBinaryStream(dw);
     CPPUNIT_ASSERT_EQUAL((size_t)1, m->getEntries().size());
 
-    dw->setString(StringFormat(tmpl, "999999").str());
+    dw->setString(fmt(tmpl, "999999"));
     m = proc.parseFromBinaryStream(dw);
     CPPUNIT_ASSERT_EQUAL((size_t)1, m->getEntries().size());
 
-    dw->setString(StringFormat(tmpl, "1000000").str());
+    dw->setString(fmt(tmpl, "1000000"));
     try {
       m = proc.parseFromBinaryStream(dw);
       CPPUNIT_FAIL("exception must be thrown.");
     } catch(RecoverableException& e) {
       // success
     }
-    dw->setString(StringFormat(tmpl, "A").str());
+    dw->setString(fmt(tmpl, "A"));
     try {
       m = proc.parseFromBinaryStream(dw);
       CPPUNIT_FAIL("exception must be thrown.");
@@ -292,12 +292,12 @@ void MetalinkProcessorTest::testParseFileV4_attrs()
       "</file>"
       "</metalink>";
 
-    dw->setString(StringFormat(tmpl, "torrent").str());
+    dw->setString(fmt(tmpl, "torrent"));
     m = proc.parseFromBinaryStream(dw);
     CPPUNIT_ASSERT_EQUAL((size_t)1, m->getEntries().size());
 
     // empty mediatype
-    dw->setString(StringFormat(tmpl, "").str());
+    dw->setString(fmt(tmpl, ""));
     try {
       m = proc.parseFromBinaryStream(dw);
       CPPUNIT_FAIL("exception must be thrown.");
@@ -315,12 +315,12 @@ void MetalinkProcessorTest::testParseFileV4_attrs()
       "</file>"
       "</metalink>";
 
-    dw->setString(StringFormat(tmpl, "foo").str());
+    dw->setString(fmt(tmpl, "foo"));
     m = proc.parseFromBinaryStream(dw);
     CPPUNIT_ASSERT_EQUAL((size_t)1, m->getEntries().size());
 
     // dir traversing
-    dw->setString(StringFormat(tmpl, "../doughnuts").str());
+    dw->setString(fmt(tmpl, "../doughnuts"));
     try {
       m = proc.parseFromBinaryStream(dw);
       CPPUNIT_FAIL("exception must be thrown.");
@@ -328,7 +328,7 @@ void MetalinkProcessorTest::testParseFileV4_attrs()
       // success
     }
     // empty name
-    dw->setString(StringFormat(tmpl, "").str());
+    dw->setString(fmt(tmpl, ""));
     try {
       m = proc.parseFromBinaryStream(dw);
       CPPUNIT_FAIL("exception must be thrown.");
@@ -366,17 +366,17 @@ void MetalinkProcessorTest::testParseFileV4_attrs()
       "</file>"
       "</metalink>";
 
-    dw->setString(StringFormat(tmpl, "262144").str());
+    dw->setString(fmt(tmpl, "262144"));
     m = proc.parseFromBinaryStream(dw);
     // empty
     try {
-      dw->setString(StringFormat(tmpl, "").str());
+      dw->setString(fmt(tmpl, ""));
       m = proc.parseFromBinaryStream(dw);
       CPPUNIT_FAIL("exception must be thrown.");
     } catch(RecoverableException& e) {}
     // not a number
     try {
-      dw->setString(StringFormat(tmpl, "A").str());
+      dw->setString(fmt(tmpl, "A"));
       m = proc.parseFromBinaryStream(dw);
       CPPUNIT_FAIL("exception must be thrown.");
     } catch(RecoverableException& e) {}
@@ -410,11 +410,11 @@ void MetalinkProcessorTest::testParseFileV4_attrs()
       "</file>"
       "</metalink>";
 
-    dw->setString(StringFormat(tmpl, "sha-1").str());
+    dw->setString(fmt(tmpl, "sha-1"));
     m = proc.parseFromBinaryStream(dw);
     // empty
     try {
-      dw->setString(StringFormat(tmpl, "").str());
+      dw->setString(fmt(tmpl, ""));
       m = proc.parseFromBinaryStream(dw);
       CPPUNIT_FAIL("exception must be thrown.");
     } catch(RecoverableException& e) {}
@@ -444,11 +444,11 @@ void MetalinkProcessorTest::testParseFileV4_attrs()
       "</file>"
       "</metalink>";
 
-    dw->setString(StringFormat(tmpl, "sha-1").str());
+    dw->setString(fmt(tmpl, "sha-1"));
     m = proc.parseFromBinaryStream(dw);
     // empty
     try {
-      dw->setString(StringFormat(tmpl, "").str());
+      dw->setString(fmt(tmpl, ""));
       m = proc.parseFromBinaryStream(dw);
       CPPUNIT_FAIL("exception must be thrown.");
     } catch(RecoverableException& e) {}
@@ -479,11 +479,11 @@ void MetalinkProcessorTest::testParseFileV4_attrs()
       "</file>"
       "</metalink>";
 
-    dw->setString(StringFormat(tmpl, "application/pgp-signature").str());
+    dw->setString(fmt(tmpl, "application/pgp-signature"));
     m = proc.parseFromBinaryStream(dw);
     // empty
     try {
-      dw->setString(StringFormat(tmpl, "").str());
+      dw->setString(fmt(tmpl, ""));
       m = proc.parseFromBinaryStream(dw);
       CPPUNIT_FAIL("exception must be thrown.");
     } catch(RecoverableException& e) {}
@@ -670,10 +670,10 @@ void MetalinkProcessorTest::testBadSizeV4()
      "</file>"
     "</metalink>";
 
-  dw->setString(StringFormat(tmpl, "9223372036854775807").str());
+  dw->setString(fmt(tmpl, "9223372036854775807"));
   m = proc.parseFromBinaryStream(dw);
 
-  dw->setString(StringFormat(tmpl, "-1").str());
+  dw->setString(fmt(tmpl, "-1"));
   try {
     m = proc.parseFromBinaryStream(dw);
     CPPUNIT_FAIL("exception must be thrown.");

+ 0 - 35
test/StringFormatTest.cc

@@ -1,35 +0,0 @@
-#include "StringFormat.h"
-#include "Exception.h"
-#include "util.h"
-#include <iostream>
-#include <cppunit/extensions/HelperMacros.h>
-
-namespace aria2 {
-
-class StringFormatTest:public CppUnit::TestFixture {
-
-  CPPUNIT_TEST_SUITE(StringFormatTest);
-  CPPUNIT_TEST(testStr);
-  CPPUNIT_TEST_SUITE_END();
-public:
-  void setUp() {}
-
-  void tearDown() {}
-
-  void testStr();
-};
-
-
-CPPUNIT_TEST_SUITE_REGISTRATION(StringFormatTest);
-
-void StringFormatTest::testStr()
-{
-  int major = 1;
-  int minor = 0;
-  int release = 7;
-  StringFormat fmt("aria2-%d.%d.%d-%s", major, minor, release, "beta");
-
-  CPPUNIT_ASSERT_EQUAL(std::string("aria2-1.0.7-beta"), fmt.str());
-}
-
-} // namespace aria2

+ 5 - 5
test/TestUtil.cc

@@ -10,10 +10,10 @@
 
 #include "a2io.h"
 #include "File.h"
-#include "StringFormat.h"
 #include "FatalException.h"
 #include "Cookie.h"
 #include "DefaultDiskWriter.h"
+#include "fmt.h"
 #ifdef ENABLE_MESSAGE_DIGEST
 # include "MessageDigestHelper.h"
 #endif // ENABLE_MESSAGE_DIGEST
@@ -25,12 +25,12 @@ void createFile(const std::string& path, size_t length)
   File(File(path).getDirname()).mkdirs();
   int fd = creat(path.c_str(), OPEN_MODE);
   if(fd == -1) {
-    throw FATAL_EXCEPTION(StringFormat("Could not create file=%s. cause:%s",
-                                       path.c_str(), strerror(errno)).str());
+    throw FATAL_EXCEPTION(fmt("Could not create file=%s. cause:%s",
+                              path.c_str(),
+                              strerror(errno)));
   }
   if(-1 == ftruncate(fd, length)) {
-    throw FATAL_EXCEPTION(StringFormat("ftruncate failed. cause:%s",
-                                       strerror(errno)).str());
+    throw FATAL_EXCEPTION(fmt("ftruncate failed. cause:%s", strerror(errno)));
   }
   close(fd);
 }