summaryrefslogtreecommitdiffstats
path: root/JavaScriptCore/wtf/text/WTFString.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'JavaScriptCore/wtf/text/WTFString.cpp')
-rw-r--r--JavaScriptCore/wtf/text/WTFString.cpp65
1 files changed, 29 insertions, 36 deletions
diff --git a/JavaScriptCore/wtf/text/WTFString.cpp b/JavaScriptCore/wtf/text/WTFString.cpp
index bbff576..a83dbba 100644
--- a/JavaScriptCore/wtf/text/WTFString.cpp
+++ b/JavaScriptCore/wtf/text/WTFString.cpp
@@ -25,10 +25,10 @@
#include <limits>
#include <stdarg.h>
#include <wtf/ASCIICType.h>
-#include <wtf/DecimalNumber.h>
+#include <wtf/text/CString.h>
#include <wtf/StringExtras.h>
#include <wtf/Vector.h>
-#include <wtf/text/CString.h>
+#include <wtf/dtoa.h>
#include <wtf/unicode/UTF8.h>
#include <wtf/unicode/Unicode.h>
@@ -947,49 +947,42 @@ float charactersToFloat(const UChar* data, size_t length, bool* ok)
return static_cast<float>(charactersToDouble(data, length, ok));
}
-static unsigned copyToString(const char* string, unsigned length, NumberToStringBuffer& buffer)
-{
- for (unsigned i = 0; i < length; ++i)
- buffer[i] = string[i];
- return length;
-}
+} // namespace WTF
-static NEVER_INLINE unsigned nanOrInfToString(double x, NumberToStringBuffer& buffer)
+#ifndef NDEBUG
+// For use in the debugger
+String* string(const char*);
+Vector<char> asciiDebug(StringImpl* impl);
+Vector<char> asciiDebug(String& string);
+
+String* string(const char* s)
{
- ASSERT(isnan(x) || isinf(x));
- if (isnan(x))
- return copyToString("NaN", 3, buffer);
- if (x < 0)
- return copyToString("-Infinity", 9, buffer);
- return copyToString("Infinity", 8, buffer);
+ // leaks memory!
+ return new String(s);
}
-// toString converts a number to a string without rounding. For values in the range
-// 1e-6 <= x < 1e+21 the result is formatted as a decimal, with values outside of
-// this range being formatted as an exponential.
-unsigned numberToString(double x, NumberToStringBuffer& buffer)
+Vector<char> asciiDebug(StringImpl* impl)
{
- // Handle NaN and Infinity.
- if (UNLIKELY(isnan(x) || isinf(x)))
- return nanOrInfToString(x, buffer);
-
- // Convert to decimal, no rounding.
- DecimalNumber number(x);
+ if (!impl)
+ return asciiDebug(String("[null]").impl());
- // Format as decimal or exponential, depending on the exponent.
- return number.exponent() >= -6 && number.exponent() < 21
- ? number.toStringDecimal(buffer)
- : number.toStringExponential(buffer);
-}
+ Vector<char> buffer;
+ unsigned length = impl->length();
+ const UChar* characters = impl->characters();
-} // namespace WTF
+ buffer.resize(length + 1);
+ for (unsigned i = 0; i < length; ++i) {
+ UChar ch = characters[i];
+ buffer[i] = ch && (ch < 0x20 || ch > 0x7f) ? '?' : ch;
+ }
+ buffer[length] = '\0';
-#ifndef NDEBUG
-// For use in the debugger - leaks memory
-String* string(const char*);
+ return buffer;
+}
-String* string(const char* s)
+Vector<char> asciiDebug(String& string)
{
- return new String(s);
+ return asciiDebug(string.impl());
}
+
#endif