OLD | NEW |
---|---|
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 icu::Locale(currentTextBreakLocaleID()), openStatus); | 76 icu::Locale(currentTextBreakLocaleID()), openStatus); |
77 } | 77 } |
78 | 78 |
79 if (U_FAILURE(openStatus)) { | 79 if (U_FAILURE(openStatus)) { |
80 DLOG(ERROR) << "icu::BreakIterator construction failed with status " | 80 DLOG(ERROR) << "icu::BreakIterator construction failed with status " |
81 << openStatus; | 81 << openStatus; |
82 return 0; | 82 return 0; |
83 } | 83 } |
84 } | 84 } |
85 | 85 |
86 ASSERT(!m_vendedIterators.contains(iterator)); | 86 DCHECK(!m_vendedIterators.contains(iterator)); |
87 m_vendedIterators.set(iterator, locale); | 87 m_vendedIterators.set(iterator, locale); |
88 return iterator; | 88 return iterator; |
89 } | 89 } |
90 | 90 |
91 void put(icu::BreakIterator* iterator) { | 91 void put(icu::BreakIterator* iterator) { |
92 DCHECK(m_vendedIterators.contains(iterator)); | 92 DCHECK(m_vendedIterators.contains(iterator)); |
93 | 93 |
94 if (m_pool.size() == capacity) { | 94 if (m_pool.size() == capacity) { |
95 delete (m_pool[0].second); | 95 delete (m_pool[0].second); |
96 m_pool.erase(0); | 96 m_pool.erase(0); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 void* extraNew = destination->pExtra; | 169 void* extraNew = destination->pExtra; |
170 int32_t flags = destination->flags; | 170 int32_t flags = destination->flags; |
171 int sizeToCopy = std::min(source->sizeOfStruct, destination->sizeOfStruct); | 171 int sizeToCopy = std::min(source->sizeOfStruct, destination->sizeOfStruct); |
172 memcpy(destination, source, sizeToCopy); | 172 memcpy(destination, source, sizeToCopy); |
173 destination->pExtra = extraNew; | 173 destination->pExtra = extraNew; |
174 destination->flags = flags; | 174 destination->flags = flags; |
175 memcpy(destination->pExtra, source->pExtra, extraSize); | 175 memcpy(destination->pExtra, source->pExtra, extraSize); |
176 textFixPointer(source, destination, destination->context); | 176 textFixPointer(source, destination, destination->context); |
177 textFixPointer(source, destination, destination->p); | 177 textFixPointer(source, destination, destination->p); |
178 textFixPointer(source, destination, destination->q); | 178 textFixPointer(source, destination, destination->q); |
179 ASSERT(!destination->r); | 179 DCHECK(!destination->r); |
180 const void* chunkContents = | 180 const void* chunkContents = |
181 static_cast<const void*>(destination->chunkContents); | 181 static_cast<const void*>(destination->chunkContents); |
182 textFixPointer(source, destination, chunkContents); | 182 textFixPointer(source, destination, chunkContents); |
183 destination->chunkContents = static_cast<const UChar*>(chunkContents); | 183 destination->chunkContents = static_cast<const UChar*>(chunkContents); |
184 return destination; | 184 return destination; |
185 } | 185 } |
186 | 186 |
187 static int32_t textExtract(UText*, | 187 static int32_t textExtract(UText*, |
188 int64_t, | 188 int64_t, |
189 int64_t, | 189 int64_t, |
190 UChar*, | 190 UChar*, |
191 int32_t, | 191 int32_t, |
192 UErrorCode* errorCode) { | 192 UErrorCode* errorCode) { |
193 // In the present context, this text provider is used only with ICU functions | 193 // In the present context, this text provider is used only with ICU functions |
194 // that do not perform an extract operation. | 194 // that do not perform an extract operation. |
195 ASSERT_NOT_REACHED(); | 195 NOTREACHED(); |
196 *errorCode = U_UNSUPPORTED_ERROR; | 196 *errorCode = U_UNSUPPORTED_ERROR; |
197 return 0; | 197 return 0; |
198 } | 198 } |
199 | 199 |
200 static void textClose(UText* text) { | 200 static void textClose(UText* text) { |
201 text->context = 0; | 201 text->context = 0; |
202 } | 202 } |
203 | 203 |
204 static inline TextContext textGetContext(const UText* text, | 204 static inline TextContext textGetContext(const UText* text, |
205 int64_t nativeIndex, | 205 int64_t nativeIndex, |
206 UBool forward) { | 206 UBool forward) { |
207 if (!text->b || nativeIndex > text->b) | 207 if (!text->b || nativeIndex > text->b) |
208 return PrimaryContext; | 208 return PrimaryContext; |
209 if (nativeIndex == text->b) | 209 if (nativeIndex == text->b) |
210 return forward ? PrimaryContext : PriorContext; | 210 return forward ? PrimaryContext : PriorContext; |
211 return PriorContext; | 211 return PriorContext; |
212 } | 212 } |
213 | 213 |
214 static inline TextContext textLatin1GetCurrentContext(const UText* text) { | 214 static inline TextContext textLatin1GetCurrentContext(const UText* text) { |
215 if (!text->chunkContents) | 215 if (!text->chunkContents) |
216 return NoContext; | 216 return NoContext; |
217 return text->chunkContents == text->pExtra ? PrimaryContext : PriorContext; | 217 return text->chunkContents == text->pExtra ? PrimaryContext : PriorContext; |
218 } | 218 } |
219 | 219 |
220 static void textLatin1MoveInPrimaryContext(UText* text, | 220 static void textLatin1MoveInPrimaryContext(UText* text, |
221 int64_t nativeIndex, | 221 int64_t nativeIndex, |
222 int64_t nativeLength, | 222 int64_t nativeLength, |
223 UBool forward) { | 223 UBool forward) { |
224 ASSERT(text->chunkContents == text->pExtra); | 224 DCHECK_EQ(text->chunkContents, text->pExtra); |
225 if (forward) { | 225 if (forward) { |
226 ASSERT(nativeIndex >= text->b && nativeIndex < nativeLength); | 226 DCHECK(nativeIndex >= text->b && nativeIndex < nativeLength); |
tkent
2017/04/09 23:07:02
Split this into two DCHECKs.
Hwanseung Lee
2017/04/11 03:29:38
Done.
| |
227 text->chunkNativeStart = nativeIndex; | 227 text->chunkNativeStart = nativeIndex; |
228 text->chunkNativeLimit = nativeIndex + text->extraSize / sizeof(UChar); | 228 text->chunkNativeLimit = nativeIndex + text->extraSize / sizeof(UChar); |
229 if (text->chunkNativeLimit > nativeLength) | 229 if (text->chunkNativeLimit > nativeLength) |
230 text->chunkNativeLimit = nativeLength; | 230 text->chunkNativeLimit = nativeLength; |
231 } else { | 231 } else { |
232 ASSERT(nativeIndex > text->b && nativeIndex <= nativeLength); | 232 DCHECK(nativeIndex > text->b && nativeIndex <= nativeLength); |
tkent
2017/04/09 23:07:02
Split this into two DCHECKs
Hwanseung Lee
2017/04/11 03:29:38
Done.
| |
233 text->chunkNativeLimit = nativeIndex; | 233 text->chunkNativeLimit = nativeIndex; |
234 text->chunkNativeStart = nativeIndex - text->extraSize / sizeof(UChar); | 234 text->chunkNativeStart = nativeIndex - text->extraSize / sizeof(UChar); |
235 if (text->chunkNativeStart < text->b) | 235 if (text->chunkNativeStart < text->b) |
236 text->chunkNativeStart = text->b; | 236 text->chunkNativeStart = text->b; |
237 } | 237 } |
238 int64_t length = text->chunkNativeLimit - text->chunkNativeStart; | 238 int64_t length = text->chunkNativeLimit - text->chunkNativeStart; |
239 // Ensure chunk length is well defined if computed length exceeds int32_t | 239 // Ensure chunk length is well defined if computed length exceeds int32_t |
240 // range. | 240 // range. |
241 ASSERT(length <= std::numeric_limits<int32_t>::max()); | 241 DCHECK_LE(length, std::numeric_limits<int32_t>::max()); |
242 text->chunkLength = length <= std::numeric_limits<int32_t>::max() | 242 text->chunkLength = length <= std::numeric_limits<int32_t>::max() |
243 ? static_cast<int32_t>(length) | 243 ? static_cast<int32_t>(length) |
244 : 0; | 244 : 0; |
245 text->nativeIndexingLimit = text->chunkLength; | 245 text->nativeIndexingLimit = text->chunkLength; |
246 text->chunkOffset = forward ? 0 : text->chunkLength; | 246 text->chunkOffset = forward ? 0 : text->chunkLength; |
247 StringImpl::copyChars( | 247 StringImpl::copyChars( |
248 const_cast<UChar*>(text->chunkContents), | 248 const_cast<UChar*>(text->chunkContents), |
249 static_cast<const LChar*>(text->p) + (text->chunkNativeStart - text->b), | 249 static_cast<const LChar*>(text->p) + (text->chunkNativeStart - text->b), |
250 static_cast<unsigned>(text->chunkLength)); | 250 static_cast<unsigned>(text->chunkLength)); |
251 } | 251 } |
252 | 252 |
253 static void textLatin1SwitchToPrimaryContext(UText* text, | 253 static void textLatin1SwitchToPrimaryContext(UText* text, |
254 int64_t nativeIndex, | 254 int64_t nativeIndex, |
255 int64_t nativeLength, | 255 int64_t nativeLength, |
256 UBool forward) { | 256 UBool forward) { |
257 ASSERT(!text->chunkContents || text->chunkContents == text->q); | 257 DCHECK(!text->chunkContents || text->chunkContents == text->q); |
258 text->chunkContents = static_cast<const UChar*>(text->pExtra); | 258 text->chunkContents = static_cast<const UChar*>(text->pExtra); |
259 textLatin1MoveInPrimaryContext(text, nativeIndex, nativeLength, forward); | 259 textLatin1MoveInPrimaryContext(text, nativeIndex, nativeLength, forward); |
260 } | 260 } |
261 | 261 |
262 static void textLatin1MoveInPriorContext(UText* text, | 262 static void textLatin1MoveInPriorContext(UText* text, |
263 int64_t nativeIndex, | 263 int64_t nativeIndex, |
264 int64_t nativeLength, | 264 int64_t nativeLength, |
265 UBool forward) { | 265 UBool forward) { |
266 ASSERT(text->chunkContents == text->q); | 266 DCHECK_EQ(text->chunkContents, text->q); |
267 ASSERT(forward ? nativeIndex < text->b : nativeIndex <= text->b); | 267 DCHECK(forward ? nativeIndex < text->b : nativeIndex <= text->b); |
268 DCHECK(forward ? nativeIndex < nativeLength : nativeIndex <= nativeLength); | 268 DCHECK(forward ? nativeIndex < nativeLength : nativeIndex <= nativeLength); |
269 DCHECK(forward ? nativeIndex < nativeLength : nativeIndex <= nativeLength); | 269 DCHECK(forward ? nativeIndex < nativeLength : nativeIndex <= nativeLength); |
270 text->chunkNativeStart = 0; | 270 text->chunkNativeStart = 0; |
271 text->chunkNativeLimit = text->b; | 271 text->chunkNativeLimit = text->b; |
272 text->chunkLength = text->b; | 272 text->chunkLength = text->b; |
273 text->nativeIndexingLimit = text->chunkLength; | 273 text->nativeIndexingLimit = text->chunkLength; |
274 int64_t offset = nativeIndex - text->chunkNativeStart; | 274 int64_t offset = nativeIndex - text->chunkNativeStart; |
275 // Ensure chunk offset is well defined if computed offset exceeds int32_t | 275 // Ensure chunk offset is well defined if computed offset exceeds int32_t |
276 // range or chunk length. | 276 // range or chunk length. |
277 ASSERT(offset <= std::numeric_limits<int32_t>::max()); | 277 DCHECK_LE(offset, std::numeric_limits<int32_t>::max()); |
278 text->chunkOffset = std::min(offset <= std::numeric_limits<int32_t>::max() | 278 text->chunkOffset = std::min(offset <= std::numeric_limits<int32_t>::max() |
279 ? static_cast<int32_t>(offset) | 279 ? static_cast<int32_t>(offset) |
280 : 0, | 280 : 0, |
281 text->chunkLength); | 281 text->chunkLength); |
282 } | 282 } |
283 | 283 |
284 static void textLatin1SwitchToPriorContext(UText* text, | 284 static void textLatin1SwitchToPriorContext(UText* text, |
285 int64_t nativeIndex, | 285 int64_t nativeIndex, |
286 int64_t nativeLength, | 286 int64_t nativeLength, |
287 UBool forward) { | 287 UBool forward) { |
288 ASSERT(!text->chunkContents || text->chunkContents == text->pExtra); | 288 DCHECK(!text->chunkContents || text->chunkContents == text->pExtra); |
289 text->chunkContents = static_cast<const UChar*>(text->q); | 289 text->chunkContents = static_cast<const UChar*>(text->q); |
290 textLatin1MoveInPriorContext(text, nativeIndex, nativeLength, forward); | 290 textLatin1MoveInPriorContext(text, nativeIndex, nativeLength, forward); |
291 } | 291 } |
292 | 292 |
293 static inline bool textInChunkOrOutOfRange(UText* text, | 293 static inline bool textInChunkOrOutOfRange(UText* text, |
294 int64_t nativeIndex, | 294 int64_t nativeIndex, |
295 int64_t nativeLength, | 295 int64_t nativeLength, |
296 UBool forward, | 296 UBool forward, |
297 UBool& isAccessible) { | 297 UBool& isAccessible) { |
298 if (forward) { | 298 if (forward) { |
299 if (nativeIndex >= text->chunkNativeStart && | 299 if (nativeIndex >= text->chunkNativeStart && |
300 nativeIndex < text->chunkNativeLimit) { | 300 nativeIndex < text->chunkNativeLimit) { |
301 int64_t offset = nativeIndex - text->chunkNativeStart; | 301 int64_t offset = nativeIndex - text->chunkNativeStart; |
302 // Ensure chunk offset is well formed if computed offset exceeds int32_t | 302 // Ensure chunk offset is well formed if computed offset exceeds int32_t |
303 // range. | 303 // range. |
304 ASSERT(offset <= std::numeric_limits<int32_t>::max()); | 304 DCHECK_LE(offset, std::numeric_limits<int32_t>::max()); |
305 text->chunkOffset = offset <= std::numeric_limits<int32_t>::max() | 305 text->chunkOffset = offset <= std::numeric_limits<int32_t>::max() |
306 ? static_cast<int32_t>(offset) | 306 ? static_cast<int32_t>(offset) |
307 : 0; | 307 : 0; |
308 isAccessible = TRUE; | 308 isAccessible = TRUE; |
309 return true; | 309 return true; |
310 } | 310 } |
311 if (nativeIndex >= nativeLength && text->chunkNativeLimit == nativeLength) { | 311 if (nativeIndex >= nativeLength && text->chunkNativeLimit == nativeLength) { |
312 text->chunkOffset = text->chunkLength; | 312 text->chunkOffset = text->chunkLength; |
313 isAccessible = FALSE; | 313 isAccessible = FALSE; |
314 return true; | 314 return true; |
315 } | 315 } |
316 } else { | 316 } else { |
317 if (nativeIndex > text->chunkNativeStart && | 317 if (nativeIndex > text->chunkNativeStart && |
318 nativeIndex <= text->chunkNativeLimit) { | 318 nativeIndex <= text->chunkNativeLimit) { |
319 int64_t offset = nativeIndex - text->chunkNativeStart; | 319 int64_t offset = nativeIndex - text->chunkNativeStart; |
320 // Ensure chunk offset is well formed if computed offset exceeds int32_t | 320 // Ensure chunk offset is well formed if computed offset exceeds int32_t |
321 // range. | 321 // range. |
322 ASSERT(offset <= std::numeric_limits<int32_t>::max()); | 322 DCHECK_LE(offset, std::numeric_limits<int32_t>::max()); |
323 text->chunkOffset = offset <= std::numeric_limits<int32_t>::max() | 323 text->chunkOffset = offset <= std::numeric_limits<int32_t>::max() |
324 ? static_cast<int32_t>(offset) | 324 ? static_cast<int32_t>(offset) |
325 : 0; | 325 : 0; |
326 isAccessible = TRUE; | 326 isAccessible = TRUE; |
327 return true; | 327 return true; |
328 } | 328 } |
329 if (nativeIndex <= 0 && !text->chunkNativeStart) { | 329 if (nativeIndex <= 0 && !text->chunkNativeStart) { |
330 text->chunkOffset = 0; | 330 text->chunkOffset = 0; |
331 isAccessible = FALSE; | 331 isAccessible = FALSE; |
332 return true; | 332 return true; |
333 } | 333 } |
334 } | 334 } |
335 return false; | 335 return false; |
336 } | 336 } |
337 | 337 |
338 static UBool textLatin1Access(UText* text, int64_t nativeIndex, UBool forward) { | 338 static UBool textLatin1Access(UText* text, int64_t nativeIndex, UBool forward) { |
339 if (!text->context) | 339 if (!text->context) |
340 return FALSE; | 340 return FALSE; |
341 int64_t nativeLength = textNativeLength(text); | 341 int64_t nativeLength = textNativeLength(text); |
342 UBool isAccessible; | 342 UBool isAccessible; |
343 if (textInChunkOrOutOfRange(text, nativeIndex, nativeLength, forward, | 343 if (textInChunkOrOutOfRange(text, nativeIndex, nativeLength, forward, |
344 isAccessible)) | 344 isAccessible)) |
345 return isAccessible; | 345 return isAccessible; |
346 nativeIndex = textPinIndex(nativeIndex, nativeLength - 1); | 346 nativeIndex = textPinIndex(nativeIndex, nativeLength - 1); |
347 TextContext currentContext = textLatin1GetCurrentContext(text); | 347 TextContext currentContext = textLatin1GetCurrentContext(text); |
348 TextContext newContext = textGetContext(text, nativeIndex, forward); | 348 TextContext newContext = textGetContext(text, nativeIndex, forward); |
349 ASSERT(newContext != NoContext); | 349 DCHECK_NE(newContext, NoContext); |
350 if (newContext == currentContext) { | 350 if (newContext == currentContext) { |
351 if (currentContext == PrimaryContext) { | 351 if (currentContext == PrimaryContext) { |
352 textLatin1MoveInPrimaryContext(text, nativeIndex, nativeLength, forward); | 352 textLatin1MoveInPrimaryContext(text, nativeIndex, nativeLength, forward); |
353 } else { | 353 } else { |
354 textLatin1MoveInPriorContext(text, nativeIndex, nativeLength, forward); | 354 textLatin1MoveInPriorContext(text, nativeIndex, nativeLength, forward); |
355 } | 355 } |
356 } else if (newContext == PrimaryContext) { | 356 } else if (newContext == PrimaryContext) { |
357 textLatin1SwitchToPrimaryContext(text, nativeIndex, nativeLength, forward); | 357 textLatin1SwitchToPrimaryContext(text, nativeIndex, nativeLength, forward); |
358 } else { | 358 } else { |
359 ASSERT(newContext == PriorContext); | 359 DCHECK_EQ(newContext, PriorContext); |
360 textLatin1SwitchToPriorContext(text, nativeIndex, nativeLength, forward); | 360 textLatin1SwitchToPriorContext(text, nativeIndex, nativeLength, forward); |
361 } | 361 } |
362 return TRUE; | 362 return TRUE; |
363 } | 363 } |
364 | 364 |
365 static const struct UTextFuncs textLatin1Funcs = { | 365 static const struct UTextFuncs textLatin1Funcs = { |
366 sizeof(UTextFuncs), 0, 0, 0, textClone, textNativeLength, | 366 sizeof(UTextFuncs), 0, 0, 0, textClone, textNativeLength, |
367 textLatin1Access, textExtract, 0, 0, 0, 0, | 367 textLatin1Access, textExtract, 0, 0, 0, 0, |
368 textClose, 0, 0, 0, | 368 textClose, 0, 0, 0, |
369 }; | 369 }; |
(...skipping 23 matching lines...) Expand all Loading... | |
393 return 0; | 393 return 0; |
394 | 394 |
395 if (!string || | 395 if (!string || |
396 length > static_cast<unsigned>(std::numeric_limits<int32_t>::max())) { | 396 length > static_cast<unsigned>(std::numeric_limits<int32_t>::max())) { |
397 *status = U_ILLEGAL_ARGUMENT_ERROR; | 397 *status = U_ILLEGAL_ARGUMENT_ERROR; |
398 return 0; | 398 return 0; |
399 } | 399 } |
400 UText* text = | 400 UText* text = |
401 utext_setup(&utWithBuffer->text, sizeof(utWithBuffer->buffer), status); | 401 utext_setup(&utWithBuffer->text, sizeof(utWithBuffer->buffer), status); |
402 if (U_FAILURE(*status)) { | 402 if (U_FAILURE(*status)) { |
403 ASSERT(!text); | 403 DCHECK(!text); |
404 return 0; | 404 return 0; |
405 } | 405 } |
406 textInit(text, &textLatin1Funcs, string, length, priorContext, | 406 textInit(text, &textLatin1Funcs, string, length, priorContext, |
407 priorContextLength); | 407 priorContextLength); |
408 return text; | 408 return text; |
409 } | 409 } |
410 | 410 |
411 static inline TextContext textUTF16GetCurrentContext(const UText* text) { | 411 static inline TextContext textUTF16GetCurrentContext(const UText* text) { |
412 if (!text->chunkContents) | 412 if (!text->chunkContents) |
413 return NoContext; | 413 return NoContext; |
414 return text->chunkContents == text->p ? PrimaryContext : PriorContext; | 414 return text->chunkContents == text->p ? PrimaryContext : PriorContext; |
415 } | 415 } |
416 | 416 |
417 static void textUTF16MoveInPrimaryContext(UText* text, | 417 static void textUTF16MoveInPrimaryContext(UText* text, |
418 int64_t nativeIndex, | 418 int64_t nativeIndex, |
419 int64_t nativeLength, | 419 int64_t nativeLength, |
420 UBool forward) { | 420 UBool forward) { |
421 ASSERT(text->chunkContents == text->p); | 421 DCHECK_EQ(text->chunkContents, text->p); |
422 DCHECK(forward ? nativeIndex >= text->b : nativeIndex > text->b); | 422 DCHECK(forward ? nativeIndex >= text->b : nativeIndex > text->b); |
423 DCHECK(forward ? nativeIndex < nativeLength : nativeIndex <= nativeLength); | 423 DCHECK(forward ? nativeIndex < nativeLength : nativeIndex <= nativeLength); |
424 text->chunkNativeStart = text->b; | 424 text->chunkNativeStart = text->b; |
425 text->chunkNativeLimit = nativeLength; | 425 text->chunkNativeLimit = nativeLength; |
426 int64_t length = text->chunkNativeLimit - text->chunkNativeStart; | 426 int64_t length = text->chunkNativeLimit - text->chunkNativeStart; |
427 // Ensure chunk length is well defined if computed length exceeds int32_t | 427 // Ensure chunk length is well defined if computed length exceeds int32_t |
428 // range. | 428 // range. |
429 ASSERT(length <= std::numeric_limits<int32_t>::max()); | 429 DCHECK_LE(length, std::numeric_limits<int32_t>::max()); |
430 text->chunkLength = length <= std::numeric_limits<int32_t>::max() | 430 text->chunkLength = length <= std::numeric_limits<int32_t>::max() |
431 ? static_cast<int32_t>(length) | 431 ? static_cast<int32_t>(length) |
432 : 0; | 432 : 0; |
433 text->nativeIndexingLimit = text->chunkLength; | 433 text->nativeIndexingLimit = text->chunkLength; |
434 int64_t offset = nativeIndex - text->chunkNativeStart; | 434 int64_t offset = nativeIndex - text->chunkNativeStart; |
435 // Ensure chunk offset is well defined if computed offset exceeds int32_t | 435 // Ensure chunk offset is well defined if computed offset exceeds int32_t |
436 // range or chunk length. | 436 // range or chunk length. |
437 ASSERT(offset <= std::numeric_limits<int32_t>::max()); | 437 DCHECK_LE(offset, std::numeric_limits<int32_t>::max()); |
438 text->chunkOffset = std::min(offset <= std::numeric_limits<int32_t>::max() | 438 text->chunkOffset = std::min(offset <= std::numeric_limits<int32_t>::max() |
439 ? static_cast<int32_t>(offset) | 439 ? static_cast<int32_t>(offset) |
440 : 0, | 440 : 0, |
441 text->chunkLength); | 441 text->chunkLength); |
442 } | 442 } |
443 | 443 |
444 static void textUTF16SwitchToPrimaryContext(UText* text, | 444 static void textUTF16SwitchToPrimaryContext(UText* text, |
445 int64_t nativeIndex, | 445 int64_t nativeIndex, |
446 int64_t nativeLength, | 446 int64_t nativeLength, |
447 UBool forward) { | 447 UBool forward) { |
448 ASSERT(!text->chunkContents || text->chunkContents == text->q); | 448 DCHECK(!text->chunkContents || text->chunkContents == text->q); |
449 text->chunkContents = static_cast<const UChar*>(text->p); | 449 text->chunkContents = static_cast<const UChar*>(text->p); |
450 textUTF16MoveInPrimaryContext(text, nativeIndex, nativeLength, forward); | 450 textUTF16MoveInPrimaryContext(text, nativeIndex, nativeLength, forward); |
451 } | 451 } |
452 | 452 |
453 static void textUTF16MoveInPriorContext(UText* text, | 453 static void textUTF16MoveInPriorContext(UText* text, |
454 int64_t nativeIndex, | 454 int64_t nativeIndex, |
455 int64_t nativeLength, | 455 int64_t nativeLength, |
456 UBool forward) { | 456 UBool forward) { |
457 ASSERT(text->chunkContents == text->q); | 457 DCHECK_EQ(text->chunkContents, text->q); |
458 ASSERT(forward ? nativeIndex < text->b : nativeIndex <= text->b); | 458 DCHECK(forward ? nativeIndex < text->b : nativeIndex <= text->b); |
459 DCHECK(forward ? nativeIndex < nativeLength : nativeIndex <= nativeLength); | 459 DCHECK(forward ? nativeIndex < nativeLength : nativeIndex <= nativeLength); |
460 DCHECK(forward ? nativeIndex < nativeLength : nativeIndex <= nativeLength); | 460 DCHECK(forward ? nativeIndex < nativeLength : nativeIndex <= nativeLength); |
461 text->chunkNativeStart = 0; | 461 text->chunkNativeStart = 0; |
462 text->chunkNativeLimit = text->b; | 462 text->chunkNativeLimit = text->b; |
463 text->chunkLength = text->b; | 463 text->chunkLength = text->b; |
464 text->nativeIndexingLimit = text->chunkLength; | 464 text->nativeIndexingLimit = text->chunkLength; |
465 int64_t offset = nativeIndex - text->chunkNativeStart; | 465 int64_t offset = nativeIndex - text->chunkNativeStart; |
466 // Ensure chunk offset is well defined if computed offset exceeds int32_t | 466 // Ensure chunk offset is well defined if computed offset exceeds int32_t |
467 // range or chunk length. | 467 // range or chunk length. |
468 ASSERT(offset <= std::numeric_limits<int32_t>::max()); | 468 DCHECK_LE(offset, std::numeric_limits<int32_t>::max()); |
469 text->chunkOffset = std::min(offset <= std::numeric_limits<int32_t>::max() | 469 text->chunkOffset = std::min(offset <= std::numeric_limits<int32_t>::max() |
470 ? static_cast<int32_t>(offset) | 470 ? static_cast<int32_t>(offset) |
471 : 0, | 471 : 0, |
472 text->chunkLength); | 472 text->chunkLength); |
473 } | 473 } |
474 | 474 |
475 static void textUTF16SwitchToPriorContext(UText* text, | 475 static void textUTF16SwitchToPriorContext(UText* text, |
476 int64_t nativeIndex, | 476 int64_t nativeIndex, |
477 int64_t nativeLength, | 477 int64_t nativeLength, |
478 UBool forward) { | 478 UBool forward) { |
479 ASSERT(!text->chunkContents || text->chunkContents == text->p); | 479 DCHECK(!text->chunkContents || text->chunkContents == text->p); |
480 text->chunkContents = static_cast<const UChar*>(text->q); | 480 text->chunkContents = static_cast<const UChar*>(text->q); |
481 textUTF16MoveInPriorContext(text, nativeIndex, nativeLength, forward); | 481 textUTF16MoveInPriorContext(text, nativeIndex, nativeLength, forward); |
482 } | 482 } |
483 | 483 |
484 static UBool textUTF16Access(UText* text, int64_t nativeIndex, UBool forward) { | 484 static UBool textUTF16Access(UText* text, int64_t nativeIndex, UBool forward) { |
485 if (!text->context) | 485 if (!text->context) |
486 return FALSE; | 486 return FALSE; |
487 int64_t nativeLength = textNativeLength(text); | 487 int64_t nativeLength = textNativeLength(text); |
488 UBool isAccessible; | 488 UBool isAccessible; |
489 if (textInChunkOrOutOfRange(text, nativeIndex, nativeLength, forward, | 489 if (textInChunkOrOutOfRange(text, nativeIndex, nativeLength, forward, |
490 isAccessible)) | 490 isAccessible)) |
491 return isAccessible; | 491 return isAccessible; |
492 nativeIndex = textPinIndex(nativeIndex, nativeLength - 1); | 492 nativeIndex = textPinIndex(nativeIndex, nativeLength - 1); |
493 TextContext currentContext = textUTF16GetCurrentContext(text); | 493 TextContext currentContext = textUTF16GetCurrentContext(text); |
494 TextContext newContext = textGetContext(text, nativeIndex, forward); | 494 TextContext newContext = textGetContext(text, nativeIndex, forward); |
495 ASSERT(newContext != NoContext); | 495 DCHECK_NE(newContext, NoContext); |
496 if (newContext == currentContext) { | 496 if (newContext == currentContext) { |
497 if (currentContext == PrimaryContext) { | 497 if (currentContext == PrimaryContext) { |
498 textUTF16MoveInPrimaryContext(text, nativeIndex, nativeLength, forward); | 498 textUTF16MoveInPrimaryContext(text, nativeIndex, nativeLength, forward); |
499 } else { | 499 } else { |
500 textUTF16MoveInPriorContext(text, nativeIndex, nativeLength, forward); | 500 textUTF16MoveInPriorContext(text, nativeIndex, nativeLength, forward); |
501 } | 501 } |
502 } else if (newContext == PrimaryContext) { | 502 } else if (newContext == PrimaryContext) { |
503 textUTF16SwitchToPrimaryContext(text, nativeIndex, nativeLength, forward); | 503 textUTF16SwitchToPrimaryContext(text, nativeIndex, nativeLength, forward); |
504 } else { | 504 } else { |
505 ASSERT(newContext == PriorContext); | 505 DCHECK_EQ(newContext, PriorContext); |
506 textUTF16SwitchToPriorContext(text, nativeIndex, nativeLength, forward); | 506 textUTF16SwitchToPriorContext(text, nativeIndex, nativeLength, forward); |
507 } | 507 } |
508 return TRUE; | 508 return TRUE; |
509 } | 509 } |
510 | 510 |
511 static const struct UTextFuncs textUTF16Funcs = { | 511 static const struct UTextFuncs textUTF16Funcs = { |
512 sizeof(UTextFuncs), 0, 0, 0, textClone, textNativeLength, | 512 sizeof(UTextFuncs), 0, 0, 0, textClone, textNativeLength, |
513 textUTF16Access, textExtract, 0, 0, 0, 0, | 513 textUTF16Access, textExtract, 0, 0, 0, 0, |
514 textClose, 0, 0, 0, | 514 textClose, 0, 0, 0, |
515 }; | 515 }; |
516 | 516 |
517 static UText* textOpenUTF16(UText* text, | 517 static UText* textOpenUTF16(UText* text, |
518 const UChar* string, | 518 const UChar* string, |
519 unsigned length, | 519 unsigned length, |
520 const UChar* priorContext, | 520 const UChar* priorContext, |
521 int priorContextLength, | 521 int priorContextLength, |
522 UErrorCode* status) { | 522 UErrorCode* status) { |
523 if (U_FAILURE(*status)) | 523 if (U_FAILURE(*status)) |
524 return 0; | 524 return 0; |
525 | 525 |
526 if (!string || | 526 if (!string || |
527 length > static_cast<unsigned>(std::numeric_limits<int32_t>::max())) { | 527 length > static_cast<unsigned>(std::numeric_limits<int32_t>::max())) { |
528 *status = U_ILLEGAL_ARGUMENT_ERROR; | 528 *status = U_ILLEGAL_ARGUMENT_ERROR; |
529 return 0; | 529 return 0; |
530 } | 530 } |
531 | 531 |
532 text = utext_setup(text, 0, status); | 532 text = utext_setup(text, 0, status); |
533 if (U_FAILURE(*status)) { | 533 if (U_FAILURE(*status)) { |
534 ASSERT(!text); | 534 DCHECK(!text); |
535 return 0; | 535 return 0; |
536 } | 536 } |
537 textInit(text, &textUTF16Funcs, string, length, priorContext, | 537 textInit(text, &textUTF16Funcs, string, length, priorContext, |
538 priorContextLength); | 538 priorContextLength); |
539 return text; | 539 return text; |
540 } | 540 } |
541 | 541 |
542 static UText emptyText = UTEXT_INITIALIZER; | 542 static UText emptyText = UTEXT_INITIALIZER; |
543 | 543 |
544 static TextBreakIterator* wordBreakIterator(const LChar* string, int length) { | 544 static TextBreakIterator* wordBreakIterator(const LChar* string, int length) { |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
932 "$Tel1 $TelV $Tel0;" // Telugu Virama (backward) | 932 "$Tel1 $TelV $Tel0;" // Telugu Virama (backward) |
933 "$Kan1 $KanV $Kan0;" // Kannada Virama (backward) | 933 "$Kan1 $KanV $Kan0;" // Kannada Virama (backward) |
934 "$Mal1 $MalV $Mal0;" // Malayalam Virama (backward) | 934 "$Mal1 $MalV $Mal0;" // Malayalam Virama (backward) |
935 "!!safe_reverse;" | 935 "!!safe_reverse;" |
936 "!!safe_forward;"; | 936 "!!safe_forward;"; |
937 | 937 |
938 return setUpIteratorWithRules(kRules, string, length); | 938 return setUpIteratorWithRules(kRules, string, length); |
939 } | 939 } |
940 | 940 |
941 } // namespace blink | 941 } // namespace blink |
OLD | NEW |