OLD | NEW |
1 /* | 1 /* |
2 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
3 | 3 |
4 This library is free software; you can redistribute it and/or | 4 This library is free software; you can redistribute it and/or |
5 modify it under the terms of the GNU Library General Public | 5 modify it under the terms of the GNU Library General Public |
6 License as published by the Free Software Foundation; either | 6 License as published by the Free Software Foundation; either |
7 version 2 of the License, or (at your option) any later version. | 7 version 2 of the License, or (at your option) any later version. |
8 | 8 |
9 This library is distributed in the hope that it will be useful, | 9 This library is distributed in the hope that it will be useful, |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } | 118 } |
119 | 119 |
120 ALWAYS_INLINE UChar incrementAndGetCurrentChar() | 120 ALWAYS_INLINE UChar incrementAndGetCurrentChar() |
121 { | 121 { |
122 ASSERT(m_length); | 122 ASSERT(m_length); |
123 if (is8Bit()) | 123 if (is8Bit()) |
124 return incrementAndGetCurrentChar8(); | 124 return incrementAndGetCurrentChar8(); |
125 return incrementAndGetCurrentChar16(); | 125 return incrementAndGetCurrentChar16(); |
126 } | 126 } |
127 | 127 |
128 public: | 128 ALWAYS_INLINE bool haveOneCharacterLeft() const |
| 129 { |
| 130 return m_length == 1; |
| 131 } |
| 132 |
| 133 ALWAYS_INLINE void decrementLength() { --m_length; } |
| 134 |
| 135 ALWAYS_INLINE int length() const { return m_length; } |
| 136 |
| 137 private: |
129 union { | 138 union { |
130 const LChar* string8Ptr; | 139 const LChar* string8Ptr; |
131 const UChar* string16Ptr; | 140 const UChar* string16Ptr; |
132 } m_data; | 141 } m_data; |
133 int m_length; | 142 int m_length; |
134 | |
135 private: | |
136 bool m_doNotExcludeLineNumbers; | 143 bool m_doNotExcludeLineNumbers; |
137 bool m_is8Bit; | 144 bool m_is8Bit; |
138 String m_string; | 145 String m_string; |
139 }; | 146 }; |
140 | 147 |
141 class PLATFORM_EXPORT SegmentedString { | 148 class PLATFORM_EXPORT SegmentedString { |
142 public: | 149 public: |
143 SegmentedString() | 150 SegmentedString() |
144 : m_pushedChar1(0) | 151 : m_pushedChar1(0) |
145 , m_pushedChar2(0) | 152 , m_pushedChar2(0) |
(...skipping 14 matching lines...) Expand all Loading... |
160 , m_pushedChar2(0) | 167 , m_pushedChar2(0) |
161 , m_currentString(str) | 168 , m_currentString(str) |
162 , m_currentChar(0) | 169 , m_currentChar(0) |
163 , m_numberOfCharactersConsumedPriorToCurrentString(0) | 170 , m_numberOfCharactersConsumedPriorToCurrentString(0) |
164 , m_numberOfCharactersConsumedPriorToCurrentLine(0) | 171 , m_numberOfCharactersConsumedPriorToCurrentLine(0) |
165 , m_currentLine(0) | 172 , m_currentLine(0) |
166 , m_closed(false) | 173 , m_closed(false) |
167 , m_empty(!str.length()) | 174 , m_empty(!str.length()) |
168 , m_fastPathFlags(NoFastPath) | 175 , m_fastPathFlags(NoFastPath) |
169 { | 176 { |
170 if (m_currentString.m_length) | 177 if (m_currentString.length()) |
171 m_currentChar = m_currentString.getCurrentChar(); | 178 m_currentChar = m_currentString.getCurrentChar(); |
172 updateAdvanceFunctionPointers(); | 179 updateAdvanceFunctionPointers(); |
173 } | 180 } |
174 | 181 |
175 void clear(); | 182 void clear(); |
176 void close(); | 183 void close(); |
177 | 184 |
178 void append(const SegmentedString&); | 185 void append(const SegmentedString&); |
179 void prepend(const SegmentedString&); | 186 void prepend(const SegmentedString&); |
180 | 187 |
(...skipping 23 matching lines...) Expand all Loading... |
204 NotEnoughCharacters, | 211 NotEnoughCharacters, |
205 }; | 212 }; |
206 | 213 |
207 LookAheadResult lookAhead(const String& string) { return lookAheadInline(str
ing, TextCaseSensitive); } | 214 LookAheadResult lookAhead(const String& string) { return lookAheadInline(str
ing, TextCaseSensitive); } |
208 LookAheadResult lookAheadIgnoringCase(const String& string) { return lookAhe
adInline(string, TextCaseInsensitive); } | 215 LookAheadResult lookAheadIgnoringCase(const String& string) { return lookAhe
adInline(string, TextCaseInsensitive); } |
209 | 216 |
210 void advance() | 217 void advance() |
211 { | 218 { |
212 if (m_fastPathFlags & Use8BitAdvance) { | 219 if (m_fastPathFlags & Use8BitAdvance) { |
213 ASSERT(!m_pushedChar1); | 220 ASSERT(!m_pushedChar1); |
214 bool haveOneCharacterLeft = (--m_currentString.m_length == 1); | |
215 m_currentChar = m_currentString.incrementAndGetCurrentChar8(); | 221 m_currentChar = m_currentString.incrementAndGetCurrentChar8(); |
216 | 222 m_currentString.decrementLength(); |
217 if (!haveOneCharacterLeft) | 223 if (!m_currentString.haveOneCharacterLeft()) |
218 return; | 224 return; |
219 | 225 |
220 updateSlowCaseFunctionPointers(); | 226 updateSlowCaseFunctionPointers(); |
221 | 227 |
222 return; | 228 return; |
223 } | 229 } |
224 | 230 |
225 (this->*m_advanceFunc)(); | 231 (this->*m_advanceFunc)(); |
226 } | 232 } |
227 | 233 |
228 inline void advanceAndUpdateLineNumber() | 234 inline void advanceAndUpdateLineNumber() |
229 { | 235 { |
230 if (m_fastPathFlags & Use8BitAdvance) { | 236 if (m_fastPathFlags & Use8BitAdvance) { |
231 ASSERT(!m_pushedChar1); | 237 ASSERT(!m_pushedChar1); |
232 | 238 |
233 bool haveNewLine = (m_currentChar == '\n') & !!(m_fastPathFlags & Us
e8BitAdvanceAndUpdateLineNumbers); | 239 bool haveNewLine = (m_currentChar == '\n') & !!(m_fastPathFlags & Us
e8BitAdvanceAndUpdateLineNumbers); |
234 bool haveOneCharacterLeft = (--m_currentString.m_length == 1); | |
235 | |
236 m_currentChar = m_currentString.incrementAndGetCurrentChar8(); | 240 m_currentChar = m_currentString.incrementAndGetCurrentChar8(); |
237 | 241 m_currentString.decrementLength(); |
238 if (!(haveNewLine | haveOneCharacterLeft)) | 242 bool haveOneCharacterLeft = m_currentString.haveOneCharacterLeft(); |
239 return; | |
240 | 243 |
241 if (haveNewLine) { | 244 if (haveNewLine) { |
242 ++m_currentLine; | 245 ++m_currentLine; |
243 m_numberOfCharactersConsumedPriorToCurrentLine = m_numberOfChar
actersConsumedPriorToCurrentString + m_currentString.numberOfCharactersConsumed(
); | 246 m_numberOfCharactersConsumedPriorToCurrentLine = m_numberOfChar
actersConsumedPriorToCurrentString + m_currentString.numberOfCharactersConsumed(
); |
244 } | 247 } |
245 | 248 |
246 if (haveOneCharacterLeft) | 249 if (haveOneCharacterLeft) |
247 updateSlowCaseFunctionPointers(); | 250 updateSlowCaseFunctionPointers(); |
248 | 251 |
249 return; | 252 return; |
(...skipping 16 matching lines...) Expand all Loading... |
266 | 269 |
267 void advancePastNonNewline() | 270 void advancePastNonNewline() |
268 { | 271 { |
269 ASSERT(currentChar() != '\n'); | 272 ASSERT(currentChar() != '\n'); |
270 advance(); | 273 advance(); |
271 } | 274 } |
272 | 275 |
273 void advancePastNewlineAndUpdateLineNumber() | 276 void advancePastNewlineAndUpdateLineNumber() |
274 { | 277 { |
275 ASSERT(currentChar() == '\n'); | 278 ASSERT(currentChar() == '\n'); |
276 if (!m_pushedChar1 && m_currentString.m_length > 1) { | 279 if (!m_pushedChar1 && m_currentString.length() > 1) { |
277 int newLineFlag = m_currentString.doNotExcludeLineNumbers(); | 280 int newLineFlag = m_currentString.doNotExcludeLineNumbers(); |
278 m_currentLine += newLineFlag; | 281 m_currentLine += newLineFlag; |
279 if (newLineFlag) | 282 if (newLineFlag) |
280 m_numberOfCharactersConsumedPriorToCurrentLine = numberOfCharact
ersConsumed() + 1; | 283 m_numberOfCharactersConsumedPriorToCurrentLine = numberOfCharact
ersConsumed() + 1; |
281 decrementAndCheckLength(); | 284 decrementAndCheckLength(); |
282 m_currentChar = m_currentString.incrementAndGetCurrentChar(); | 285 m_currentChar = m_currentString.incrementAndGetCurrentChar(); |
283 return; | 286 return; |
284 } | 287 } |
285 advanceAndUpdateLineNumberSlowCase(); | 288 advanceAndUpdateLineNumberSlowCase(); |
286 } | 289 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 void advanceAndUpdateLineNumber16(); | 332 void advanceAndUpdateLineNumber16(); |
330 void advanceSlowCase(); | 333 void advanceSlowCase(); |
331 void advanceAndUpdateLineNumberSlowCase(); | 334 void advanceAndUpdateLineNumberSlowCase(); |
332 void advanceEmpty(); | 335 void advanceEmpty(); |
333 void advanceSubstring(); | 336 void advanceSubstring(); |
334 | 337 |
335 void updateSlowCaseFunctionPointers(); | 338 void updateSlowCaseFunctionPointers(); |
336 | 339 |
337 void decrementAndCheckLength() | 340 void decrementAndCheckLength() |
338 { | 341 { |
339 ASSERT(m_currentString.m_length > 1); | 342 ASSERT(m_currentString.length() > 1); |
340 if (--m_currentString.m_length == 1) | 343 m_currentString.decrementLength(); |
| 344 if (m_currentString.haveOneCharacterLeft()) |
341 updateSlowCaseFunctionPointers(); | 345 updateSlowCaseFunctionPointers(); |
342 } | 346 } |
343 | 347 |
344 void updateAdvanceFunctionPointers() | 348 void updateAdvanceFunctionPointers() |
345 { | 349 { |
346 if ((m_currentString.m_length > 1) && !m_pushedChar1) { | 350 if ((m_currentString.length() > 1) && !m_pushedChar1) { |
347 if (m_currentString.is8Bit()) { | 351 if (m_currentString.is8Bit()) { |
348 m_advanceFunc = &SegmentedString::advance8; | 352 m_advanceFunc = &SegmentedString::advance8; |
349 m_fastPathFlags = Use8BitAdvance; | 353 m_fastPathFlags = Use8BitAdvance; |
350 if (m_currentString.doNotExcludeLineNumbers()) { | 354 if (m_currentString.doNotExcludeLineNumbers()) { |
351 m_advanceAndUpdateLineNumberFunc = &SegmentedString::advance
AndUpdateLineNumber8; | 355 m_advanceAndUpdateLineNumberFunc = &SegmentedString::advance
AndUpdateLineNumber8; |
352 m_fastPathFlags |= Use8BitAdvanceAndUpdateLineNumbers; | 356 m_fastPathFlags |= Use8BitAdvanceAndUpdateLineNumbers; |
353 } else { | 357 } else { |
354 m_advanceAndUpdateLineNumberFunc = &SegmentedString::advance
8; | 358 m_advanceAndUpdateLineNumberFunc = &SegmentedString::advance
8; |
355 } | 359 } |
356 return; | 360 return; |
357 } | 361 } |
358 | 362 |
359 m_advanceFunc = &SegmentedString::advance16; | 363 m_advanceFunc = &SegmentedString::advance16; |
360 m_fastPathFlags = NoFastPath; | 364 m_fastPathFlags = NoFastPath; |
361 if (m_currentString.doNotExcludeLineNumbers()) | 365 if (m_currentString.doNotExcludeLineNumbers()) |
362 m_advanceAndUpdateLineNumberFunc = &SegmentedString::advanceAndU
pdateLineNumber16; | 366 m_advanceAndUpdateLineNumberFunc = &SegmentedString::advanceAndU
pdateLineNumber16; |
363 else | 367 else |
364 m_advanceAndUpdateLineNumberFunc = &SegmentedString::advance16; | 368 m_advanceAndUpdateLineNumberFunc = &SegmentedString::advance16; |
365 return; | 369 return; |
366 } | 370 } |
367 | 371 |
368 if (!m_currentString.m_length && !isComposite()) { | 372 if (!m_currentString.length() && !isComposite()) { |
369 m_advanceFunc = &SegmentedString::advanceEmpty; | 373 m_advanceFunc = &SegmentedString::advanceEmpty; |
370 m_fastPathFlags = NoFastPath; | 374 m_fastPathFlags = NoFastPath; |
371 m_advanceAndUpdateLineNumberFunc = &SegmentedString::advanceEmpty; | 375 m_advanceAndUpdateLineNumberFunc = &SegmentedString::advanceEmpty; |
372 } | 376 } |
373 | 377 |
374 updateSlowCaseFunctionPointers(); | 378 updateSlowCaseFunctionPointers(); |
375 } | 379 } |
376 | 380 |
377 inline LookAheadResult lookAheadInline(const String& string, TextCaseSensiti
vity caseSensitivity) | 381 inline LookAheadResult lookAheadInline(const String& string, TextCaseSensiti
vity caseSensitivity) |
378 { | 382 { |
379 if (!m_pushedChar1 && string.length() <= static_cast<unsigned>(m_current
String.m_length)) { | 383 if (!m_pushedChar1 && string.length() <= static_cast<unsigned>(m_current
String.length())) { |
380 String currentSubstring = m_currentString.currentSubString(string.le
ngth()); | 384 String currentSubstring = m_currentString.currentSubString(string.le
ngth()); |
381 if (currentSubstring.startsWith(string, caseSensitivity)) | 385 if (currentSubstring.startsWith(string, caseSensitivity)) |
382 return DidMatch; | 386 return DidMatch; |
383 return DidNotMatch; | 387 return DidNotMatch; |
384 } | 388 } |
385 return lookAheadSlowCase(string, caseSensitivity); | 389 return lookAheadSlowCase(string, caseSensitivity); |
386 } | 390 } |
387 | 391 |
388 LookAheadResult lookAheadSlowCase(const String& string, TextCaseSensitivity
caseSensitivity) | 392 LookAheadResult lookAheadSlowCase(const String& string, TextCaseSensitivity
caseSensitivity) |
389 { | 393 { |
(...skipping 23 matching lines...) Expand all Loading... |
413 bool m_closed; | 417 bool m_closed; |
414 bool m_empty; | 418 bool m_empty; |
415 unsigned char m_fastPathFlags; | 419 unsigned char m_fastPathFlags; |
416 void (SegmentedString::*m_advanceFunc)(); | 420 void (SegmentedString::*m_advanceFunc)(); |
417 void (SegmentedString::*m_advanceAndUpdateLineNumberFunc)(); | 421 void (SegmentedString::*m_advanceAndUpdateLineNumberFunc)(); |
418 }; | 422 }; |
419 | 423 |
420 } | 424 } |
421 | 425 |
422 #endif | 426 #endif |
OLD | NEW |