| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r
ights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r
ights reserved. |
| 3 * Copyright (C) 2005 Alexey Proskuryakov. | 3 * Copyright (C) 2005 Alexey Proskuryakov. |
| 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 1831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1842 m_offset += runLength; | 1842 m_offset += runLength; |
| 1843 } | 1843 } |
| 1844 } | 1844 } |
| 1845 | 1845 |
| 1846 m_atBreak = true; | 1846 m_atBreak = true; |
| 1847 m_runOffset = 0; | 1847 m_runOffset = 0; |
| 1848 } | 1848 } |
| 1849 | 1849 |
| 1850 // -------- | 1850 // -------- |
| 1851 | 1851 |
| 1852 WordAwareIterator::WordAwareIterator(const Range* range) | 1852 WordAwareIterator::WordAwareIterator(const Position& start, const Position& end) |
| 1853 : m_didLookAhead(true) // So we consider the first chunk from the text itera
tor. | 1853 : m_didLookAhead(true) // So we consider the first chunk from the text itera
tor. |
| 1854 , m_textIterator(range) | 1854 , m_textIterator(start, end) |
| 1855 { | 1855 { |
| 1856 advance(); // Get in position over the first chunk of text. | 1856 advance(); // Get in position over the first chunk of text. |
| 1857 } | 1857 } |
| 1858 | 1858 |
| 1859 WordAwareIterator::~WordAwareIterator() | 1859 WordAwareIterator::~WordAwareIterator() |
| 1860 { | 1860 { |
| 1861 } | 1861 } |
| 1862 | 1862 |
| 1863 // FIXME: Performance could be bad for huge spans next to each other that don't
fall on word boundaries. | 1863 // FIXME: Performance could be bad for huge spans next to each other that don't
fall on word boundaries. |
| 1864 | 1864 |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2235 int length = 0; | 2235 int length = 0; |
| 2236 TextIteratorBehaviorFlags behaviorFlags = TextIteratorEmitsObjectReplacement
Character; | 2236 TextIteratorBehaviorFlags behaviorFlags = TextIteratorEmitsObjectReplacement
Character; |
| 2237 if (forSelectionPreservation) | 2237 if (forSelectionPreservation) |
| 2238 behaviorFlags |= TextIteratorEmitsCharactersBetweenAllVisiblePositions; | 2238 behaviorFlags |= TextIteratorEmitsCharactersBetweenAllVisiblePositions; |
| 2239 for (TextIterator it(r, behaviorFlags); !it.atEnd(); it.advance()) | 2239 for (TextIterator it(r, behaviorFlags); !it.atEnd(); it.advance()) |
| 2240 length += it.length(); | 2240 length += it.length(); |
| 2241 | 2241 |
| 2242 return length; | 2242 return length; |
| 2243 } | 2243 } |
| 2244 | 2244 |
| 2245 int TextIterator::rangeLength(const Position& start, const Position& end, bool f
orSelectionPreservation) |
| 2246 { |
| 2247 int length = 0; |
| 2248 TextIteratorBehaviorFlags behaviorFlags = TextIteratorEmitsObjectReplacement
Character; |
| 2249 if (forSelectionPreservation) |
| 2250 behaviorFlags |= TextIteratorEmitsCharactersBetweenAllVisiblePositions; |
| 2251 for (TextIterator it(start, end, behaviorFlags); !it.atEnd(); it.advance()) |
| 2252 length += it.length(); |
| 2253 |
| 2254 return length; |
| 2255 } |
| 2256 |
| 2245 PassRefPtrWillBeRawPtr<Range> TextIterator::subrange(Range* entireRange, int cha
racterOffset, int characterCount) | 2257 PassRefPtrWillBeRawPtr<Range> TextIterator::subrange(Range* entireRange, int cha
racterOffset, int characterCount) |
| 2246 { | 2258 { |
| 2247 CharacterIterator entireRangeIterator(entireRange); | 2259 CharacterIterator entireRangeIterator(entireRange); |
| 2248 Position start; | 2260 Position start; |
| 2249 Position end; | 2261 Position end; |
| 2250 calculateCharacterSubrange(entireRangeIterator, characterOffset, characterCo
unt, start, end); | 2262 calculateCharacterSubrange(entireRangeIterator, characterOffset, characterCo
unt, start, end); |
| 2251 return Range::create(entireRange->ownerDocument(), start, end); | 2263 return Range::create(entireRange->ownerDocument(), start, end); |
| 2252 } | 2264 } |
| 2253 | 2265 |
| 2266 void TextIterator::subrange(Position& start, Position& end, int characterOffset,
int characterCount) |
| 2267 { |
| 2268 CharacterIterator entireRangeIterator(start, end); |
| 2269 calculateCharacterSubrange(entireRangeIterator, characterOffset, characterCo
unt, start, end); |
| 2270 } |
| 2271 |
| 2254 // -------- | 2272 // -------- |
| 2255 | 2273 |
| 2256 String plainText(const Range* r, TextIteratorBehaviorFlags behavior) | 2274 static String createPlainText(TextIterator& it) |
| 2257 { | 2275 { |
| 2258 // The initial buffer size can be critical for performance: https://bugs.web
kit.org/show_bug.cgi?id=81192 | 2276 // The initial buffer size can be critical for performance: https://bugs.web
kit.org/show_bug.cgi?id=81192 |
| 2259 static const unsigned initialCapacity = 1 << 15; | 2277 static const unsigned initialCapacity = 1 << 15; |
| 2260 | 2278 |
| 2261 unsigned bufferLength = 0; | 2279 unsigned bufferLength = 0; |
| 2262 StringBuilder builder; | 2280 StringBuilder builder; |
| 2263 builder.reserveCapacity(initialCapacity); | 2281 builder.reserveCapacity(initialCapacity); |
| 2264 | 2282 |
| 2265 for (TextIterator it(r, behavior); !it.atEnd(); it.advance()) { | 2283 for (; !it.atEnd(); it.advance()) { |
| 2266 it.appendTextToStringBuilder(builder); | 2284 it.appendTextToStringBuilder(builder); |
| 2267 bufferLength += it.length(); | 2285 bufferLength += it.length(); |
| 2268 } | 2286 } |
| 2269 | 2287 |
| 2270 if (!bufferLength) | 2288 if (!bufferLength) |
| 2271 return emptyString(); | 2289 return emptyString(); |
| 2272 | 2290 |
| 2273 return builder.toString(); | 2291 return builder.toString(); |
| 2274 } | 2292 } |
| 2275 | 2293 |
| 2294 String plainText(const Range* r, TextIteratorBehaviorFlags behavior) |
| 2295 { |
| 2296 TextIterator it(r, behavior); |
| 2297 return createPlainText(it); |
| 2298 } |
| 2299 |
| 2300 String plainText(const Position& start, const Position& end, TextIteratorBehavio
rFlags behavior) |
| 2301 { |
| 2302 TextIterator it(start, end, behavior); |
| 2303 return createPlainText(it); |
| 2304 } |
| 2305 |
| 2276 static PassRefPtrWillBeRawPtr<Range> collapsedToBoundary(const Range* range, boo
l forward) | 2306 static PassRefPtrWillBeRawPtr<Range> collapsedToBoundary(const Range* range, boo
l forward) |
| 2277 { | 2307 { |
| 2278 RefPtrWillBeRawPtr<Range> result = range->cloneRange(); | 2308 RefPtrWillBeRawPtr<Range> result = range->cloneRange(); |
| 2279 result->collapse(!forward); | 2309 result->collapse(!forward); |
| 2280 return result.release(); | 2310 return result.release(); |
| 2281 } | 2311 } |
| 2282 | 2312 |
| 2283 // Check if there's any unpaird surrogate code point. | 2313 // Check if there's any unpaird surrogate code point. |
| 2284 // Non-character code points are not checked. | 2314 // Non-character code points are not checked. |
| 2285 static bool isValidUTF16(const String& s) | 2315 static bool isValidUTF16(const String& s) |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2389 resultEnd = collapseTo; | 2419 resultEnd = collapseTo; |
| 2390 return; | 2420 return; |
| 2391 } | 2421 } |
| 2392 } | 2422 } |
| 2393 | 2423 |
| 2394 CharacterIterator computeRangeIterator(inputStart, inputEnd, iteratorFlagsFo
rFindPlainText); | 2424 CharacterIterator computeRangeIterator(inputStart, inputEnd, iteratorFlagsFo
rFindPlainText); |
| 2395 calculateCharacterSubrange(computeRangeIterator, matchStart, matchLength, re
sultStart, resultEnd); | 2425 calculateCharacterSubrange(computeRangeIterator, matchStart, matchLength, re
sultStart, resultEnd); |
| 2396 } | 2426 } |
| 2397 | 2427 |
| 2398 } | 2428 } |
| OLD | NEW |