Bump version to 10:0
[folly.git] / folly / Format.cpp
index 169eca087192066ddc1963c547727a81b70052d7..feec8fb255c3f9b4c15807e22f43e9433aad56d8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2014 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "folly/Format.h"
+#include <folly/Format.h>
 
 namespace folly {
 namespace detail {
@@ -70,7 +70,7 @@ void FormatArg::initSlow() {
     }
 
     if (*p == '0') {
-      CHECK(align == Align::DEFAULT) << errorStr("alignment specified twice");
+      enforce(align == Align::DEFAULT, "alignment specified twice");
       fill = '0';
       align = Align::PAD_AFTER_SIGN;
       if (++p == end) return;
@@ -96,7 +96,15 @@ void FormatArg::initSlow() {
       while (p != end && *p >= '0' && *p <= '9') {
         ++p;
       }
-      precision = to<int>(StringPiece(b, p));
+      if (p != b) {
+        precision = to<int>(StringPiece(b, p));
+        if (p != end && *p == '.') {
+          trailingDot = true;
+          ++p;
+        }
+      } else {
+        trailingDot = true;
+      }
 
       if (p == end) return;
     }
@@ -105,31 +113,31 @@ void FormatArg::initSlow() {
     if (++p == end) return;
   }
 
-  LOG(FATAL) << "extra characters in format string";
+  error("extra characters in format string");
 }
 
 void FormatArg::validate(Type type) const {
-  CHECK(keyEmpty()) << "index not allowed";
+  enforce(keyEmpty(), "index not allowed");
   switch (type) {
   case Type::INTEGER:
-    CHECK(precision == kDefaultPrecision)
-      << errorStr("precision not allowed on integers");
+    enforce(precision == kDefaultPrecision,
+            "precision not allowed on integers");
     break;
   case Type::FLOAT:
-    CHECK(!basePrefix)
-      << errorStr("base prefix ('#') specifier only allowed on integers");
-    CHECK(!thousandsSeparator)
-      << errorStr("thousands separator (',') only allowed on integers");
+    enforce(!basePrefix,
+            "base prefix ('#') specifier only allowed on integers");
+    enforce(!thousandsSeparator,
+            "thousands separator (',') only allowed on integers");
     break;
   case Type::OTHER:
-    CHECK(align != Align::PAD_AFTER_SIGN)
-      << errorStr("'='alignment only allowed on numbers");
-    CHECK(sign == Sign::DEFAULT)
-      << errorStr("sign specifier only allowed on numbers");
-    CHECK(!basePrefix)
-      << errorStr("base prefix ('#') specifier only allowed on integers");
-    CHECK(!thousandsSeparator)
-      << errorStr("thousands separator (',') only allowed on integers");
+    enforce(align != Align::PAD_AFTER_SIGN,
+            "'='alignment only allowed on numbers");
+    enforce(sign == Sign::DEFAULT,
+            "sign specifier only allowed on numbers");
+    enforce(!basePrefix,
+            "base prefix ('#') specifier only allowed on integers");
+    enforce(!thousandsSeparator,
+            "thousands separator (',') only allowed on integers");
     break;
   }
 }