| 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()), open_status); | 76 icu::Locale(CurrentTextBreakLocaleID()), open_status); |
| 77 } | 77 } |
| 78 | 78 |
| 79 if (U_FAILURE(open_status)) { | 79 if (U_FAILURE(open_status)) { |
| 80 DLOG(ERROR) << "icu::BreakIterator construction failed with status " | 80 DLOG(ERROR) << "icu::BreakIterator construction failed with status " |
| 81 << open_status; | 81 << open_status; |
| 82 return 0; | 82 return 0; |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 ASSERT(!vended_iterators_.Contains(iterator)); | 86 DCHECK(!vended_iterators_.Contains(iterator)); |
| 87 vended_iterators_.Set(iterator, locale); | 87 vended_iterators_.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(vended_iterators_.Contains(iterator)); | 92 DCHECK(vended_iterators_.Contains(iterator)); |
| 93 | 93 |
| 94 if (pool_.size() == kCapacity) { | 94 if (pool_.size() == kCapacity) { |
| 95 delete (pool_[0].second); | 95 delete (pool_[0].second); |
| 96 pool_.erase(0); | 96 pool_.erase(0); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 void* extra_new = destination->pExtra; | 169 void* extra_new = destination->pExtra; |
| 170 int32_t flags = destination->flags; | 170 int32_t flags = destination->flags; |
| 171 int size_to_copy = std::min(source->sizeOfStruct, destination->sizeOfStruct); | 171 int size_to_copy = std::min(source->sizeOfStruct, destination->sizeOfStruct); |
| 172 memcpy(destination, source, size_to_copy); | 172 memcpy(destination, source, size_to_copy); |
| 173 destination->pExtra = extra_new; | 173 destination->pExtra = extra_new; |
| 174 destination->flags = flags; | 174 destination->flags = flags; |
| 175 memcpy(destination->pExtra, source->pExtra, extra_size); | 175 memcpy(destination->pExtra, source->pExtra, extra_size); |
| 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* chunk_contents = | 180 const void* chunk_contents = |
| 181 static_cast<const void*>(destination->chunkContents); | 181 static_cast<const void*>(destination->chunkContents); |
| 182 TextFixPointer(source, destination, chunk_contents); | 182 TextFixPointer(source, destination, chunk_contents); |
| 183 destination->chunkContents = static_cast<const UChar*>(chunk_contents); | 183 destination->chunkContents = static_cast<const UChar*>(chunk_contents); |
| 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* error_code) { | 192 UErrorCode* error_code) { |
| 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 *error_code = U_UNSUPPORTED_ERROR; | 196 *error_code = 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 native_index, | 205 int64_t native_index, |
| 206 UBool forward) { | 206 UBool forward) { |
| 207 if (!text->b || native_index > text->b) | 207 if (!text->b || native_index > text->b) |
| 208 return kPrimaryContext; | 208 return kPrimaryContext; |
| 209 if (native_index == text->b) | 209 if (native_index == text->b) |
| 210 return forward ? kPrimaryContext : kPriorContext; | 210 return forward ? kPrimaryContext : kPriorContext; |
| 211 return kPriorContext; | 211 return kPriorContext; |
| 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 kNoContext; | 216 return kNoContext; |
| 217 return text->chunkContents == text->pExtra ? kPrimaryContext : kPriorContext; | 217 return text->chunkContents == text->pExtra ? kPrimaryContext : kPriorContext; |
| 218 } | 218 } |
| 219 | 219 |
| 220 static void TextLatin1MoveInPrimaryContext(UText* text, | 220 static void TextLatin1MoveInPrimaryContext(UText* text, |
| 221 int64_t native_index, | 221 int64_t native_index, |
| 222 int64_t native_length, | 222 int64_t native_length, |
| 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(native_index >= text->b && native_index < native_length); | 226 DCHECK_GE(native_index, text->b); |
| 227 DCHECK_LT(native_index, native_length); |
| 227 text->chunkNativeStart = native_index; | 228 text->chunkNativeStart = native_index; |
| 228 text->chunkNativeLimit = native_index + text->extraSize / sizeof(UChar); | 229 text->chunkNativeLimit = native_index + text->extraSize / sizeof(UChar); |
| 229 if (text->chunkNativeLimit > native_length) | 230 if (text->chunkNativeLimit > native_length) |
| 230 text->chunkNativeLimit = native_length; | 231 text->chunkNativeLimit = native_length; |
| 231 } else { | 232 } else { |
| 232 ASSERT(native_index > text->b && native_index <= native_length); | 233 DCHECK_GT(native_index, text->b); |
| 234 DCHECK_LE(native_index, native_length); |
| 233 text->chunkNativeLimit = native_index; | 235 text->chunkNativeLimit = native_index; |
| 234 text->chunkNativeStart = native_index - text->extraSize / sizeof(UChar); | 236 text->chunkNativeStart = native_index - text->extraSize / sizeof(UChar); |
| 235 if (text->chunkNativeStart < text->b) | 237 if (text->chunkNativeStart < text->b) |
| 236 text->chunkNativeStart = text->b; | 238 text->chunkNativeStart = text->b; |
| 237 } | 239 } |
| 238 int64_t length = text->chunkNativeLimit - text->chunkNativeStart; | 240 int64_t length = text->chunkNativeLimit - text->chunkNativeStart; |
| 239 // Ensure chunk length is well defined if computed length exceeds int32_t | 241 // Ensure chunk length is well defined if computed length exceeds int32_t |
| 240 // range. | 242 // range. |
| 241 ASSERT(length <= std::numeric_limits<int32_t>::max()); | 243 DCHECK_LE(length, std::numeric_limits<int32_t>::max()); |
| 242 text->chunkLength = length <= std::numeric_limits<int32_t>::max() | 244 text->chunkLength = length <= std::numeric_limits<int32_t>::max() |
| 243 ? static_cast<int32_t>(length) | 245 ? static_cast<int32_t>(length) |
| 244 : 0; | 246 : 0; |
| 245 text->nativeIndexingLimit = text->chunkLength; | 247 text->nativeIndexingLimit = text->chunkLength; |
| 246 text->chunkOffset = forward ? 0 : text->chunkLength; | 248 text->chunkOffset = forward ? 0 : text->chunkLength; |
| 247 StringImpl::CopyChars( | 249 StringImpl::CopyChars( |
| 248 const_cast<UChar*>(text->chunkContents), | 250 const_cast<UChar*>(text->chunkContents), |
| 249 static_cast<const LChar*>(text->p) + (text->chunkNativeStart - text->b), | 251 static_cast<const LChar*>(text->p) + (text->chunkNativeStart - text->b), |
| 250 static_cast<unsigned>(text->chunkLength)); | 252 static_cast<unsigned>(text->chunkLength)); |
| 251 } | 253 } |
| 252 | 254 |
| 253 static void TextLatin1SwitchToPrimaryContext(UText* text, | 255 static void TextLatin1SwitchToPrimaryContext(UText* text, |
| 254 int64_t native_index, | 256 int64_t native_index, |
| 255 int64_t native_length, | 257 int64_t native_length, |
| 256 UBool forward) { | 258 UBool forward) { |
| 257 ASSERT(!text->chunkContents || text->chunkContents == text->q); | 259 DCHECK(!text->chunkContents || text->chunkContents == text->q); |
| 258 text->chunkContents = static_cast<const UChar*>(text->pExtra); | 260 text->chunkContents = static_cast<const UChar*>(text->pExtra); |
| 259 TextLatin1MoveInPrimaryContext(text, native_index, native_length, forward); | 261 TextLatin1MoveInPrimaryContext(text, native_index, native_length, forward); |
| 260 } | 262 } |
| 261 | 263 |
| 262 static void TextLatin1MoveInPriorContext(UText* text, | 264 static void TextLatin1MoveInPriorContext(UText* text, |
| 263 int64_t native_index, | 265 int64_t native_index, |
| 264 int64_t native_length, | 266 int64_t native_length, |
| 265 UBool forward) { | 267 UBool forward) { |
| 266 ASSERT(text->chunkContents == text->q); | 268 DCHECK_EQ(text->chunkContents, text->q); |
| 267 ASSERT(forward ? native_index < text->b : native_index <= text->b); | 269 DCHECK(forward ? native_index < text->b : native_index <= text->b); |
| 268 DCHECK(forward ? native_index < native_length | 270 DCHECK(forward ? native_index < native_length |
| 269 : native_index <= native_length); | 271 : native_index <= native_length); |
| 270 DCHECK(forward ? native_index < native_length | 272 DCHECK(forward ? native_index < native_length |
| 271 : native_index <= native_length); | 273 : native_index <= native_length); |
| 272 text->chunkNativeStart = 0; | 274 text->chunkNativeStart = 0; |
| 273 text->chunkNativeLimit = text->b; | 275 text->chunkNativeLimit = text->b; |
| 274 text->chunkLength = text->b; | 276 text->chunkLength = text->b; |
| 275 text->nativeIndexingLimit = text->chunkLength; | 277 text->nativeIndexingLimit = text->chunkLength; |
| 276 int64_t offset = native_index - text->chunkNativeStart; | 278 int64_t offset = native_index - text->chunkNativeStart; |
| 277 // Ensure chunk offset is well defined if computed offset exceeds int32_t | 279 // Ensure chunk offset is well defined if computed offset exceeds int32_t |
| 278 // range or chunk length. | 280 // range or chunk length. |
| 279 ASSERT(offset <= std::numeric_limits<int32_t>::max()); | 281 DCHECK_LE(offset, std::numeric_limits<int32_t>::max()); |
| 280 text->chunkOffset = std::min(offset <= std::numeric_limits<int32_t>::max() | 282 text->chunkOffset = std::min(offset <= std::numeric_limits<int32_t>::max() |
| 281 ? static_cast<int32_t>(offset) | 283 ? static_cast<int32_t>(offset) |
| 282 : 0, | 284 : 0, |
| 283 text->chunkLength); | 285 text->chunkLength); |
| 284 } | 286 } |
| 285 | 287 |
| 286 static void TextLatin1SwitchToPriorContext(UText* text, | 288 static void TextLatin1SwitchToPriorContext(UText* text, |
| 287 int64_t native_index, | 289 int64_t native_index, |
| 288 int64_t native_length, | 290 int64_t native_length, |
| 289 UBool forward) { | 291 UBool forward) { |
| 290 ASSERT(!text->chunkContents || text->chunkContents == text->pExtra); | 292 DCHECK(!text->chunkContents || text->chunkContents == text->pExtra); |
| 291 text->chunkContents = static_cast<const UChar*>(text->q); | 293 text->chunkContents = static_cast<const UChar*>(text->q); |
| 292 TextLatin1MoveInPriorContext(text, native_index, native_length, forward); | 294 TextLatin1MoveInPriorContext(text, native_index, native_length, forward); |
| 293 } | 295 } |
| 294 | 296 |
| 295 static inline bool TextInChunkOrOutOfRange(UText* text, | 297 static inline bool TextInChunkOrOutOfRange(UText* text, |
| 296 int64_t native_index, | 298 int64_t native_index, |
| 297 int64_t native_length, | 299 int64_t native_length, |
| 298 UBool forward, | 300 UBool forward, |
| 299 UBool& is_accessible) { | 301 UBool& is_accessible) { |
| 300 if (forward) { | 302 if (forward) { |
| 301 if (native_index >= text->chunkNativeStart && | 303 if (native_index >= text->chunkNativeStart && |
| 302 native_index < text->chunkNativeLimit) { | 304 native_index < text->chunkNativeLimit) { |
| 303 int64_t offset = native_index - text->chunkNativeStart; | 305 int64_t offset = native_index - text->chunkNativeStart; |
| 304 // Ensure chunk offset is well formed if computed offset exceeds int32_t | 306 // Ensure chunk offset is well formed if computed offset exceeds int32_t |
| 305 // range. | 307 // range. |
| 306 ASSERT(offset <= std::numeric_limits<int32_t>::max()); | 308 DCHECK_LE(offset, std::numeric_limits<int32_t>::max()); |
| 307 text->chunkOffset = offset <= std::numeric_limits<int32_t>::max() | 309 text->chunkOffset = offset <= std::numeric_limits<int32_t>::max() |
| 308 ? static_cast<int32_t>(offset) | 310 ? static_cast<int32_t>(offset) |
| 309 : 0; | 311 : 0; |
| 310 is_accessible = TRUE; | 312 is_accessible = TRUE; |
| 311 return true; | 313 return true; |
| 312 } | 314 } |
| 313 if (native_index >= native_length && | 315 if (native_index >= native_length && |
| 314 text->chunkNativeLimit == native_length) { | 316 text->chunkNativeLimit == native_length) { |
| 315 text->chunkOffset = text->chunkLength; | 317 text->chunkOffset = text->chunkLength; |
| 316 is_accessible = FALSE; | 318 is_accessible = FALSE; |
| 317 return true; | 319 return true; |
| 318 } | 320 } |
| 319 } else { | 321 } else { |
| 320 if (native_index > text->chunkNativeStart && | 322 if (native_index > text->chunkNativeStart && |
| 321 native_index <= text->chunkNativeLimit) { | 323 native_index <= text->chunkNativeLimit) { |
| 322 int64_t offset = native_index - text->chunkNativeStart; | 324 int64_t offset = native_index - text->chunkNativeStart; |
| 323 // Ensure chunk offset is well formed if computed offset exceeds int32_t | 325 // Ensure chunk offset is well formed if computed offset exceeds int32_t |
| 324 // range. | 326 // range. |
| 325 ASSERT(offset <= std::numeric_limits<int32_t>::max()); | 327 DCHECK_LE(offset, std::numeric_limits<int32_t>::max()); |
| 326 text->chunkOffset = offset <= std::numeric_limits<int32_t>::max() | 328 text->chunkOffset = offset <= std::numeric_limits<int32_t>::max() |
| 327 ? static_cast<int32_t>(offset) | 329 ? static_cast<int32_t>(offset) |
| 328 : 0; | 330 : 0; |
| 329 is_accessible = TRUE; | 331 is_accessible = TRUE; |
| 330 return true; | 332 return true; |
| 331 } | 333 } |
| 332 if (native_index <= 0 && !text->chunkNativeStart) { | 334 if (native_index <= 0 && !text->chunkNativeStart) { |
| 333 text->chunkOffset = 0; | 335 text->chunkOffset = 0; |
| 334 is_accessible = FALSE; | 336 is_accessible = FALSE; |
| 335 return true; | 337 return true; |
| 336 } | 338 } |
| 337 } | 339 } |
| 338 return false; | 340 return false; |
| 339 } | 341 } |
| 340 | 342 |
| 341 static UBool TextLatin1Access(UText* text, | 343 static UBool TextLatin1Access(UText* text, |
| 342 int64_t native_index, | 344 int64_t native_index, |
| 343 UBool forward) { | 345 UBool forward) { |
| 344 if (!text->context) | 346 if (!text->context) |
| 345 return FALSE; | 347 return FALSE; |
| 346 int64_t native_length = TextNativeLength(text); | 348 int64_t native_length = TextNativeLength(text); |
| 347 UBool is_accessible; | 349 UBool is_accessible; |
| 348 if (TextInChunkOrOutOfRange(text, native_index, native_length, forward, | 350 if (TextInChunkOrOutOfRange(text, native_index, native_length, forward, |
| 349 is_accessible)) | 351 is_accessible)) |
| 350 return is_accessible; | 352 return is_accessible; |
| 351 native_index = TextPinIndex(native_index, native_length - 1); | 353 native_index = TextPinIndex(native_index, native_length - 1); |
| 352 TextContext current_context = TextLatin1GetCurrentContext(text); | 354 TextContext current_context = TextLatin1GetCurrentContext(text); |
| 353 TextContext new_context = TextGetContext(text, native_index, forward); | 355 TextContext new_context = TextGetContext(text, native_index, forward); |
| 354 ASSERT(new_context != kNoContext); | 356 DCHECK_NE(new_context, kNoContext); |
| 355 if (new_context == current_context) { | 357 if (new_context == current_context) { |
| 356 if (current_context == kPrimaryContext) { | 358 if (current_context == kPrimaryContext) { |
| 357 TextLatin1MoveInPrimaryContext(text, native_index, native_length, | 359 TextLatin1MoveInPrimaryContext(text, native_index, native_length, |
| 358 forward); | 360 forward); |
| 359 } else { | 361 } else { |
| 360 TextLatin1MoveInPriorContext(text, native_index, native_length, forward); | 362 TextLatin1MoveInPriorContext(text, native_index, native_length, forward); |
| 361 } | 363 } |
| 362 } else if (new_context == kPrimaryContext) { | 364 } else if (new_context == kPrimaryContext) { |
| 363 TextLatin1SwitchToPrimaryContext(text, native_index, native_length, | 365 TextLatin1SwitchToPrimaryContext(text, native_index, native_length, |
| 364 forward); | 366 forward); |
| 365 } else { | 367 } else { |
| 366 ASSERT(new_context == kPriorContext); | 368 DCHECK_EQ(new_context, kPriorContext); |
| 367 TextLatin1SwitchToPriorContext(text, native_index, native_length, forward); | 369 TextLatin1SwitchToPriorContext(text, native_index, native_length, forward); |
| 368 } | 370 } |
| 369 return TRUE; | 371 return TRUE; |
| 370 } | 372 } |
| 371 | 373 |
| 372 static const struct UTextFuncs kTextLatin1Funcs = { | 374 static const struct UTextFuncs kTextLatin1Funcs = { |
| 373 sizeof(UTextFuncs), 0, 0, 0, TextClone, TextNativeLength, | 375 sizeof(UTextFuncs), 0, 0, 0, TextClone, TextNativeLength, |
| 374 TextLatin1Access, TextExtract, 0, 0, 0, 0, | 376 TextLatin1Access, TextExtract, 0, 0, 0, 0, |
| 375 TextClose, 0, 0, 0, | 377 TextClose, 0, 0, 0, |
| 376 }; | 378 }; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 400 return 0; | 402 return 0; |
| 401 | 403 |
| 402 if (!string || | 404 if (!string || |
| 403 length > static_cast<unsigned>(std::numeric_limits<int32_t>::max())) { | 405 length > static_cast<unsigned>(std::numeric_limits<int32_t>::max())) { |
| 404 *status = U_ILLEGAL_ARGUMENT_ERROR; | 406 *status = U_ILLEGAL_ARGUMENT_ERROR; |
| 405 return 0; | 407 return 0; |
| 406 } | 408 } |
| 407 UText* text = utext_setup(&ut_with_buffer->text, | 409 UText* text = utext_setup(&ut_with_buffer->text, |
| 408 sizeof(ut_with_buffer->buffer), status); | 410 sizeof(ut_with_buffer->buffer), status); |
| 409 if (U_FAILURE(*status)) { | 411 if (U_FAILURE(*status)) { |
| 410 ASSERT(!text); | 412 DCHECK(!text); |
| 411 return 0; | 413 return 0; |
| 412 } | 414 } |
| 413 TextInit(text, &kTextLatin1Funcs, string, length, prior_context, | 415 TextInit(text, &kTextLatin1Funcs, string, length, prior_context, |
| 414 prior_context_length); | 416 prior_context_length); |
| 415 return text; | 417 return text; |
| 416 } | 418 } |
| 417 | 419 |
| 418 static inline TextContext TextUTF16GetCurrentContext(const UText* text) { | 420 static inline TextContext TextUTF16GetCurrentContext(const UText* text) { |
| 419 if (!text->chunkContents) | 421 if (!text->chunkContents) |
| 420 return kNoContext; | 422 return kNoContext; |
| 421 return text->chunkContents == text->p ? kPrimaryContext : kPriorContext; | 423 return text->chunkContents == text->p ? kPrimaryContext : kPriorContext; |
| 422 } | 424 } |
| 423 | 425 |
| 424 static void TextUTF16MoveInPrimaryContext(UText* text, | 426 static void TextUTF16MoveInPrimaryContext(UText* text, |
| 425 int64_t native_index, | 427 int64_t native_index, |
| 426 int64_t native_length, | 428 int64_t native_length, |
| 427 UBool forward) { | 429 UBool forward) { |
| 428 ASSERT(text->chunkContents == text->p); | 430 DCHECK_EQ(text->chunkContents, text->p); |
| 429 DCHECK(forward ? native_index >= text->b : native_index > text->b); | 431 DCHECK(forward ? native_index >= text->b : native_index > text->b); |
| 430 DCHECK(forward ? native_index < native_length | 432 DCHECK(forward ? native_index < native_length |
| 431 : native_index <= native_length); | 433 : native_index <= native_length); |
| 432 text->chunkNativeStart = text->b; | 434 text->chunkNativeStart = text->b; |
| 433 text->chunkNativeLimit = native_length; | 435 text->chunkNativeLimit = native_length; |
| 434 int64_t length = text->chunkNativeLimit - text->chunkNativeStart; | 436 int64_t length = text->chunkNativeLimit - text->chunkNativeStart; |
| 435 // Ensure chunk length is well defined if computed length exceeds int32_t | 437 // Ensure chunk length is well defined if computed length exceeds int32_t |
| 436 // range. | 438 // range. |
| 437 ASSERT(length <= std::numeric_limits<int32_t>::max()); | 439 DCHECK_LE(length, std::numeric_limits<int32_t>::max()); |
| 438 text->chunkLength = length <= std::numeric_limits<int32_t>::max() | 440 text->chunkLength = length <= std::numeric_limits<int32_t>::max() |
| 439 ? static_cast<int32_t>(length) | 441 ? static_cast<int32_t>(length) |
| 440 : 0; | 442 : 0; |
| 441 text->nativeIndexingLimit = text->chunkLength; | 443 text->nativeIndexingLimit = text->chunkLength; |
| 442 int64_t offset = native_index - text->chunkNativeStart; | 444 int64_t offset = native_index - text->chunkNativeStart; |
| 443 // Ensure chunk offset is well defined if computed offset exceeds int32_t | 445 // Ensure chunk offset is well defined if computed offset exceeds int32_t |
| 444 // range or chunk length. | 446 // range or chunk length. |
| 445 ASSERT(offset <= std::numeric_limits<int32_t>::max()); | 447 DCHECK_LE(offset, std::numeric_limits<int32_t>::max()); |
| 446 text->chunkOffset = std::min(offset <= std::numeric_limits<int32_t>::max() | 448 text->chunkOffset = std::min(offset <= std::numeric_limits<int32_t>::max() |
| 447 ? static_cast<int32_t>(offset) | 449 ? static_cast<int32_t>(offset) |
| 448 : 0, | 450 : 0, |
| 449 text->chunkLength); | 451 text->chunkLength); |
| 450 } | 452 } |
| 451 | 453 |
| 452 static void TextUTF16SwitchToPrimaryContext(UText* text, | 454 static void TextUTF16SwitchToPrimaryContext(UText* text, |
| 453 int64_t native_index, | 455 int64_t native_index, |
| 454 int64_t native_length, | 456 int64_t native_length, |
| 455 UBool forward) { | 457 UBool forward) { |
| 456 ASSERT(!text->chunkContents || text->chunkContents == text->q); | 458 DCHECK(!text->chunkContents || text->chunkContents == text->q); |
| 457 text->chunkContents = static_cast<const UChar*>(text->p); | 459 text->chunkContents = static_cast<const UChar*>(text->p); |
| 458 TextUTF16MoveInPrimaryContext(text, native_index, native_length, forward); | 460 TextUTF16MoveInPrimaryContext(text, native_index, native_length, forward); |
| 459 } | 461 } |
| 460 | 462 |
| 461 static void TextUTF16MoveInPriorContext(UText* text, | 463 static void TextUTF16MoveInPriorContext(UText* text, |
| 462 int64_t native_index, | 464 int64_t native_index, |
| 463 int64_t native_length, | 465 int64_t native_length, |
| 464 UBool forward) { | 466 UBool forward) { |
| 465 ASSERT(text->chunkContents == text->q); | 467 DCHECK_EQ(text->chunkContents, text->q); |
| 466 ASSERT(forward ? native_index < text->b : native_index <= text->b); | 468 DCHECK(forward ? native_index < text->b : native_index <= text->b); |
| 467 DCHECK(forward ? native_index < native_length | 469 DCHECK(forward ? native_index < native_length |
| 468 : native_index <= native_length); | 470 : native_index <= native_length); |
| 469 DCHECK(forward ? native_index < native_length | 471 DCHECK(forward ? native_index < native_length |
| 470 : native_index <= native_length); | 472 : native_index <= native_length); |
| 471 text->chunkNativeStart = 0; | 473 text->chunkNativeStart = 0; |
| 472 text->chunkNativeLimit = text->b; | 474 text->chunkNativeLimit = text->b; |
| 473 text->chunkLength = text->b; | 475 text->chunkLength = text->b; |
| 474 text->nativeIndexingLimit = text->chunkLength; | 476 text->nativeIndexingLimit = text->chunkLength; |
| 475 int64_t offset = native_index - text->chunkNativeStart; | 477 int64_t offset = native_index - text->chunkNativeStart; |
| 476 // Ensure chunk offset is well defined if computed offset exceeds int32_t | 478 // Ensure chunk offset is well defined if computed offset exceeds int32_t |
| 477 // range or chunk length. | 479 // range or chunk length. |
| 478 ASSERT(offset <= std::numeric_limits<int32_t>::max()); | 480 DCHECK_LE(offset, std::numeric_limits<int32_t>::max()); |
| 479 text->chunkOffset = std::min(offset <= std::numeric_limits<int32_t>::max() | 481 text->chunkOffset = std::min(offset <= std::numeric_limits<int32_t>::max() |
| 480 ? static_cast<int32_t>(offset) | 482 ? static_cast<int32_t>(offset) |
| 481 : 0, | 483 : 0, |
| 482 text->chunkLength); | 484 text->chunkLength); |
| 483 } | 485 } |
| 484 | 486 |
| 485 static void TextUTF16SwitchToPriorContext(UText* text, | 487 static void TextUTF16SwitchToPriorContext(UText* text, |
| 486 int64_t native_index, | 488 int64_t native_index, |
| 487 int64_t native_length, | 489 int64_t native_length, |
| 488 UBool forward) { | 490 UBool forward) { |
| 489 ASSERT(!text->chunkContents || text->chunkContents == text->p); | 491 DCHECK(!text->chunkContents || text->chunkContents == text->p); |
| 490 text->chunkContents = static_cast<const UChar*>(text->q); | 492 text->chunkContents = static_cast<const UChar*>(text->q); |
| 491 TextUTF16MoveInPriorContext(text, native_index, native_length, forward); | 493 TextUTF16MoveInPriorContext(text, native_index, native_length, forward); |
| 492 } | 494 } |
| 493 | 495 |
| 494 static UBool TextUTF16Access(UText* text, int64_t native_index, UBool forward) { | 496 static UBool TextUTF16Access(UText* text, int64_t native_index, UBool forward) { |
| 495 if (!text->context) | 497 if (!text->context) |
| 496 return FALSE; | 498 return FALSE; |
| 497 int64_t native_length = TextNativeLength(text); | 499 int64_t native_length = TextNativeLength(text); |
| 498 UBool is_accessible; | 500 UBool is_accessible; |
| 499 if (TextInChunkOrOutOfRange(text, native_index, native_length, forward, | 501 if (TextInChunkOrOutOfRange(text, native_index, native_length, forward, |
| 500 is_accessible)) | 502 is_accessible)) |
| 501 return is_accessible; | 503 return is_accessible; |
| 502 native_index = TextPinIndex(native_index, native_length - 1); | 504 native_index = TextPinIndex(native_index, native_length - 1); |
| 503 TextContext current_context = TextUTF16GetCurrentContext(text); | 505 TextContext current_context = TextUTF16GetCurrentContext(text); |
| 504 TextContext new_context = TextGetContext(text, native_index, forward); | 506 TextContext new_context = TextGetContext(text, native_index, forward); |
| 505 ASSERT(new_context != kNoContext); | 507 DCHECK_NE(new_context, kNoContext); |
| 506 if (new_context == current_context) { | 508 if (new_context == current_context) { |
| 507 if (current_context == kPrimaryContext) { | 509 if (current_context == kPrimaryContext) { |
| 508 TextUTF16MoveInPrimaryContext(text, native_index, native_length, forward); | 510 TextUTF16MoveInPrimaryContext(text, native_index, native_length, forward); |
| 509 } else { | 511 } else { |
| 510 TextUTF16MoveInPriorContext(text, native_index, native_length, forward); | 512 TextUTF16MoveInPriorContext(text, native_index, native_length, forward); |
| 511 } | 513 } |
| 512 } else if (new_context == kPrimaryContext) { | 514 } else if (new_context == kPrimaryContext) { |
| 513 TextUTF16SwitchToPrimaryContext(text, native_index, native_length, forward); | 515 TextUTF16SwitchToPrimaryContext(text, native_index, native_length, forward); |
| 514 } else { | 516 } else { |
| 515 ASSERT(new_context == kPriorContext); | 517 DCHECK_EQ(new_context, kPriorContext); |
| 516 TextUTF16SwitchToPriorContext(text, native_index, native_length, forward); | 518 TextUTF16SwitchToPriorContext(text, native_index, native_length, forward); |
| 517 } | 519 } |
| 518 return TRUE; | 520 return TRUE; |
| 519 } | 521 } |
| 520 | 522 |
| 521 static const struct UTextFuncs kTextUTF16Funcs = { | 523 static const struct UTextFuncs kTextUTF16Funcs = { |
| 522 sizeof(UTextFuncs), 0, 0, 0, TextClone, TextNativeLength, | 524 sizeof(UTextFuncs), 0, 0, 0, TextClone, TextNativeLength, |
| 523 TextUTF16Access, TextExtract, 0, 0, 0, 0, | 525 TextUTF16Access, TextExtract, 0, 0, 0, 0, |
| 524 TextClose, 0, 0, 0, | 526 TextClose, 0, 0, 0, |
| 525 }; | 527 }; |
| 526 | 528 |
| 527 static UText* TextOpenUTF16(UText* text, | 529 static UText* TextOpenUTF16(UText* text, |
| 528 const UChar* string, | 530 const UChar* string, |
| 529 unsigned length, | 531 unsigned length, |
| 530 const UChar* prior_context, | 532 const UChar* prior_context, |
| 531 int prior_context_length, | 533 int prior_context_length, |
| 532 UErrorCode* status) { | 534 UErrorCode* status) { |
| 533 if (U_FAILURE(*status)) | 535 if (U_FAILURE(*status)) |
| 534 return 0; | 536 return 0; |
| 535 | 537 |
| 536 if (!string || | 538 if (!string || |
| 537 length > static_cast<unsigned>(std::numeric_limits<int32_t>::max())) { | 539 length > static_cast<unsigned>(std::numeric_limits<int32_t>::max())) { |
| 538 *status = U_ILLEGAL_ARGUMENT_ERROR; | 540 *status = U_ILLEGAL_ARGUMENT_ERROR; |
| 539 return 0; | 541 return 0; |
| 540 } | 542 } |
| 541 | 543 |
| 542 text = utext_setup(text, 0, status); | 544 text = utext_setup(text, 0, status); |
| 543 if (U_FAILURE(*status)) { | 545 if (U_FAILURE(*status)) { |
| 544 ASSERT(!text); | 546 DCHECK(!text); |
| 545 return 0; | 547 return 0; |
| 546 } | 548 } |
| 547 TextInit(text, &kTextUTF16Funcs, string, length, prior_context, | 549 TextInit(text, &kTextUTF16Funcs, string, length, prior_context, |
| 548 prior_context_length); | 550 prior_context_length); |
| 549 return text; | 551 return text; |
| 550 } | 552 } |
| 551 | 553 |
| 552 static UText g_empty_text = UTEXT_INITIALIZER; | 554 static UText g_empty_text = UTEXT_INITIALIZER; |
| 553 | 555 |
| 554 static TextBreakIterator* WordBreakIterator(const LChar* string, int length) { | 556 static TextBreakIterator* WordBreakIterator(const LChar* string, int length) { |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 "$Tel1 $TelV $Tel0;" // Telugu Virama (backward) | 940 "$Tel1 $TelV $Tel0;" // Telugu Virama (backward) |
| 939 "$Kan1 $KanV $Kan0;" // Kannada Virama (backward) | 941 "$Kan1 $KanV $Kan0;" // Kannada Virama (backward) |
| 940 "$Mal1 $MalV $Mal0;" // Malayalam Virama (backward) | 942 "$Mal1 $MalV $Mal0;" // Malayalam Virama (backward) |
| 941 "!!safe_reverse;" | 943 "!!safe_reverse;" |
| 942 "!!safe_forward;"; | 944 "!!safe_forward;"; |
| 943 | 945 |
| 944 return SetUpIteratorWithRules(kRules, string, length); | 946 return SetUpIteratorWithRules(kRules, string, length); |
| 945 } | 947 } |
| 946 | 948 |
| 947 } // namespace blink | 949 } // namespace blink |
| OLD | NEW |