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 <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 namespace { | 858 namespace { |
859 MUST_USE_RESULT Object* LocaleConvertCase(Handle<String> s, Isolate* isolate, | 859 MUST_USE_RESULT Object* LocaleConvertCase(Handle<String> s, Isolate* isolate, |
860 bool is_to_upper, const char* lang) { | 860 bool is_to_upper, const char* lang) { |
861 auto case_converter = is_to_upper ? u_strToUpper : u_strToLower; | 861 auto case_converter = is_to_upper ? u_strToUpper : u_strToLower; |
862 int32_t src_length = s->length(); | 862 int32_t src_length = s->length(); |
863 int32_t dest_length = src_length; | 863 int32_t dest_length = src_length; |
864 UErrorCode status; | 864 UErrorCode status; |
865 Handle<SeqTwoByteString> result; | 865 Handle<SeqTwoByteString> result; |
866 std::unique_ptr<uc16[]> sap; | 866 std::unique_ptr<uc16[]> sap; |
867 | 867 |
868 if (dest_length == 0) return isolate->heap()->empty_string(); | |
869 | |
870 // This is not a real loop. It'll be executed only once (no overflow) or | 868 // This is not a real loop. It'll be executed only once (no overflow) or |
871 // twice (overflow). | 869 // twice (overflow). |
872 for (int i = 0; i < 2; ++i) { | 870 for (int i = 0; i < 2; ++i) { |
873 // Case conversion can increase the string length (e.g. sharp-S => SS) so | 871 // Case conversion can increase the string length (e.g. sharp-S => SS) so |
874 // that we have to handle RangeError exceptions here. | 872 // that we have to handle RangeError exceptions here. |
875 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 873 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
876 isolate, result, isolate->factory()->NewRawTwoByteString(dest_length)); | 874 isolate, result, isolate->factory()->NewRawTwoByteString(dest_length)); |
877 DisallowHeapAllocation no_gc; | 875 DisallowHeapAllocation no_gc; |
878 String::FlatContent flat = s->GetFlatContent(); | 876 String::FlatContent flat = s->GetFlatContent(); |
879 const UChar* src = GetUCharBufferFromFlat(flat, &sap, src_length); | 877 const UChar* src = GetUCharBufferFromFlat(flat, &sap, src_length); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1068 for (int index = index_to_first_unprocessed; index < length; ++index) { | 1066 for (int index = index_to_first_unprocessed; index < length; ++index) { |
1069 dest[index] = ToLatin1Lower(static_cast<uint16_t>(src[index])); | 1067 dest[index] = ToLatin1Lower(static_cast<uint16_t>(src[index])); |
1070 } | 1068 } |
1071 } | 1069 } |
1072 | 1070 |
1073 return *result; | 1071 return *result; |
1074 } | 1072 } |
1075 | 1073 |
1076 MUST_USE_RESULT Object* ConvertToUpper(Handle<String> s, Isolate* isolate) { | 1074 MUST_USE_RESULT Object* ConvertToUpper(Handle<String> s, Isolate* isolate) { |
1077 int32_t length = s->length(); | 1075 int32_t length = s->length(); |
1078 if (s->HasOnlyOneByteChars() && length > 0) { | 1076 if (s->HasOnlyOneByteChars()) { |
1079 Handle<SeqOneByteString> result = | 1077 Handle<SeqOneByteString> result = |
1080 isolate->factory()->NewRawOneByteString(length).ToHandleChecked(); | 1078 isolate->factory()->NewRawOneByteString(length).ToHandleChecked(); |
1081 | 1079 |
1082 int sharp_s_count; | 1080 int sharp_s_count; |
1083 bool is_result_single_byte; | 1081 bool is_result_single_byte; |
1084 { | 1082 { |
1085 DisallowHeapAllocation no_gc; | 1083 DisallowHeapAllocation no_gc; |
1086 String::FlatContent flat = s->GetFlatContent(); | 1084 String::FlatContent flat = s->GetFlatContent(); |
1087 uint8_t* dest = result->GetChars(); | 1085 uint8_t* dest = result->GetChars(); |
1088 if (flat.IsOneByte()) { | 1086 if (flat.IsOneByte()) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1209 Handle<FixedArray> date_cache_version = | 1207 Handle<FixedArray> date_cache_version = |
1210 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton( | 1208 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton( |
1211 EternalHandles::DATE_CACHE_VERSION)); | 1209 EternalHandles::DATE_CACHE_VERSION)); |
1212 return date_cache_version->get(0); | 1210 return date_cache_version->get(0); |
1213 } | 1211 } |
1214 | 1212 |
1215 } // namespace internal | 1213 } // namespace internal |
1216 } // namespace v8 | 1214 } // namespace v8 |
1217 | 1215 |
1218 #endif // V8_I18N_SUPPORT | 1216 #endif // V8_I18N_SUPPORT |
OLD | NEW |