| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011,2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011,2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 for (size_t i = 0; i < symbols.size(); ++i) { | 241 for (size_t i = 0; i < symbols.size(); ++i) { |
| 242 ASSERT(!symbols[i].isEmpty()); | 242 ASSERT(!symbols[i].isEmpty()); |
| 243 m_decimalSymbols[i] = symbols[i]; | 243 m_decimalSymbols[i] = symbols[i]; |
| 244 } | 244 } |
| 245 m_positivePrefix = positivePrefix; | 245 m_positivePrefix = positivePrefix; |
| 246 m_positiveSuffix = positiveSuffix; | 246 m_positiveSuffix = positiveSuffix; |
| 247 m_negativePrefix = negativePrefix; | 247 m_negativePrefix = negativePrefix; |
| 248 m_negativeSuffix = negativeSuffix; | 248 m_negativeSuffix = negativeSuffix; |
| 249 ASSERT(!m_positivePrefix.isEmpty() || !m_positiveSuffix.isEmpty() || !m_nega
tivePrefix.isEmpty() || !m_negativeSuffix.isEmpty()); | 249 ASSERT(!m_positivePrefix.isEmpty() || !m_positiveSuffix.isEmpty() || !m_nega
tivePrefix.isEmpty() || !m_negativeSuffix.isEmpty()); |
| 250 m_hasLocaleData = true; | 250 m_hasLocaleData = true; |
| 251 |
| 252 StringBuilder builder; |
| 253 for (size_t i = 0; i < DecimalSymbolsSize; ++i) { |
| 254 // We don't accept group separatros. |
| 255 if (i != GroupSeparatorIndex) |
| 256 builder.append(m_decimalSymbols[i]); |
| 257 } |
| 258 builder.append(m_positivePrefix); |
| 259 builder.append(m_positiveSuffix); |
| 260 builder.append(m_negativePrefix); |
| 261 builder.append(m_negativeSuffix); |
| 262 m_acceptableNumberCharacters = builder.toString(); |
| 251 } | 263 } |
| 252 | 264 |
| 253 String Locale::convertToLocalizedNumber(const String& input) | 265 String Locale::convertToLocalizedNumber(const String& input) |
| 254 { | 266 { |
| 255 initializeLocaleData(); | 267 initializeLocaleData(); |
| 256 if (!m_hasLocaleData || input.isEmpty()) | 268 if (!m_hasLocaleData || input.isEmpty()) |
| 257 return input; | 269 return input; |
| 258 | 270 |
| 259 unsigned i = 0; | 271 unsigned i = 0; |
| 260 bool isNegative = false; | 272 bool isNegative = false; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 if (symbolIndex == DecimalSeparatorIndex) | 386 if (symbolIndex == DecimalSeparatorIndex) |
| 375 builder.append('.'); | 387 builder.append('.'); |
| 376 else if (symbolIndex == GroupSeparatorIndex) | 388 else if (symbolIndex == GroupSeparatorIndex) |
| 377 return input; | 389 return input; |
| 378 else | 390 else |
| 379 builder.append(static_cast<UChar>('0' + symbolIndex)); | 391 builder.append(static_cast<UChar>('0' + symbolIndex)); |
| 380 } | 392 } |
| 381 return builder.toString(); | 393 return builder.toString(); |
| 382 } | 394 } |
| 383 | 395 |
| 396 String Locale::stripInvalidNumberCharacters(const String& input, const String& s
tandardChars) const |
| 397 { |
| 398 StringBuilder builder; |
| 399 builder.reserveCapacity(input.length()); |
| 400 for (unsigned i = 0; i < input.length(); ++i) { |
| 401 UChar ch = input[i]; |
| 402 if (standardChars.find(ch) != kNotFound) |
| 403 builder.append(ch); |
| 404 else if (m_acceptableNumberCharacters.find(ch) != kNotFound) |
| 405 builder.append(ch); |
| 406 } |
| 407 return builder.toString(); |
| 408 } |
| 409 |
| 384 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) | 410 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) |
| 385 String Locale::localizedDecimalSeparator() | 411 String Locale::localizedDecimalSeparator() |
| 386 { | 412 { |
| 387 initializeLocaleData(); | 413 initializeLocaleData(); |
| 388 return m_decimalSymbols[DecimalSeparatorIndex]; | 414 return m_decimalSymbols[DecimalSeparatorIndex]; |
| 389 } | 415 } |
| 390 #endif | 416 #endif |
| 391 | 417 |
| 392 String Locale::formatDateTime(const DateComponents& date, FormatType formatType) | 418 String Locale::formatDateTime(const DateComponents& date, FormatType formatType) |
| 393 { | 419 { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 413 builder.build(formatType == FormatTypeShort ? dateTimeFormatWithoutSecon
ds() : dateTimeFormatWithSeconds()); | 439 builder.build(formatType == FormatTypeShort ? dateTimeFormatWithoutSecon
ds() : dateTimeFormatWithSeconds()); |
| 414 break; | 440 break; |
| 415 case DateComponents::Invalid: | 441 case DateComponents::Invalid: |
| 416 ASSERT_NOT_REACHED(); | 442 ASSERT_NOT_REACHED(); |
| 417 break; | 443 break; |
| 418 } | 444 } |
| 419 return builder.toString(); | 445 return builder.toString(); |
| 420 } | 446 } |
| 421 | 447 |
| 422 } // namespace blink | 448 } // namespace blink |
| OLD | NEW |