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 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 , m_length(0) | 43 , m_length(0) |
44 , m_is8Bit(true) | 44 , m_is8Bit(true) |
45 { | 45 { |
46 } | 46 } |
47 | 47 |
48 void append(const UChar*, unsigned); | 48 void append(const UChar*, unsigned); |
49 void append(const LChar*, unsigned); | 49 void append(const LChar*, unsigned); |
50 | 50 |
51 ALWAYS_INLINE void append(const char* characters, unsigned length) { append( reinterpret_cast<const LChar*>(characters), length); } | 51 ALWAYS_INLINE void append(const char* characters, unsigned length) { append( reinterpret_cast<const LChar*>(characters), length); } |
52 | 52 |
53 void append(const String& string) | |
54 { | |
55 if (!string.length()) | |
56 return; | |
57 | |
58 // If we're appending to an empty string, and there is not a buffer (res erveCapacity has not been called) | |
59 // then just retain the string. | |
60 if (!m_length && !m_buffer) { | |
esprehn
2016/05/26 20:59:08
I did actually remove this optimization, but I aud
| |
61 m_string = string; | |
62 m_length = string.length(); | |
63 m_is8Bit = m_string.is8Bit(); | |
64 return; | |
65 } | |
66 | |
67 if (string.is8Bit()) | |
68 append(string.characters8(), string.length()); | |
69 else | |
70 append(string.characters16(), string.length()); | |
71 } | |
72 | |
73 void append(const StringBuilder& other) | 53 void append(const StringBuilder& other) |
74 { | 54 { |
75 if (!other.m_length) | 55 if (!other.m_length) |
76 return; | 56 return; |
77 | 57 |
78 // If we're appending to an empty string, and there is not a buffer (res erveCapacity has not been called) | 58 // If we're appending to an empty string, and there is not a buffer (res erveCapacity has not been called) |
79 // then just retain the string. | 59 // then just retain the string. |
80 if (!m_length && !m_buffer && !other.m_string.isNull()) { | 60 if (!m_length && !m_buffer && !other.m_string.isNull()) { |
81 m_string = other.m_string; | 61 m_string = other.m_string; |
82 m_length = other.m_length; | 62 m_length = other.m_length; |
83 return; | 63 return; |
84 } | 64 } |
85 | 65 |
86 if (other.is8Bit()) | 66 if (other.is8Bit()) |
87 append(other.characters8(), other.m_length); | 67 append(other.characters8(), other.m_length); |
88 else | 68 else |
89 append(other.characters16(), other.m_length); | 69 append(other.characters16(), other.m_length); |
90 } | 70 } |
91 | 71 |
92 void append(const String& string, unsigned offset, unsigned length) | 72 // TODO(esprehn): This method is just duplicating what StringView itself |
73 // does. Remove it and replace callers with append(StringView(string, offset , length)). | |
74 void append(const StringView& string, unsigned offset, unsigned length) | |
93 { | 75 { |
94 if (!string.length()) | 76 if (!string.length()) |
95 return; | 77 return; |
96 | 78 |
97 unsigned extent = offset + length; | 79 unsigned extent = offset + length; |
98 if (extent < offset || extent > string.length()) | 80 if (extent < offset || extent > string.length()) |
99 return; | 81 return; |
100 | 82 |
101 if (string.is8Bit()) | 83 if (string.is8Bit()) |
102 append(string.characters8() + offset, length); | 84 append(string.characters8() + offset, length); |
103 else | 85 else |
104 append(string.characters16() + offset, length); | 86 append(string.characters16() + offset, length); |
105 } | 87 } |
106 | 88 |
107 void append(const StringView& string) | 89 void append(const StringView& string) |
108 { | 90 { |
109 if (!string.length()) | 91 if (!string.length()) |
110 return; | 92 return; |
111 | 93 |
112 if (string.is8Bit()) | 94 if (string.is8Bit()) |
113 append(string.characters8(), string.length()); | 95 append(string.characters8(), string.length()); |
114 else | 96 else |
115 append(string.characters16(), string.length()); | 97 append(string.characters16(), string.length()); |
116 } | 98 } |
117 | 99 |
118 void append(const char* characters) | |
119 { | |
120 if (characters) | |
121 append(characters, strlen(characters)); | |
122 } | |
123 | |
124 void append(UChar c) | 100 void append(UChar c) |
125 { | 101 { |
126 if (m_buffer && m_length < m_buffer->length() && m_string.isNull()) { | 102 if (m_buffer && m_length < m_buffer->length() && m_string.isNull()) { |
127 if (!m_is8Bit) { | 103 if (!m_is8Bit) { |
128 m_bufferCharacters16[m_length++] = c; | 104 m_bufferCharacters16[m_length++] = c; |
129 return; | 105 return; |
130 } | 106 } |
131 | 107 |
132 if (!(c & ~0xff)) { | 108 if (!(c & ~0xff)) { |
133 m_bufferCharacters8[m_length++] = static_cast<LChar>(c); | 109 m_bufferCharacters8[m_length++] = static_cast<LChar>(c); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 inline bool operator==(const StringBuilder& a, const String& b) { return equal(a , b); } | 370 inline bool operator==(const StringBuilder& a, const String& b) { return equal(a , b); } |
395 inline bool operator!=(const StringBuilder& a, const String& b) { return !equal( a, b); } | 371 inline bool operator!=(const StringBuilder& a, const String& b) { return !equal( a, b); } |
396 inline bool operator==(const String& a, const StringBuilder& b) { return equal(b , a); } | 372 inline bool operator==(const String& a, const StringBuilder& b) { return equal(b , a); } |
397 inline bool operator!=(const String& a, const StringBuilder& b) { return !equal( b, a); } | 373 inline bool operator!=(const String& a, const StringBuilder& b) { return !equal( b, a); } |
398 | 374 |
399 } // namespace WTF | 375 } // namespace WTF |
400 | 376 |
401 using WTF::StringBuilder; | 377 using WTF::StringBuilder; |
402 | 378 |
403 #endif // StringBuilder_h | 379 #endif // StringBuilder_h |
OLD | NEW |