OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 #ifdef V8_I18N_SUPPORT | 6 #ifdef V8_I18N_SUPPORT |
7 #include "src/runtime/runtime-utils.h" | 7 #include "src/runtime/runtime-utils.h" |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/api-natives.h" | 10 #include "src/api-natives.h" |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 CONVERT_ARG_HANDLE_CHECKED(String, stringValue, 0); | 579 CONVERT_ARG_HANDLE_CHECKED(String, stringValue, 0); |
580 CONVERT_NUMBER_CHECKED(int, form_id, Int32, args[1]); | 580 CONVERT_NUMBER_CHECKED(int, form_id, Int32, args[1]); |
581 RUNTIME_ASSERT(form_id >= 0 && | 581 RUNTIME_ASSERT(form_id >= 0 && |
582 static_cast<size_t>(form_id) < arraysize(normalizationForms)); | 582 static_cast<size_t>(form_id) < arraysize(normalizationForms)); |
583 | 583 |
584 v8::String::Value string_value(v8::Utils::ToLocal(stringValue)); | 584 v8::String::Value string_value(v8::Utils::ToLocal(stringValue)); |
585 const UChar* u_value = reinterpret_cast<const UChar*>(*string_value); | 585 const UChar* u_value = reinterpret_cast<const UChar*>(*string_value); |
586 | 586 |
587 // TODO(mnita): check Normalizer2 (not available in ICU 46) | 587 // TODO(mnita): check Normalizer2 (not available in ICU 46) |
588 UErrorCode status = U_ZERO_ERROR; | 588 UErrorCode status = U_ZERO_ERROR; |
| 589 icu::UnicodeString input(false, u_value, string_value.length()); |
589 icu::UnicodeString result; | 590 icu::UnicodeString result; |
590 icu::Normalizer::normalize(u_value, normalizationForms[form_id], 0, result, | 591 icu::Normalizer::normalize(input, normalizationForms[form_id], 0, result, |
591 status); | 592 status); |
592 if (U_FAILURE(status)) { | 593 if (U_FAILURE(status)) { |
593 return isolate->heap()->undefined_value(); | 594 return isolate->heap()->undefined_value(); |
594 } | 595 } |
595 | 596 |
596 Handle<String> result_str; | 597 Handle<String> result_str; |
597 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 598 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
598 isolate, result_str, | 599 isolate, result_str, |
599 isolate->factory()->NewStringFromTwoByte(Vector<const uint16_t>( | 600 isolate->factory()->NewStringFromTwoByte(Vector<const uint16_t>( |
600 reinterpret_cast<const uint16_t*>(result.getBuffer()), | 601 reinterpret_cast<const uint16_t*>(result.getBuffer()), |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 } else if (status >= UBRK_WORD_IDEO && status < UBRK_WORD_IDEO_LIMIT) { | 746 } else if (status >= UBRK_WORD_IDEO && status < UBRK_WORD_IDEO_LIMIT) { |
746 return *isolate->factory()->NewStringFromStaticChars("ideo"); | 747 return *isolate->factory()->NewStringFromStaticChars("ideo"); |
747 } else { | 748 } else { |
748 return *isolate->factory()->NewStringFromStaticChars("unknown"); | 749 return *isolate->factory()->NewStringFromStaticChars("unknown"); |
749 } | 750 } |
750 } | 751 } |
751 } // namespace internal | 752 } // namespace internal |
752 } // namespace v8 | 753 } // namespace v8 |
753 | 754 |
754 #endif // V8_I18N_SUPPORT | 755 #endif // V8_I18N_SUPPORT |
OLD | NEW |