ソースを参照

Clean up excess code in format

Sam Jaffe 6 年 前
コミット
1426c8c4df
2 ファイル変更6 行追加22 行削除
  1. 6 14
      include/logger/format.h
  2. 0 8
      src/format.cxx

+ 6 - 14
include/logger/format.h

@@ -35,27 +35,19 @@ namespace logging {
     msg << interp.substr(pos);
   }
   
-  struct format_point_t {
-    size_t start;
-    size_t end;
-  };
-  
-  format_point_t get_next_format_specifier(std::string const & interp,
-                                           size_t pos );
-  
   template <typename Arg0, typename... Args>
   inline void format_msg(std::stringstream & msg, std::string const & interp,
                          size_t pos, Arg0 && arg0, Args && ...args) {
-    format_point_t next = get_next_format_specifier( interp, pos );
-    msg << interp.substr(pos, next.start);
-    if (next.start == std::string::npos) {
+    size_t next = interp.find("{}", pos);
+    msg << interp.substr(pos, next);
+    if (next == std::string::npos) {
       return; // throw?
-    } else if (!strncmp(interp.c_str() + next.start - 1, "{{}}", 4)) {
-      format_msg(msg, interp, next.end, std::forward<Arg0>(arg0),
+    } else if (!strncmp(interp.c_str() + next - 1, "{{}}", 4)) {
+      format_msg(msg, interp, next+2, std::forward<Arg0>(arg0),
                  std::forward<Args>(args)... );
     } else {
       msg << arg0;
-      format_msg(msg, interp, next.end, std::forward<Args>(args)... );
+      format_msg(msg, interp, next+2, std::forward<Args>(args)... );
     }
   }
   

+ 0 - 8
src/format.cxx

@@ -206,11 +206,3 @@ namespace logging {
     return ss.str();
   }
 }
-
-namespace logging {
-  format_point_t get_next_format_specifier(std::string const & interp,
-                                           size_t pos) {
-    size_t next = interp.find("{}", pos);
-    return { next, next + 2 };
-  }
-}