| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Google Inc. All rights reserved. | 3 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| 11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
| 13 * | 13 * |
| 14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #ifndef StringBuilder_h | 27 #ifndef StringBuilder_h |
| 28 #define StringBuilder_h | 28 #define StringBuilder_h |
| 29 | 29 |
| 30 #include "wtf/WTFExport.h" | 30 #include "wtf/WTFExport.h" |
| 31 #include "wtf/text/AtomicString.h" | 31 #include "wtf/text/AtomicString.h" |
| 32 #include "wtf/text/WTFString.h" | 32 #include "wtf/text/WTFString.h" |
| 33 | 33 |
| 34 namespace WTF { | 34 namespace WTF { |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 189 |
| 190 AtomicString toAtomicString() const | 190 AtomicString toAtomicString() const |
| 191 { | 191 { |
| 192 if (!m_length) | 192 if (!m_length) |
| 193 return emptyAtom; | 193 return emptyAtom; |
| 194 | 194 |
| 195 // If the buffer is sufficiently over-allocated, make a new AtomicString
from a copy so its buffer is not so large. | 195 // If the buffer is sufficiently over-allocated, make a new AtomicString
from a copy so its buffer is not so large. |
| 196 if (canShrink()) { | 196 if (canShrink()) { |
| 197 if (is8Bit()) | 197 if (is8Bit()) |
| 198 return AtomicString(characters8(), length()); | 198 return AtomicString(characters8(), length()); |
| 199 return AtomicString(characters16(), length()); | 199 return AtomicString(characters16(), length()); |
| 200 } | 200 } |
| 201 | 201 |
| 202 if (!m_string.isNull()) | 202 if (!m_string.isNull()) |
| 203 return AtomicString(m_string); | 203 return AtomicString(m_string); |
| 204 | 204 |
| 205 ASSERT(m_buffer); | 205 ASSERT(m_buffer); |
| 206 return AtomicString(m_buffer.get(), 0, m_length); | 206 return AtomicString(m_buffer.get(), 0, m_length); |
| 207 } | 207 } |
| 208 | 208 |
| 209 unsigned length() const | 209 unsigned length() const |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 const UChar* characters16() const | 248 const UChar* characters16() const |
| 249 { | 249 { |
| 250 ASSERT(!m_is8Bit); | 250 ASSERT(!m_is8Bit); |
| 251 if (!m_length) | 251 if (!m_length) |
| 252 return 0; | 252 return 0; |
| 253 if (!m_string.isNull()) | 253 if (!m_string.isNull()) |
| 254 return m_string.characters16(); | 254 return m_string.characters16(); |
| 255 ASSERT(m_buffer); | 255 ASSERT(m_buffer); |
| 256 return m_buffer->characters16(); | 256 return m_buffer->characters16(); |
| 257 } | 257 } |
| 258 | 258 |
| 259 bool is8Bit() const { return m_is8Bit; } | 259 bool is8Bit() const { return m_is8Bit; } |
| 260 | 260 |
| 261 void clear() | 261 void clear() |
| 262 { | 262 { |
| 263 m_length = 0; | 263 m_length = 0; |
| 264 m_string = String(); | 264 m_string = String(); |
| 265 m_buffer = 0; | 265 m_buffer = 0; |
| 266 m_bufferCharacters8 = 0; | 266 m_bufferCharacters8 = 0; |
| 267 m_is8Bit = true; | 267 m_is8Bit = true; |
| 268 } | 268 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 { | 306 { |
| 307 ASSERT(m_is8Bit); | 307 ASSERT(m_is8Bit); |
| 308 return m_bufferCharacters8; | 308 return m_bufferCharacters8; |
| 309 } | 309 } |
| 310 | 310 |
| 311 template <> | 311 template <> |
| 312 ALWAYS_INLINE UChar* StringBuilder::getBufferCharacters<UChar>() | 312 ALWAYS_INLINE UChar* StringBuilder::getBufferCharacters<UChar>() |
| 313 { | 313 { |
| 314 ASSERT(!m_is8Bit); | 314 ASSERT(!m_is8Bit); |
| 315 return m_bufferCharacters16; | 315 return m_bufferCharacters16; |
| 316 } | 316 } |
| 317 | 317 |
| 318 template <typename CharType> | 318 template <typename CharType> |
| 319 bool equal(const StringBuilder& s, const CharType* buffer, unsigned length) | 319 bool equal(const StringBuilder& s, const CharType* buffer, unsigned length) |
| 320 { | 320 { |
| 321 if (s.length() != length) | 321 if (s.length() != length) |
| 322 return false; | 322 return false; |
| 323 | 323 |
| 324 if (s.is8Bit()) | 324 if (s.is8Bit()) |
| 325 return equal(s.characters8(), buffer, length); | 325 return equal(s.characters8(), buffer, length); |
| 326 | 326 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 inline bool operator==(const StringBuilder& a, const String& b) { return equal(a
, b); } | 389 inline bool operator==(const StringBuilder& a, const String& b) { return equal(a
, b); } |
| 390 inline bool operator!=(const StringBuilder& a, const String& b) { return !equal(
a, b); } | 390 inline bool operator!=(const StringBuilder& a, const String& b) { return !equal(
a, b); } |
| 391 inline bool operator==(const String& a, const StringBuilder& b) { return equal(b
, a); } | 391 inline bool operator==(const String& a, const StringBuilder& b) { return equal(b
, a); } |
| 392 inline bool operator!=(const String& a, const StringBuilder& b) { return !equal(
b, a); } | 392 inline bool operator!=(const String& a, const StringBuilder& b) { return !equal(
b, a); } |
| 393 | 393 |
| 394 } // namespace WTF | 394 } // namespace WTF |
| 395 | 395 |
| 396 using WTF::StringBuilder; | 396 using WTF::StringBuilder; |
| 397 | 397 |
| 398 #endif // StringBuilder_h | 398 #endif // StringBuilder_h |
| OLD | NEW |