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

Side by Side Diff: third_party/WebKit/Source/platform/text/TextBreakIterator.h

Issue 2811453002: Replace ASSERT, ASSERT_NOT_REACHED, and RELEASE_ASSERT in platform/text (Closed)
Patch Set: Replace ASSERT, ASSERT_NOT_REACHED, and RELEASE_ASSERT in platform/text Created 3 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006 Lars Knoll <lars@trolltech.com> 2 * Copyright (C) 2006 Lars Knoll <lars@trolltech.com>
3 * Copyright (C) 2007, 2011, 2012 Apple Inc. All rights reserved. 3 * Copyright (C) 2007, 2011, 2012 Apple Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 ++priorContextLength; 142 ++priorContextLength;
143 } 143 }
144 return priorContextLength; 144 return priorContextLength;
145 } 145 }
146 146
147 // Obtain text break iterator, possibly previously cached, where this iterator 147 // Obtain text break iterator, possibly previously cached, where this iterator
148 // is (or has been) initialized to use the previously stored string as the 148 // is (or has been) initialized to use the previously stored string as the
149 // primary breaking context and using previously stored prior context if 149 // primary breaking context and using previously stored prior context if
150 // non-empty. 150 // non-empty.
151 TextBreakIterator* get(unsigned priorContextLength) { 151 TextBreakIterator* get(unsigned priorContextLength) {
152 ASSERT(priorContextLength <= priorContextCapacity); 152 DCHECK(priorContextLength <= priorContextCapacity);
tkent 2017/04/09 23:07:01 Use DCHECK_LE if it doesn't cause a compile failur
Hwanseung Lee 2017/04/11 03:29:38 it was cause compile failure.
153 const UChar* priorContext = 153 const UChar* priorContext =
154 priorContextLength 154 priorContextLength
155 ? &m_priorContext[priorContextCapacity - priorContextLength] 155 ? &m_priorContext[priorContextCapacity - priorContextLength]
156 : 0; 156 : 0;
157 if (!m_iterator) { 157 if (!m_iterator) {
158 if (m_string.is8Bit()) 158 if (m_string.is8Bit())
159 m_iterator = acquireLineBreakIterator(m_string.characters8(), 159 m_iterator = acquireLineBreakIterator(m_string.characters8(),
160 m_string.length(), m_locale, 160 m_string.length(), m_locale,
161 priorContext, priorContextLength); 161 priorContext, priorContextLength);
162 else 162 else
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 bool isBreak(int offset) const; 237 bool isBreak(int offset) const;
238 int preceding(int offset) const; 238 int preceding(int offset) const;
239 int following(int offset) const; 239 int following(int offset) const;
240 240
241 bool operator!() const { return !m_is8Bit && !m_iterator; } 241 bool operator!() const { return !m_is8Bit && !m_iterator; }
242 242
243 private: 243 private:
244 void createIteratorForBuffer(const UChar*, unsigned length); 244 void createIteratorForBuffer(const UChar*, unsigned length);
245 245
246 unsigned clusterLengthStartingAt(unsigned offset) const { 246 unsigned clusterLengthStartingAt(unsigned offset) const {
247 ASSERT(m_is8Bit); 247 DCHECK(m_is8Bit);
248 // The only Latin-1 Extended Grapheme Cluster is CR LF 248 // The only Latin-1 Extended Grapheme Cluster is CR LF
249 return isCRBeforeLF(offset) ? 2 : 1; 249 return isCRBeforeLF(offset) ? 2 : 1;
250 } 250 }
251 251
252 bool isCRBeforeLF(unsigned offset) const { 252 bool isCRBeforeLF(unsigned offset) const {
253 ASSERT(m_is8Bit); 253 DCHECK(m_is8Bit);
254 return m_charaters8[offset] == '\r' && offset + 1 < m_length && 254 return m_charaters8[offset] == '\r' && offset + 1 < m_length &&
255 m_charaters8[offset + 1] == '\n'; 255 m_charaters8[offset + 1] == '\n';
256 } 256 }
257 257
258 bool isLFAfterCR(unsigned offset) const { 258 bool isLFAfterCR(unsigned offset) const {
259 ASSERT(m_is8Bit); 259 DCHECK(m_is8Bit);
260 return m_charaters8[offset] == '\n' && offset >= 1 && 260 return m_charaters8[offset] == '\n' && offset >= 1 &&
261 m_charaters8[offset - 1] == '\r'; 261 m_charaters8[offset - 1] == '\r';
262 } 262 }
263 263
264 bool m_is8Bit; 264 bool m_is8Bit;
265 265
266 // For 8 bit strings, we implement the iterator ourselves. 266 // For 8 bit strings, we implement the iterator ourselves.
267 const LChar* m_charaters8; 267 const LChar* m_charaters8;
268 unsigned m_offset; 268 unsigned m_offset;
269 unsigned m_length; 269 unsigned m_length;
270 270
271 // For 16 bit strings, we use a TextBreakIterator. 271 // For 16 bit strings, we use a TextBreakIterator.
272 TextBreakIterator* m_iterator; 272 TextBreakIterator* m_iterator;
273 }; 273 };
274 274
275 // Counts the number of grapheme clusters. A surrogate pair or a sequence 275 // Counts the number of grapheme clusters. A surrogate pair or a sequence
276 // of a non-combining character and following combining characters is 276 // of a non-combining character and following combining characters is
277 // counted as 1 grapheme cluster. 277 // counted as 1 grapheme cluster.
278 PLATFORM_EXPORT unsigned numGraphemeClusters(const String&); 278 PLATFORM_EXPORT unsigned numGraphemeClusters(const String&);
279 279
280 } // namespace blink 280 } // namespace blink
281 281
282 #endif 282 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698