Merge pull request #6072 from haon4/revert_strcat

Partially Revert "Replaced all instances of Simple{IDF}toa with StrCat."
This commit is contained in:
Hao Nguyen 2019-04-25 14:41:36 -07:00 committed by GitHub
commit 7f07bcdcfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 16 deletions

View File

@ -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.

View File

@ -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";

View File

@ -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:

View File

@ -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);
}

View File

@ -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: {

View File

@ -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:

View File

@ -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: