OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2008, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2008, 2010 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 25 matching lines...) Expand all Loading... |
36 #include "wtf/text/WTFString.h" | 36 #include "wtf/text/WTFString.h" |
37 | 37 |
38 namespace blink { | 38 namespace blink { |
39 | 39 |
40 static const size_t printBufferSize = 100; // large enough for any integer or fl
oating point value in string format, including trailing null character | 40 static const size_t printBufferSize = 100; // large enough for any integer or fl
oating point value in string format, including trailing null character |
41 | 41 |
42 static inline bool hasFractions(double val) | 42 static inline bool hasFractions(double val) |
43 { | 43 { |
44 // We use 0.011 to more than match the number of significant digits we print
out when dumping the render tree. | 44 // We use 0.011 to more than match the number of significant digits we print
out when dumping the render tree. |
45 static const double s_epsilon = 0.011; | 45 static const double s_epsilon = 0.011; |
46 int ival = static_cast<int>(val); | 46 int ival = static_cast<int>(round(val)); |
47 double dval = static_cast<double>(ival); | 47 double dval = static_cast<double>(ival); |
48 return fabs(val - dval) > s_epsilon; | 48 return fabs(val - dval) > s_epsilon; |
49 } | 49 } |
50 | 50 |
51 TextStream& TextStream::operator<<(bool b) | 51 TextStream& TextStream::operator<<(bool b) |
52 { | 52 { |
53 return *this << (b ? "1" : "0"); | 53 return *this << (b ? "1" : "0"); |
54 } | 54 } |
55 | 55 |
56 TextStream& TextStream::operator<<(int i) | 56 TextStream& TextStream::operator<<(int i) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 { | 118 { |
119 m_text.append(string); | 119 m_text.append(string); |
120 return *this; | 120 return *this; |
121 } | 121 } |
122 | 122 |
123 TextStream& TextStream::operator<<(const FormatNumberRespectingIntegers& numberT
oFormat) | 123 TextStream& TextStream::operator<<(const FormatNumberRespectingIntegers& numberT
oFormat) |
124 { | 124 { |
125 if (hasFractions(numberToFormat.value)) | 125 if (hasFractions(numberToFormat.value)) |
126 return *this << numberToFormat.value; | 126 return *this << numberToFormat.value; |
127 | 127 |
128 m_text.appendNumber(static_cast<int>(numberToFormat.value)); | 128 m_text.appendNumber(static_cast<int>(round(numberToFormat.value))); |
129 return *this; | 129 return *this; |
130 } | 130 } |
131 | 131 |
132 String TextStream::release() | 132 String TextStream::release() |
133 { | 133 { |
134 String result = m_text.toString(); | 134 String result = m_text.toString(); |
135 m_text.clear(); | 135 m_text.clear(); |
136 return result; | 136 return result; |
137 } | 137 } |
138 | 138 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 return ts; | 170 return ts; |
171 } | 171 } |
172 | 172 |
173 void writeIndent(TextStream& ts, int indent) | 173 void writeIndent(TextStream& ts, int indent) |
174 { | 174 { |
175 for (int i = 0; i != indent; ++i) | 175 for (int i = 0; i != indent; ++i) |
176 ts << " "; | 176 ts << " "; |
177 } | 177 } |
178 | 178 |
179 } | 179 } |
OLD | NEW |