Browse Source

Merge pull request #6072 from haon4/revert_strcat

Partially Revert "Replaced all instances of Simple{IDF}toa with StrCat."
Hao Nguyen 6 years ago
parent
commit
7f07bcdcfc

+ 2 - 2
src/google/protobuf/compiler/cpp/cpp_helpers.cc

@@ -643,7 +643,7 @@ std::string DefaultValue(const Options& options, const FieldDescriptor* field) {
       } else if (value != value) {
         return "std::numeric_limits<double>::quiet_NaN()";
       } else {
-        return StrCat(value);
+        return SimpleDtoa(value);
       }
     }
     case FieldDescriptor::CPPTYPE_FLOAT: {
@@ -655,7 +655,7 @@ std::string DefaultValue(const Options& options, const FieldDescriptor* field) {
       } else if (value != value) {
         return "std::numeric_limits<float>::quiet_NaN()";
       } else {
-        std::string float_value = StrCat(value);
+        std::string float_value = SimpleFtoa(value);
         // If floating point value contains a period (.) or an exponent
         // (either E or e), then append suffix 'f' to make it a float
         // literal.

+ 2 - 2
src/google/protobuf/compiler/csharp/csharp_field_base.cc

@@ -325,7 +325,7 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor)
       } else if (std::isnan(value)) {
         return "double.NaN";
       }
-      return StrCat(value) + "D";
+      return SimpleDtoa(value) + "D";
     }
     case FieldDescriptor::TYPE_FLOAT: {
       float value = descriptor->default_value_float();
@@ -336,7 +336,7 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor)
       } else if (std::isnan(value)) {
         return "float.NaN";
       }
-      return StrCat(value) + "F";
+      return SimpleFtoa(value) + "F";
     }
     case FieldDescriptor::TYPE_INT64:
       return StrCat(descriptor->default_value_int64()) + "L";

+ 2 - 2
src/google/protobuf/compiler/java/java_helpers.cc

@@ -522,7 +522,7 @@ std::string DefaultValue(const FieldDescriptor* field, bool immutable,
       } else if (value != value) {
         return "Double.NaN";
       } else {
-        return StrCat(value) + "D";
+        return SimpleDtoa(value) + "D";
       }
     }
     case FieldDescriptor::CPPTYPE_FLOAT: {
@@ -534,7 +534,7 @@ std::string DefaultValue(const FieldDescriptor* field, bool immutable,
       } else if (value != value) {
         return "Float.NaN";
       } else {
-        return StrCat(value) + "F";
+        return SimpleFtoa(value) + "F";
       }
     }
     case FieldDescriptor::CPPTYPE_BOOL:

+ 5 - 5
src/google/protobuf/compiler/js/js_generator.cc

@@ -733,9 +733,9 @@ std::string EscapeBase64(const std::string& in) {
   return result;
 }
 
-// Post-process the result of StrCat to *exactly* match the original codegen's
-// formatting (which is just .toString() on java.lang.Double or
-// java.lang.Float).
+// Post-process the result of SimpleFtoa/SimpleDtoa to *exactly* match the
+// original codegen's formatting (which is just .toString() on java.lang.Double
+// or java.lang.Float).
 std::string PostProcessFloat(std::string result) {
   // If inf, -inf or nan, replace with +Infinity, -Infinity or NaN.
   if (result == "inf") {
@@ -787,12 +787,12 @@ std::string PostProcessFloat(std::string result) {
 }
 
 std::string FloatToString(float value) {
-  std::string result = StrCat(value);
+  std::string result = SimpleFtoa(value);
   return PostProcessFloat(result);
 }
 
 std::string DoubleToString(double value) {
-  std::string result = StrCat(value);
+  std::string result = SimpleDtoa(value);
   return PostProcessFloat(result);
 }
 

+ 2 - 2
src/google/protobuf/compiler/objectivec/objectivec_helpers.cc

@@ -818,10 +818,10 @@ string DefaultValue(const FieldDescriptor* field) {
       return StrCat(field->default_value_uint64()) + "ULL";
     case FieldDescriptor::CPPTYPE_DOUBLE:
       return HandleExtremeFloatingPoint(
-          StrCat(field->default_value_double()), false);
+          SimpleDtoa(field->default_value_double()), false);
     case FieldDescriptor::CPPTYPE_FLOAT:
       return HandleExtremeFloatingPoint(
-          StrCat(field->default_value_float()), true);
+          SimpleFtoa(field->default_value_float()), true);
     case FieldDescriptor::CPPTYPE_BOOL:
       return field->default_value_bool() ? "YES" : "NO";
     case FieldDescriptor::CPPTYPE_STRING: {

+ 1 - 1
src/google/protobuf/compiler/parser.cc

@@ -1267,7 +1267,7 @@ bool Parser::ParseDefaultAssignment(
       double value;
       DO(ConsumeNumber(&value, "Expected number."));
       // And stringify it again.
-      default_value->append(StrCat(value));
+      default_value->append(SimpleDtoa(value));
       break;
 
     case FieldDescriptorProto::TYPE_BOOL:

+ 2 - 2
src/google/protobuf/compiler/python/python_generator.cc

@@ -250,7 +250,7 @@ std::string StringifyDefaultValue(const FieldDescriptor& field) {
         // infinity * 0 = nan
         return "(1e10000 * 0)";
       } else {
-        return "float(" + StrCat(value) + ")";
+        return "float(" + SimpleDtoa(value) + ")";
       }
     }
     case FieldDescriptor::CPPTYPE_FLOAT: {
@@ -266,7 +266,7 @@ std::string StringifyDefaultValue(const FieldDescriptor& field) {
         // infinity - infinity = nan
         return "(1e10000 * 0)";
       } else {
-        return "float(" + StrCat(value) + ")";
+        return "float(" + SimpleFtoa(value) + ")";
       }
     }
     case FieldDescriptor::CPPTYPE_BOOL: