| OLD | NEW |
| 1 /* | 1 /* |
| 2 ***************************************************************************** | 2 ***************************************************************************** |
| 3 * Copyright (C) 1996-2014, International Business Machines Corporation and | 3 * Copyright (C) 1996-2015, International Business Machines Corporation and |
| 4 * others. All Rights Reserved. | 4 * others. All Rights Reserved. |
| 5 ***************************************************************************** | 5 ***************************************************************************** |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "unicode/utypes.h" | 8 #include "unicode/utypes.h" |
| 9 | 9 |
| 10 #if !UCONFIG_NO_NORMALIZATION | 10 #if !UCONFIG_NO_NORMALIZATION |
| 11 | 11 |
| 12 #include "unicode/caniter.h" | 12 #include "unicode/caniter.h" |
| 13 #include "unicode/normalizer2.h" | 13 #include "unicode/normalizer2.h" |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 UChar32 cp; | 287 UChar32 cp; |
| 288 Hashtable subpermute(status); | 288 Hashtable subpermute(status); |
| 289 if(U_FAILURE(status)) { | 289 if(U_FAILURE(status)) { |
| 290 return; | 290 return; |
| 291 } | 291 } |
| 292 subpermute.setValueDeleter(uprv_deleteUObject); | 292 subpermute.setValueDeleter(uprv_deleteUObject); |
| 293 | 293 |
| 294 for (i = 0; i < source.length(); i += U16_LENGTH(cp)) { | 294 for (i = 0; i < source.length(); i += U16_LENGTH(cp)) { |
| 295 cp = source.char32At(i); | 295 cp = source.char32At(i); |
| 296 const UHashElement *ne = NULL; | 296 const UHashElement *ne = NULL; |
| 297 int32_t el = -1; | 297 int32_t el = UHASH_FIRST; |
| 298 UnicodeString subPermuteString = source; | 298 UnicodeString subPermuteString = source; |
| 299 | 299 |
| 300 // optimization: | 300 // optimization: |
| 301 // if the character is canonical combining class zero, | 301 // if the character is canonical combining class zero, |
| 302 // don't permute it | 302 // don't permute it |
| 303 if (skipZeros && i != 0 && u_getCombiningClass(cp) == 0) { | 303 if (skipZeros && i != 0 && u_getCombiningClass(cp) == 0) { |
| 304 //System.out.println("Skipping " + Utility.hex(UTF16.valueOf(source,
i))); | 304 //System.out.println("Skipping " + Utility.hex(UTF16.valueOf(source,
i))); |
| 305 continue; | 305 continue; |
| 306 } | 306 } |
| 307 | 307 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 | 352 |
| 353 UChar USeg[256]; | 353 UChar USeg[256]; |
| 354 int32_t segLen = segment.extract(USeg, 256, status); | 354 int32_t segLen = segment.extract(USeg, 256, status); |
| 355 getEquivalents2(&basic, USeg, segLen, status); | 355 getEquivalents2(&basic, USeg, segLen, status); |
| 356 | 356 |
| 357 // now get all the permutations | 357 // now get all the permutations |
| 358 // add only the ones that are canonically equivalent | 358 // add only the ones that are canonically equivalent |
| 359 // TODO: optimize by not permuting any class zero. | 359 // TODO: optimize by not permuting any class zero. |
| 360 | 360 |
| 361 const UHashElement *ne = NULL; | 361 const UHashElement *ne = NULL; |
| 362 int32_t el = -1; | 362 int32_t el = UHASH_FIRST; |
| 363 //Iterator it = basic.iterator(); | 363 //Iterator it = basic.iterator(); |
| 364 ne = basic.nextElement(el); | 364 ne = basic.nextElement(el); |
| 365 //while (it.hasNext()) | 365 //while (it.hasNext()) |
| 366 while (ne != NULL) { | 366 while (ne != NULL) { |
| 367 //String item = (String) it.next(); | 367 //String item = (String) it.next(); |
| 368 UnicodeString item = *((UnicodeString *)(ne->value.pointer)); | 368 UnicodeString item = *((UnicodeString *)(ne->value.pointer)); |
| 369 | 369 |
| 370 permutations.removeAll(); | 370 permutations.removeAll(); |
| 371 permute(item, CANITER_SKIP_ZEROES, &permutations, status); | 371 permute(item, CANITER_SKIP_ZEROES, &permutations, status); |
| 372 const UHashElement *ne2 = NULL; | 372 const UHashElement *ne2 = NULL; |
| 373 int32_t el2 = -1; | 373 int32_t el2 = UHASH_FIRST; |
| 374 //Iterator it2 = permutations.iterator(); | 374 //Iterator it2 = permutations.iterator(); |
| 375 ne2 = permutations.nextElement(el2); | 375 ne2 = permutations.nextElement(el2); |
| 376 //while (it2.hasNext()) | 376 //while (it2.hasNext()) |
| 377 while (ne2 != NULL) { | 377 while (ne2 != NULL) { |
| 378 //String possible = (String) it2.next(); | 378 //String possible = (String) it2.next(); |
| 379 //UnicodeString *possible = new UnicodeString(*((UnicodeString *)(ne
2->value.pointer))); | 379 //UnicodeString *possible = new UnicodeString(*((UnicodeString *)(ne
2->value.pointer))); |
| 380 UnicodeString possible(*((UnicodeString *)(ne2->value.pointer))); | 380 UnicodeString possible(*((UnicodeString *)(ne2->value.pointer))); |
| 381 UnicodeString attempt; | 381 UnicodeString attempt; |
| 382 nfd.normalize(possible, attempt, status); | 382 nfd.normalize(possible, attempt, status); |
| 383 | 383 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 409 status = U_MEMORY_ALLOCATION_ERROR; | 409 status = U_MEMORY_ALLOCATION_ERROR; |
| 410 return NULL; | 410 return NULL; |
| 411 } | 411 } |
| 412 } | 412 } |
| 413 else { | 413 else { |
| 414 status = U_ILLEGAL_ARGUMENT_ERROR; | 414 status = U_ILLEGAL_ARGUMENT_ERROR; |
| 415 return NULL; | 415 return NULL; |
| 416 } | 416 } |
| 417 //result.toArray(finalResult); | 417 //result.toArray(finalResult); |
| 418 result_len = 0; | 418 result_len = 0; |
| 419 el = -1; | 419 el = UHASH_FIRST; |
| 420 ne = result.nextElement(el); | 420 ne = result.nextElement(el); |
| 421 while(ne != NULL) { | 421 while(ne != NULL) { |
| 422 finalResult[result_len++] = *((UnicodeString *)(ne->value.pointer)); | 422 finalResult[result_len++] = *((UnicodeString *)(ne->value.pointer)); |
| 423 ne = result.nextElement(el); | 423 ne = result.nextElement(el); |
| 424 } | 424 } |
| 425 | 425 |
| 426 | 426 |
| 427 return finalResult; | 427 return finalResult; |
| 428 } | 428 } |
| 429 | 429 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 456 Hashtable remainder(status); | 456 Hashtable remainder(status); |
| 457 remainder.setValueDeleter(uprv_deleteUObject); | 457 remainder.setValueDeleter(uprv_deleteUObject); |
| 458 if (extract(&remainder, cp2, segment, segLen, i, status) == NULL) { | 458 if (extract(&remainder, cp2, segment, segLen, i, status) == NULL) { |
| 459 continue; | 459 continue; |
| 460 } | 460 } |
| 461 | 461 |
| 462 // there were some matches, so add all the possibilities to the set. | 462 // there were some matches, so add all the possibilities to the set. |
| 463 UnicodeString prefix(segment, i); | 463 UnicodeString prefix(segment, i); |
| 464 prefix += cp2; | 464 prefix += cp2; |
| 465 | 465 |
| 466 int32_t el = -1; | 466 int32_t el = UHASH_FIRST; |
| 467 const UHashElement *ne = remainder.nextElement(el); | 467 const UHashElement *ne = remainder.nextElement(el); |
| 468 while (ne != NULL) { | 468 while (ne != NULL) { |
| 469 UnicodeString item = *((UnicodeString *)(ne->value.pointer)); | 469 UnicodeString item = *((UnicodeString *)(ne->value.pointer)); |
| 470 UnicodeString *toAdd = new UnicodeString(prefix); | 470 UnicodeString *toAdd = new UnicodeString(prefix); |
| 471 /* test for NULL */ | 471 /* test for NULL */ |
| 472 if (toAdd == 0) { | 472 if (toAdd == 0) { |
| 473 status = U_MEMORY_ALLOCATION_ERROR; | 473 status = U_MEMORY_ALLOCATION_ERROR; |
| 474 return NULL; | 474 return NULL; |
| 475 } | 475 } |
| 476 *toAdd += item; | 476 *toAdd += item; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 501 //if (PROGRESS) printf("%s, %i\n", UToS(Tr(segment)), segmentPos); | 501 //if (PROGRESS) printf("%s, %i\n", UToS(Tr(segment)), segmentPos); |
| 502 | 502 |
| 503 if (U_FAILURE(status)) { | 503 if (U_FAILURE(status)) { |
| 504 return NULL; | 504 return NULL; |
| 505 } | 505 } |
| 506 | 506 |
| 507 UnicodeString temp(comp); | 507 UnicodeString temp(comp); |
| 508 int32_t inputLen=temp.length(); | 508 int32_t inputLen=temp.length(); |
| 509 UnicodeString decompString; | 509 UnicodeString decompString; |
| 510 nfd.normalize(temp, decompString, status); | 510 nfd.normalize(temp, decompString, status); |
| 511 if (U_FAILURE(status)) { |
| 512 return NULL; |
| 513 } |
| 514 if (decompString.isBogus()) { |
| 515 status = U_MEMORY_ALLOCATION_ERROR; |
| 516 return NULL; |
| 517 } |
| 511 const UChar *decomp=decompString.getBuffer(); | 518 const UChar *decomp=decompString.getBuffer(); |
| 512 int32_t decompLen=decompString.length(); | 519 int32_t decompLen=decompString.length(); |
| 513 | 520 |
| 514 // See if it matches the start of segment (at segmentPos) | 521 // See if it matches the start of segment (at segmentPos) |
| 515 UBool ok = FALSE; | 522 UBool ok = FALSE; |
| 516 UChar32 cp; | 523 UChar32 cp; |
| 517 int32_t decompPos = 0; | 524 int32_t decompPos = 0; |
| 518 UChar32 decompCp; | 525 UChar32 decompCp; |
| 519 U16_NEXT(decomp, decompPos, decompLen, decompCp); | 526 U16_NEXT(decomp, decompPos, decompLen, decompCp); |
| 520 | 527 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 if(U_FAILURE(status) || trial.compare(segment+segmentPos, segLen - segmentPo
s) != 0) { | 575 if(U_FAILURE(status) || trial.compare(segment+segmentPos, segLen - segmentPo
s) != 0) { |
| 569 return NULL; | 576 return NULL; |
| 570 } | 577 } |
| 571 | 578 |
| 572 return getEquivalents2(fillinResult, temp.getBuffer()+inputLen, temp.length(
)-inputLen, status); | 579 return getEquivalents2(fillinResult, temp.getBuffer()+inputLen, temp.length(
)-inputLen, status); |
| 573 } | 580 } |
| 574 | 581 |
| 575 U_NAMESPACE_END | 582 U_NAMESPACE_END |
| 576 | 583 |
| 577 #endif /* #if !UCONFIG_NO_NORMALIZATION */ | 584 #endif /* #if !UCONFIG_NO_NORMALIZATION */ |
| OLD | NEW |