Changeset 65302 in webkit for trunk/JavaScriptCore/runtime/UString.h
- Timestamp:
- Aug 12, 2010, 11:42:16 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/UString.h
r65295 r65302 39 39 namespace JSC { 40 40 41 using WTF::PlacementNewAdoptType; 42 using WTF::PlacementNewAdopt; 43 41 44 class UString { 42 45 public: … … 61 64 UString(RefPtr<StringImpl> impl) : m_impl(impl) { } 62 65 63 // Inline the destructor.64 ALWAYS_INLINE ~UString() { }65 66 66 void swap(UString& o) { m_impl.swap(o.m_impl); } 67 67 … … 69 69 static UString adopt(Vector<UChar, inlineCapacity>& vector) { return StringImpl::adopt(vector); } 70 70 71 bool isNull() const { return !m_impl; }72 bool isEmpty() const { return !m_impl || !m_impl->length(); }73 74 StringImpl* impl() const { return m_impl.get(); }75 76 unsigned length() const77 {78 if (!m_impl)79 return 0;80 return m_impl->length();81 }82 83 const UChar* characters() const84 {85 if (!m_impl)86 return 0;87 return m_impl->characters();88 }89 90 CString utf8(bool strict = false) const;91 92 UChar operator[](unsigned index) const93 {94 if (!m_impl || index >= m_impl->length())95 return 0;96 return m_impl->characters()[index];97 }98 99 71 static UString number(int); 72 static UString number(long long); 100 73 static UString number(unsigned); 101 74 static UString number(long); 102 static UString number(long long);103 75 static UString number(double); 104 76 105 77 // NOTE: This method should only be used for *debugging* purposes as it 78 // is neither Unicode safe nor free from side effects nor thread-safe. 79 char* ascii() const; 80 81 /** 82 * Convert the string to UTF-8, assuming it is UTF-16 encoded. 83 * In non-strict mode, this function is tolerant of badly formed UTF-16, it 84 * can create UTF-8 strings that are invalid because they have characters in 85 * the range U+D800-U+DDFF, U+FFFE, or U+FFFF, but the UTF-8 string is 86 * guaranteed to be otherwise valid. 87 * In strict mode, error is returned as null CString. 88 */ 89 CString UTF8String(bool strict = false) const; 90 91 unsigned length() const 92 { 93 if (!m_impl) 94 return 0; 95 return m_impl->length(); 96 } 97 98 const UChar* characters() const 99 { 100 if (!m_impl) 101 return 0; 102 return m_impl->characters(); 103 } 104 105 UChar operator[](unsigned index) const 106 { 107 if (!m_impl || index >= m_impl->length()) 108 return 0; 109 return m_impl->characters()[index]; 110 } 106 111 107 112 double toDouble(bool tolerateTrailingJunk, bool tolerateEmptyString) const; … … 112 117 uint32_t toUInt32(bool* ok, bool tolerateEmptyString) const; 113 118 uint32_t toStrictUInt32(bool* ok = 0) const; 119 120 unsigned toArrayIndex(bool* ok = 0) const; 114 121 115 122 static const unsigned NotFound = 0xFFFFFFFFu; … … 121 128 UString substr(unsigned pos = 0, unsigned len = 0xFFFFFFFF) const; 122 129 123 // NOTE: This method should only be used for *debugging* purposes as it 124 // is neither Unicode safe nor free from side effects nor thread-safe. 125 char* ascii() const; 126 130 bool isNull() const { return !m_impl; } 131 bool isEmpty() const { return !m_impl || !m_impl->length(); } 132 133 StringImpl* impl() const { return m_impl.get(); } 134 135 size_t cost() const 136 { 137 if (!m_impl) 138 return 0; 139 return m_impl->cost(); 140 } 141 142 ALWAYS_INLINE ~UString() { } 127 143 private: 128 144 RefPtr<StringImpl> m_impl; … … 202 218 } 203 219 220 // Rule from ECMA 15.2 about what an array index is. 221 // Must exactly match string form of an unsigned integer, and be less than 2^32 - 1. 222 inline unsigned UString::toArrayIndex(bool* ok) const 223 { 224 unsigned i = toStrictUInt32(ok); 225 if (ok && i >= 0xFFFFFFFFU) 226 *ok = false; 227 return i; 228 } 229 204 230 // We'd rather not do shared substring append for small strings, since 205 231 // this runs too much risk of a tiny initial string holding down a
Note:
See TracChangeset
for help on using the changeset viewer.