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

Side by Side Diff: third_party/WebKit/Source/platform/text/SegmentedString.cpp

Issue 2127043002: SegmentedString::prepend should know if the prepended string is new or previously consumed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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/platform/text/SegmentedString.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 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 ASSERT(c); 80 ASSERT(c);
81 81
82 // pushIfPossible attempts to rewind the pointer in the SegmentedSubstring, 82 // pushIfPossible attempts to rewind the pointer in the SegmentedSubstring,
83 // however it will fail if the SegmentedSubstring is empty, or 83 // however it will fail if the SegmentedSubstring is empty, or
84 // when we prepended some text while consuming a SegmentedSubstring by docum ent.write(). 84 // when we prepended some text while consuming a SegmentedSubstring by docum ent.write().
85 if (m_currentString.pushIfPossible(c)) { 85 if (m_currentString.pushIfPossible(c)) {
86 m_currentChar = c; 86 m_currentChar = c;
87 return; 87 return;
88 } 88 }
89 89
90 prepend(SegmentedString(String(&c, 1))); 90 prepend(SegmentedString(String(&c, 1)), PrependType::Unconsume);
91 } 91 }
92 92
93 void SegmentedString::prepend(const SegmentedSubstring& s) 93 void SegmentedString::prepend(const SegmentedSubstring& s, PrependType type)
94 { 94 {
95 ASSERT(!s.numberOfCharactersConsumed()); 95 ASSERT(!s.numberOfCharactersConsumed());
96 if (!s.length()) 96 if (!s.length())
97 return; 97 return;
98 98
99 // FIXME: We're assuming that the prepend were originally consumed by 99 // FIXME: We're also ASSERTing that s is a fresh SegmentedSubstring.
100 // this SegmentedString. We're also ASSERTing that s is a fresh 100 // The assumption is sufficient for our current use, but we might
101 // SegmentedSubstring. These assumptions are sufficient for our 101 // need to handle the more elaborate cases in the future.
102 // current use, but we might need to handle the more elaborate
103 // cases in the future.
104 m_numberOfCharactersConsumedPriorToCurrentString += m_currentString.numberOf CharactersConsumed(); 102 m_numberOfCharactersConsumedPriorToCurrentString += m_currentString.numberOf CharactersConsumed();
105 m_numberOfCharactersConsumedPriorToCurrentString -= s.length(); 103 if (type == PrependType::Unconsume)
104 m_numberOfCharactersConsumedPriorToCurrentString -= s.length();
106 if (!m_currentString.length()) { 105 if (!m_currentString.length()) {
107 m_currentString = s; 106 m_currentString = s;
108 updateAdvanceFunctionPointers(); 107 updateAdvanceFunctionPointers();
109 } else { 108 } else {
110 // Shift our m_currentString into our list. 109 // Shift our m_currentString into our list.
111 m_substrings.prepend(m_currentString); 110 m_substrings.prepend(m_currentString);
112 m_currentString = s; 111 m_currentString = s;
113 updateAdvanceFunctionPointers(); 112 updateAdvanceFunctionPointers();
114 } 113 }
115 m_empty = false; 114 m_empty = false;
(...skipping 13 matching lines...) Expand all
129 append(s.m_currentString); 128 append(s.m_currentString);
130 if (s.isComposite()) { 129 if (s.isComposite()) {
131 Deque<SegmentedSubstring>::const_iterator it = s.m_substrings.begin(); 130 Deque<SegmentedSubstring>::const_iterator it = s.m_substrings.begin();
132 Deque<SegmentedSubstring>::const_iterator e = s.m_substrings.end(); 131 Deque<SegmentedSubstring>::const_iterator e = s.m_substrings.end();
133 for (; it != e; ++it) 132 for (; it != e; ++it)
134 append(*it); 133 append(*it);
135 } 134 }
136 m_currentChar = m_currentString.length() ? m_currentString.getCurrentChar() : 0; 135 m_currentChar = m_currentString.length() ? m_currentString.getCurrentChar() : 0;
137 } 136 }
138 137
139 void SegmentedString::prepend(const SegmentedString& s) 138 void SegmentedString::prepend(const SegmentedString& s, PrependType type)
140 { 139 {
141 if (s.isComposite()) { 140 if (s.isComposite()) {
142 Deque<SegmentedSubstring>::const_reverse_iterator it = s.m_substrings.rb egin(); 141 Deque<SegmentedSubstring>::const_reverse_iterator it = s.m_substrings.rb egin();
143 Deque<SegmentedSubstring>::const_reverse_iterator e = s.m_substrings.ren d(); 142 Deque<SegmentedSubstring>::const_reverse_iterator e = s.m_substrings.ren d();
144 for (; it != e; ++it) 143 for (; it != e; ++it)
145 prepend(*it); 144 prepend(*it, type);
146 } 145 }
147 prepend(s.m_currentString); 146 prepend(s.m_currentString, type);
148 m_currentChar = m_currentString.length() ? m_currentString.getCurrentChar() : 0; 147 m_currentChar = m_currentString.length() ? m_currentString.getCurrentChar() : 0;
149 } 148 }
150 149
151 void SegmentedString::advanceSubstring() 150 void SegmentedString::advanceSubstring()
152 { 151 {
153 if (isComposite()) { 152 if (isComposite()) {
154 m_numberOfCharactersConsumedPriorToCurrentString += m_currentString.numb erOfCharactersConsumed(); 153 m_numberOfCharactersConsumedPriorToCurrentString += m_currentString.numb erOfCharactersConsumed();
155 m_currentString = m_substrings.takeFirst(); 154 m_currentString = m_substrings.takeFirst();
156 // If we've previously consumed some characters of the non-current 155 // If we've previously consumed some characters of the non-current
157 // string, we now account for those characters as part of the current 156 // string, we now account for those characters as part of the current
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 return OrdinalNumber::fromZeroBasedInt(zeroBasedColumn); 286 return OrdinalNumber::fromZeroBasedInt(zeroBasedColumn);
288 } 287 }
289 288
290 void SegmentedString::setCurrentPosition(OrdinalNumber line, OrdinalNumber colum nAftreProlog, int prologLength) 289 void SegmentedString::setCurrentPosition(OrdinalNumber line, OrdinalNumber colum nAftreProlog, int prologLength)
291 { 290 {
292 m_currentLine = line.zeroBasedInt(); 291 m_currentLine = line.zeroBasedInt();
293 m_numberOfCharactersConsumedPriorToCurrentLine = numberOfCharactersConsumed( ) + prologLength - columnAftreProlog.zeroBasedInt(); 292 m_numberOfCharactersConsumedPriorToCurrentLine = numberOfCharactersConsumed( ) + prologLength - columnAftreProlog.zeroBasedInt();
294 } 293 }
295 294
296 } // namespace blink 295 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/text/SegmentedString.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698