Changeset 65295 in webkit for trunk/JavaScriptCore/runtime/UString.h
- Timestamp:
- Aug 12, 2010, 8:58:37 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/UString.h
r65289 r65295 39 39 namespace JSC { 40 40 41 using WTF::PlacementNewAdoptType;42 using WTF::PlacementNewAdopt;43 44 41 class UString { 45 42 public: … … 64 61 UString(RefPtr<StringImpl> impl) : m_impl(impl) { } 65 62 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 static UString number(int); 72 static UString number(long long); 73 static UString number(unsigned); 74 static UString number(long); 75 static UString number(double); 76 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; 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(); } 90 75 91 76 unsigned length() const … … 103 88 } 104 89 90 CString utf8(bool strict = false) const; 91 105 92 UChar operator[](unsigned index) const 106 93 { … … 110 97 } 111 98 99 static UString number(int); 100 static UString number(unsigned); 101 static UString number(long); 102 static UString number(long long); 103 static UString number(double); 104 105 106 112 107 double toDouble(bool tolerateTrailingJunk, bool tolerateEmptyString) const; 113 108 double toDouble(bool tolerateTrailingJunk) const; … … 117 112 uint32_t toUInt32(bool* ok, bool tolerateEmptyString) const; 118 113 uint32_t toStrictUInt32(bool* ok = 0) const; 119 120 unsigned toArrayIndex(bool* ok = 0) const;121 114 122 115 static const unsigned NotFound = 0xFFFFFFFFu; … … 128 121 UString substr(unsigned pos = 0, unsigned len = 0xFFFFFFFF) const; 129 122 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() { } 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 143 127 private: 144 128 RefPtr<StringImpl> m_impl; … … 218 202 } 219 203 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) const223 {224 unsigned i = toStrictUInt32(ok);225 if (ok && i >= 0xFFFFFFFFU)226 *ok = false;227 return i;228 }229 230 204 // We'd rather not do shared substring append for small strings, since 231 205 // this runs too much risk of a tiny initial string holding down a
Note:
See TracChangeset
for help on using the changeset viewer.