|
5 | 5 | #include "string_utils.h"
|
6 | 6 |
|
7 | 7 | #include <algorithm>
|
8 |
| -#include <array> |
9 | 8 | #include <cctype>
|
10 | 9 | #include <codecvt>
|
11 | 10 | #include <locale>
|
12 | 11 | #include <regex>
|
13 | 12 | #include <sstream>
|
14 | 13 |
|
15 | 14 | #include "flutter/fml/string_conversion.h"
|
16 |
| -#include "third_party/dart/runtime/third_party/double-conversion/src/double-conversion.h" |
17 | 15 |
|
18 | 16 | #include "base/logging.h"
|
19 | 17 | #include "icu_utf.h"
|
20 | 18 | #include "no_destructor.h"
|
21 | 19 |
|
22 | 20 | namespace base {
|
23 | 21 |
|
24 |
| -using double_conversion::DoubleToStringConverter; |
25 |
| -using double_conversion::StringBuilder; |
26 |
| - |
27 |
| -namespace { |
28 |
| -constexpr char kExponentChar = 'e'; |
29 |
| -constexpr char kInfinitySymbol[] = "Infinity"; |
30 |
| -constexpr char kNaNSymbol[] = "NaN"; |
31 |
| - |
32 |
| -// The number of digits after the decimal we allow before switching to |
33 |
| -// exponential representation. |
34 |
| -constexpr int kDecimalInShortestLow = -6; |
35 |
| -// The number of digits before the decimal we allow before switching to |
36 |
| -// exponential representation. |
37 |
| -constexpr int kDecimalInShortestHigh = 12; |
38 |
| -constexpr int kConversionFlags = |
39 |
| - DoubleToStringConverter::EMIT_POSITIVE_EXPONENT_SIGN; |
40 |
| - |
41 |
| -const DoubleToStringConverter& GetDoubleToStringConverter() { |
42 |
| - static DoubleToStringConverter converter( |
43 |
| - kConversionFlags, kInfinitySymbol, kNaNSymbol, kExponentChar, |
44 |
| - kDecimalInShortestLow, kDecimalInShortestHigh, 0, 0); |
45 |
| - return converter; |
46 |
| -} |
47 |
| - |
48 |
| -std::string NumberToStringImpl(double number, bool is_single_precision) { |
49 |
| - if (number == 0.0) { |
50 |
| - return "0"; |
51 |
| - } |
52 |
| - |
53 |
| - constexpr int kBufferSize = 128; |
54 |
| - std::array<char, kBufferSize> char_buffer; |
55 |
| - StringBuilder builder(char_buffer.data(), char_buffer.size()); |
56 |
| - if (is_single_precision) { |
57 |
| - GetDoubleToStringConverter().ToShortestSingle(static_cast<float>(number), |
58 |
| - &builder); |
59 |
| - } else { |
60 |
| - GetDoubleToStringConverter().ToShortest(number, &builder); |
61 |
| - } |
62 |
| - return std::string(char_buffer.data(), builder.position()); |
63 |
| -} |
64 |
| -} // namespace |
65 |
| - |
66 | 22 | std::u16string ASCIIToUTF16(std::string src) {
|
67 | 23 | return std::u16string(src.begin(), src.end());
|
68 | 24 | }
|
@@ -108,11 +64,15 @@ std::string NumberToString(unsigned int number) {
|
108 | 64 | }
|
109 | 65 |
|
110 | 66 | std::string NumberToString(float number) {
|
111 |
| - return NumberToStringImpl(number, true); |
| 67 | + // TODO(gw280): Format decimals to the shortest reasonable representation. |
| 68 | + // See: https://github.com/flutter/flutter/issues/78460 |
| 69 | + return std::to_string(number); |
112 | 70 | }
|
113 | 71 |
|
114 | 72 | std::string NumberToString(double number) {
|
115 |
| - return NumberToStringImpl(number, false); |
| 73 | + // TODO(gw280): Format decimals to the shortest reasonable representation. |
| 74 | + // See: https://github.com/flutter/flutter/issues/78460 |
| 75 | + return std::to_string(number); |
116 | 76 | }
|
117 | 77 |
|
118 | 78 | std::string NumberToString(int64_t number) {
|
|
0 commit comments