summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/text/PlatformString.h
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/platform/text/PlatformString.h')
-rw-r--r--WebCore/platform/text/PlatformString.h150
1 files changed, 128 insertions, 22 deletions
diff --git a/WebCore/platform/text/PlatformString.h b/WebCore/platform/text/PlatformString.h
index f900513..73a44bd 100644
--- a/WebCore/platform/text/PlatformString.h
+++ b/WebCore/platform/text/PlatformString.h
@@ -27,23 +27,34 @@
#include "StringImpl.h"
-#if PLATFORM(CF)
+#include <wtf/PassRefPtr.h>
+
+#if USE(JSC)
+#include <kjs/identifier.h>
+#else
+// kjs/identifier.h includes HashMap.h. We explicitly include it in the case of
+// non-JSC builds to keep things consistent.
+#include <wtf/HashMap.h>
+#endif
+
+#if PLATFORM(CF) || (PLATFORM(QT) && PLATFORM(DARWIN))
typedef const struct __CFString * CFStringRef;
#endif
#if PLATFORM(QT)
+QT_BEGIN_NAMESPACE
class QString;
+QT_END_NAMESPACE
#endif
#if PLATFORM(WX)
class wxString;
#endif
-
namespace WebCore {
class CString;
-class DeprecatedString;
+class SharedBuffer;
struct StringHash;
class String {
@@ -51,19 +62,28 @@ public:
String() { } // gives null string, distinguishable from an empty string
String(const UChar*, unsigned length);
String(const UChar*); // Specifically for null terminated UTF-16
- String(const KJS::Identifier&);
- String(const KJS::UString&);
+#if USE(JSC)
+ String(const JSC::Identifier&);
+ String(const JSC::UString&);
+#endif
String(const char*);
String(const char*, unsigned length);
String(StringImpl* i) : m_impl(i) { }
String(PassRefPtr<StringImpl> i) : m_impl(i) { }
String(RefPtr<StringImpl> i) : m_impl(i) { }
+ void swap(String& o) { m_impl.swap(o.m_impl); }
+
+ // Hash table deleted values, which are only constructed and never copied or destroyed.
+ String(WTF::HashTableDeletedValueType) : m_impl(WTF::HashTableDeletedValue) { }
+ bool isHashTableDeletedValue() const { return m_impl.isHashTableDeletedValue(); }
+
static String adopt(StringBuffer& buffer) { return StringImpl::adopt(buffer); }
static String adopt(Vector<UChar>& vector) { return StringImpl::adopt(vector); }
- operator KJS::Identifier() const;
- operator KJS::UString() const;
+#if USE(JSC)
+ operator JSC::UString() const;
+#endif
unsigned length() const;
const UChar* characters() const;
@@ -132,17 +152,24 @@ public:
static String format(const char *, ...) WTF_ATTRIBUTE_PRINTF(1, 2);
- Vector<String> split(const String& separator, bool allowEmptyEntries = false) const;
- Vector<String> split(UChar separator, bool allowEmptyEntries = false) const;
+ void split(const String& separator, Vector<String>& result) const;
+ void split(const String& separator, bool allowEmptyEntries, Vector<String>& result) const;
+ void split(UChar separator, Vector<String>& result) const;
+ void split(UChar separator, bool allowEmptyEntries, Vector<String>& result) const;
+
+ int toIntStrict(bool* ok = 0, int base = 10) const;
+ unsigned toUIntStrict(bool* ok = 0, int base = 10) const;
+ int64_t toInt64Strict(bool* ok = 0, int base = 10) const;
+ uint64_t toUInt64Strict(bool* ok = 0, int base = 10) const;
int toInt(bool* ok = 0) const;
+ unsigned toUInt(bool* ok = 0) const;
int64_t toInt64(bool* ok = 0) const;
uint64_t toUInt64(bool* ok = 0) const;
double toDouble(bool* ok = 0) const;
float toFloat(bool* ok = 0) const;
- Length* toLengthArray(int& len) const;
- Length* toCoordsArray(int& len) const;
- bool percentage(int &_percentage) const;
+
+ bool percentage(int& percentage) const;
// Makes a deep copy. Helpful only if you need to use a String on another thread.
// Since the underlying StringImpl objects are immutable, there's no other reason
@@ -154,7 +181,7 @@ public:
StringImpl* impl() const { return m_impl.get(); }
-#if PLATFORM(CF)
+#if PLATFORM(CF) || (PLATFORM(QT) && PLATFORM(DARWIN))
String(CFStringRef);
CFStringRef createCFString() const;
#endif
@@ -196,10 +223,7 @@ public:
// Determines the writing direction using the Unicode Bidi Algorithm rules P2 and P3.
WTF::Unicode::Direction defaultWritingDirection() const { return m_impl ? m_impl->defaultWritingDirection() : WTF::Unicode::LeftToRight; }
-
- String(const DeprecatedString&);
- DeprecatedString deprecatedString() const;
-
+
private:
RefPtr<StringImpl> m_impl;
};
@@ -222,13 +246,30 @@ inline bool equalIgnoringCase(const String& a, const String& b) { return equalIg
inline bool equalIgnoringCase(const String& a, const char* b) { return equalIgnoringCase(a.impl(), b); }
inline bool equalIgnoringCase(const char* a, const String& b) { return equalIgnoringCase(a, b.impl()); }
-bool operator==(const String& a, const DeprecatedString& b);
-inline bool operator==(const DeprecatedString& b, const String& a) { return a == b; }
-inline bool operator!=(const String& a, const DeprecatedString& b) { return !(a == b); }
-inline bool operator!=(const DeprecatedString& b, const String& a ) { return !(a == b); }
-
inline bool operator!(const String& str) { return str.isNull(); }
+inline void swap(String& a, String& b) { a.swap(b); }
+
+// String Operations
+
+bool charactersAreAllASCII(const UChar*, size_t);
+
+int charactersToIntStrict(const UChar*, size_t, bool* ok = 0, int base = 10);
+unsigned charactersToUIntStrict(const UChar*, size_t, bool* ok = 0, int base = 10);
+int64_t charactersToInt64Strict(const UChar*, size_t, bool* ok = 0, int base = 10);
+uint64_t charactersToUInt64Strict(const UChar*, size_t, bool* ok = 0, int base = 10);
+
+int charactersToInt(const UChar*, size_t, bool* ok = 0); // ignores trailing garbage
+unsigned charactersToUInt(const UChar*, size_t, bool* ok = 0); // ignores trailing garbage
+int64_t charactersToInt64(const UChar*, size_t, bool* ok = 0); // ignores trailing garbage
+uint64_t charactersToUInt64(const UChar*, size_t, bool* ok = 0); // ignores trailing garbage
+
+double charactersToDouble(const UChar*, size_t, bool* ok = 0);
+float charactersToFloat(const UChar*, size_t, bool* ok = 0);
+
+int find(const UChar*, size_t, UChar, int startPosition = 0);
+int reverseFind(const UChar*, size_t, UChar, int startPosition = -1);
+
#ifdef __OBJC__
// This is for situations in WebKit where the long standing behavior has been
// "nil if empty", so we try to maintain longstanding behavior for the sake of
@@ -236,8 +277,73 @@ inline bool operator!(const String& str) { return str.isNull(); }
inline NSString* nsStringNilIfEmpty(const String& str) { return str.isEmpty() ? nil : (NSString*)str; }
#endif
+inline bool charactersAreAllASCII(const UChar* characters, size_t length)
+{
+ UChar ored = 0;
+ for (size_t i = 0; i < length; ++i)
+ ored |= characters[i];
+ return !(ored & 0xFF80);
}
+inline int find(const UChar* characters, size_t length, UChar character, int startPosition)
+{
+ if (startPosition >= static_cast<int>(length))
+ return -1;
+ for (size_t i = startPosition; i < length; ++i) {
+ if (characters[i] == character)
+ return static_cast<int>(i);
+ }
+ return -1;
+}
+
+inline int reverseFind(const UChar* characters, size_t length, UChar character, int startPosition)
+{
+ if (startPosition >= static_cast<int>(length) || !length)
+ return -1;
+ if (startPosition < 0)
+ startPosition += static_cast<int>(length);
+ while (true) {
+ if (characters[startPosition] == character)
+ return startPosition;
+ if (!startPosition)
+ return -1;
+ startPosition--;
+ }
+ ASSERT_NOT_REACHED();
+ return -1;
+}
+
+inline void append(Vector<UChar>& vector, const String& string)
+{
+ vector.append(string.characters(), string.length());
+}
+
+inline void appendNumber(Vector<UChar>& vector, unsigned char number)
+{
+ int numberLength = number > 99 ? 3 : (number > 9 ? 2 : 1);
+ size_t vectorSize = vector.size();
+ vector.grow(vectorSize + numberLength);
+
+ switch (numberLength) {
+ case 3:
+ vector[vectorSize + 2] = number % 10 + '0';
+ number /= 10;
+
+ case 2:
+ vector[vectorSize + 1] = number % 10 + '0';
+ number /= 10;
+
+ case 1:
+ vector[vectorSize] = number % 10 + '0';
+ }
+}
+
+
+
+PassRefPtr<SharedBuffer> utf8Buffer(const String&);
+
+} // namespace WebCore
+
namespace WTF {
// StringHash is the default hash for String