Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: third_party/WebKit/Source/core/editing/iterators/WordAwareIterator.cpp

Issue 2397033002: Reflow comments in //third_party/WebKit/Source/core/editing/iterators (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/editing/iterators/WordAwareIterator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
3 * rights reserved.
3 * Copyright (C) 2005 Alexey Proskuryakov. 4 * Copyright (C) 2005 Alexey Proskuryakov.
4 * 5 *
5 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
7 * are met: 8 * are met:
8 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
(...skipping 17 matching lines...) Expand all
30 31
31 WordAwareIterator::WordAwareIterator(const Position& start, const Position& end) 32 WordAwareIterator::WordAwareIterator(const Position& start, const Position& end)
32 // So we consider the first chunk from the text iterator. 33 // So we consider the first chunk from the text iterator.
33 : m_didLookAhead(true), 34 : m_didLookAhead(true),
34 m_textIterator(start, end) { 35 m_textIterator(start, end) {
35 advance(); // Get in position over the first chunk of text. 36 advance(); // Get in position over the first chunk of text.
36 } 37 }
37 38
38 WordAwareIterator::~WordAwareIterator() {} 39 WordAwareIterator::~WordAwareIterator() {}
39 40
40 // FIXME: Performance could be bad for huge spans next to each other that don't fall on word boundaries. 41 // FIXME: Performance could be bad for huge spans next to each other that don't
42 // fall on word boundaries.
41 43
42 void WordAwareIterator::advance() { 44 void WordAwareIterator::advance() {
43 m_buffer.clear(); 45 m_buffer.clear();
44 46
45 // If last time we did a look-ahead, start with that looked-ahead chunk now 47 // If last time we did a look-ahead, start with that looked-ahead chunk now
46 if (!m_didLookAhead) { 48 if (!m_didLookAhead) {
47 DCHECK(!m_textIterator.atEnd()); 49 DCHECK(!m_textIterator.atEnd());
48 m_textIterator.advance(); 50 m_textIterator.advance();
49 } 51 }
50 m_didLookAhead = false; 52 m_didLookAhead = false;
51 53
52 // Go to next non-empty chunk. 54 // Go to next non-empty chunk.
53 while (!m_textIterator.atEnd() && !m_textIterator.length()) 55 while (!m_textIterator.atEnd() && !m_textIterator.length())
54 m_textIterator.advance(); 56 m_textIterator.advance();
55 57
56 if (m_textIterator.atEnd()) 58 if (m_textIterator.atEnd())
57 return; 59 return;
58 60
59 while (1) { 61 while (1) {
60 // If this chunk ends in whitespace we can just use it as our chunk. 62 // If this chunk ends in whitespace we can just use it as our chunk.
61 if (isSpaceOrNewline( 63 if (isSpaceOrNewline(
62 m_textIterator.characterAt(m_textIterator.length() - 1))) 64 m_textIterator.characterAt(m_textIterator.length() - 1)))
63 return; 65 return;
64 66
65 // If this is the first chunk that failed, save it in m_buffer before look a head. 67 // If this is the first chunk that failed, save it in m_buffer before look
68 // ahead.
66 if (m_buffer.isEmpty()) 69 if (m_buffer.isEmpty())
67 m_textIterator.copyTextTo(&m_buffer); 70 m_textIterator.copyTextTo(&m_buffer);
68 71
69 // Look ahead to next chunk. If it is whitespace or a break, we can use the previous stuff 72 // Look ahead to next chunk. If it is whitespace or a break, we can use the
73 // previous stuff
70 m_textIterator.advance(); 74 m_textIterator.advance();
71 if (m_textIterator.atEnd() || !m_textIterator.length() || 75 if (m_textIterator.atEnd() || !m_textIterator.length() ||
72 isSpaceOrNewline(m_textIterator.text().characterAt(0))) { 76 isSpaceOrNewline(m_textIterator.text().characterAt(0))) {
73 m_didLookAhead = true; 77 m_didLookAhead = true;
74 return; 78 return;
75 } 79 }
76 80
77 // Start gobbling chunks until we get to a suitable stopping point 81 // Start gobbling chunks until we get to a suitable stopping point
78 m_textIterator.copyTextTo(&m_buffer); 82 m_textIterator.copyTextTo(&m_buffer);
79 } 83 }
(...skipping 11 matching lines...) Expand all
91 return m_textIterator.text().substring(position, length); 95 return m_textIterator.text().substring(position, length);
92 } 96 }
93 97
94 UChar WordAwareIterator::characterAt(unsigned index) const { 98 UChar WordAwareIterator::characterAt(unsigned index) const {
95 if (!m_buffer.isEmpty()) 99 if (!m_buffer.isEmpty())
96 return m_buffer[index]; 100 return m_buffer[index];
97 return m_textIterator.text().characterAt(index); 101 return m_textIterator.text().characterAt(index);
98 } 102 }
99 103
100 } // namespace blink 104 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/iterators/WordAwareIterator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698