OLD | NEW |
1 // Copyright 2011 the v8-i18n authors. | 1 // Copyright 2011 the v8-i18n authors. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 static bool BCP47ToICUFormat(const char* locale_id, char* result) { | 180 static bool BCP47ToICUFormat(const char* locale_id, char* result) { |
181 UErrorCode status = U_ZERO_ERROR; | 181 UErrorCode status = U_ZERO_ERROR; |
182 int32_t locale_size = 0; | 182 int32_t locale_size = 0; |
183 | 183 |
184 char locale[ULOC_FULLNAME_CAPACITY]; | 184 char locale[ULOC_FULLNAME_CAPACITY]; |
185 Utils::StrNCopy(locale, ULOC_FULLNAME_CAPACITY, locale_id); | 185 Utils::StrNCopy(locale, ULOC_FULLNAME_CAPACITY, locale_id); |
186 | 186 |
187 // uloc_forLanguageTag has a bug where long extension can crash the code. | 187 // uloc_forLanguageTag has a bug where long extension can crash the code. |
188 // We need to check if extension part of language id conforms to the length. | 188 // We need to check if extension part of language id conforms to the length. |
189 // ICU bug: http://bugs.icu-project.org/trac/ticket/8519 | 189 // ICU bug: http://bugs.icu-project.org/trac/ticket/8519 |
190 const char* extension = strstr(locale_id, "-u-"); | 190 const char* extension = strstr(locale, "-u-"); |
191 if (extension != NULL && | 191 if (extension != NULL && |
192 strlen(extension) > ULOC_KEYWORD_AND_VALUES_CAPACITY) { | 192 strlen(extension) > ULOC_KEYWORD_AND_VALUES_CAPACITY) { |
193 // Truncate to get non-crashing string, but still preserve base language. | 193 // Truncate to get non-crashing string, but still preserve base language. |
194 int base_length = strlen(locale_id) - strlen(extension); | 194 int base_length = strlen(locale) - strlen(extension); |
195 locale[base_length] = '\0'; | 195 locale[base_length] = '\0'; |
196 } | 196 } |
197 | 197 |
198 uloc_forLanguageTag(locale, result, ULOC_FULLNAME_CAPACITY, | 198 uloc_forLanguageTag(locale, result, ULOC_FULLNAME_CAPACITY, |
199 &locale_size, &status); | 199 &locale_size, &status); |
200 return !U_FAILURE(status); | 200 return !U_FAILURE(status); |
201 } | 201 } |
202 | 202 |
203 // Compares locale id subtags. | 203 // Compares locale id subtags. |
204 // Returns 1 for match or -1 for mismatch. | 204 // Returns 1 for match or -1 for mismatch. |
(...skipping 24 matching lines...) Expand all Loading... |
229 } | 229 } |
230 | 230 |
231 // Convert ICU locale name into BCP47 format. | 231 // Convert ICU locale name into BCP47 format. |
232 UErrorCode status = U_ZERO_ERROR; | 232 UErrorCode status = U_ZERO_ERROR; |
233 uloc_toLanguageTag(result->icu_id, result->bcp47_id, | 233 uloc_toLanguageTag(result->icu_id, result->bcp47_id, |
234 ULOC_FULLNAME_CAPACITY, false, &status); | 234 ULOC_FULLNAME_CAPACITY, false, &status); |
235 return !U_FAILURE(status); | 235 return !U_FAILURE(status); |
236 } | 236 } |
237 | 237 |
238 } // namespace v8_i18n | 238 } // namespace v8_i18n |
OLD | NEW |