Explorar o código

2008-05-14 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Made string listeral to static const std::string.
	* src/A2STR.cc
	* src/A2STR.h
	* src/SimpleLogger.cc
	* src/SimpleLogger.h
Tatsuhiro Tsujikawa %!s(int64=17) %!d(string=hai) anos
pai
achega
a37af74369
Modificáronse 5 ficheiros con 44 adicións e 6 borrados
  1. 8 0
      ChangeLog
  2. 4 0
      src/A2STR.cc
  3. 5 0
      src/A2STR.h
  4. 17 6
      src/SimpleLogger.cc
  5. 10 0
      src/SimpleLogger.h

+ 8 - 0
ChangeLog

@@ -1,3 +1,11 @@
+2008-05-14  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Made string listeral to static const std::string.
+	* src/A2STR.cc
+	* src/A2STR.h
+	* src/SimpleLogger.cc
+	* src/SimpleLogger.h
+
 2008-05-13  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Made string literal to static const std::string.

+ 4 - 0
src/A2STR.cc

@@ -40,4 +40,8 @@ const std::string A2STR::NIL("");
 
 const std::string A2STR::SHARP_C("#");
 
+const std::string A2STR::CR_C("\r");
+
+const std::string A2STR::LF_C("\n");
+
 } // namespace aria2

+ 5 - 0
src/A2STR.h

@@ -46,6 +46,11 @@ public:
   static const std::string NIL;
 
   static const std::string SHARP_C;
+
+  static const std::string CR_C;
+
+  static const std::string LF_C;
+
 };
 } // namespace aria2
 

+ 17 - 6
src/SimpleLogger.cc

@@ -39,6 +39,7 @@
 #include "a2io.h"
 #include "a2time.h"
 #include "StringFormat.h"
+#include "A2STR.h"
 #include <cerrno>
 #include <cstring>
 #include <iostream>
@@ -69,6 +70,16 @@ writeStackTrace(Logger::LEVEL, EX);\
 flush();\
 va_end(ap);
 
+const std::string SimpleLogger::DEBUG("DEBUG");
+
+const std::string SimpleLogger::NOTICE("NOTICE");
+
+const std::string SimpleLogger::WARN("WARN");
+
+const std::string SimpleLogger::ERROR("ERROR");
+
+const std::string SimpleLogger::INFO("INFO");
+
 SimpleLogger::SimpleLogger():stdoutField(0) {}
 
 SimpleLogger::~SimpleLogger() {
@@ -112,20 +123,20 @@ void SimpleLogger::writeLog(std::ostream& o, Logger::LEVEL level,
   std::string levelStr;
   switch(level) {
   case Logger::DEBUG:
-    levelStr = "DEBUG";
+    levelStr = DEBUG;
     break;
   case Logger::NOTICE:
-    levelStr = "NOTICE";
+    levelStr = NOTICE;
     break;
   case Logger::WARN:
-    levelStr = "WARN";
+    levelStr = WARN;
     break;
   case Logger::ERROR:
-    levelStr = "ERROR";
+    levelStr = ERROR;
     break;
   case Logger::INFO:
   default:
-    levelStr = "INFO";
+    levelStr = INFO;
   }
   time_t now = time(NULL);
   char datestr[20];
@@ -139,7 +150,7 @@ void SimpleLogger::writeLog(std::ostream& o, Logger::LEVEL level,
   }
   {
     char* res;
-    if(vasprintf(&res, std::string(Util::replace(msg, "\r", "")+"\n").c_str(), apCopy) == -1) {
+    if(vasprintf(&res, std::string(Util::replace(msg, A2STR::CR_C, A2STR::NIL)+A2STR::LF_C).c_str(), apCopy) == -1) {
       o << "SimpleLogger error, cannot allocate memory.\n";
     } else {
       o << res;

+ 10 - 0
src/SimpleLogger.h

@@ -59,6 +59,16 @@ private:
 
   std::ofstream file;
   int stdoutField;
+
+  static const std::string DEBUG;
+
+  static const std::string NOTICE;
+
+  static const std::string WARN;
+
+  static const std::string ERROR;
+
+  static const std::string INFO;
 public:
   SimpleLogger();
   ~SimpleLogger();