| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 return DateTimeFormat::parse(formatString, *this); | 75 return DateTimeFormat::parse(formatString, *this); |
| 76 } | 76 } |
| 77 | 77 |
| 78 String DateTimeStringBuilder::zeroPadString(const String& string, size_t width) | 78 String DateTimeStringBuilder::zeroPadString(const String& string, size_t width) |
| 79 { | 79 { |
| 80 if (string.length() >= width) | 80 if (string.length() >= width) |
| 81 return string; | 81 return string; |
| 82 StringBuilder zeroPaddedStringBuilder; | 82 StringBuilder zeroPaddedStringBuilder; |
| 83 zeroPaddedStringBuilder.reserveCapacity(width); | 83 zeroPaddedStringBuilder.reserveCapacity(width); |
| 84 for (size_t i = string.length(); i < width; ++i) | 84 for (size_t i = string.length(); i < width; ++i) |
| 85 zeroPaddedStringBuilder.append("0"); | 85 zeroPaddedStringBuilder.append('0'); |
| 86 zeroPaddedStringBuilder.append(string); | 86 zeroPaddedStringBuilder.append(string); |
| 87 return zeroPaddedStringBuilder.toString(); | 87 return zeroPaddedStringBuilder.toString(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void DateTimeStringBuilder::appendNumber(int number, size_t width) | 90 void DateTimeStringBuilder::appendNumber(int number, size_t width) |
| 91 { | 91 { |
| 92 String zeroPaddedNumberString = zeroPadString(String::number(number), width)
; | 92 String zeroPaddedNumberString = zeroPadString(String::number(number), width)
; |
| 93 m_builder.append(m_localizer.convertToLocalizedNumber(zeroPaddedNumberString
)); | 93 m_builder.append(m_localizer.convertToLocalizedNumber(zeroPaddedNumberString
)); |
| 94 } | 94 } |
| 95 | 95 |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 | 357 |
| 358 bool isNegative; | 358 bool isNegative; |
| 359 unsigned startIndex; | 359 unsigned startIndex; |
| 360 unsigned endIndex; | 360 unsigned endIndex; |
| 361 if (!detectSignAndGetDigitRange(input, isNegative, startIndex, endIndex)) | 361 if (!detectSignAndGetDigitRange(input, isNegative, startIndex, endIndex)) |
| 362 return input; | 362 return input; |
| 363 | 363 |
| 364 StringBuilder builder; | 364 StringBuilder builder; |
| 365 builder.reserveCapacity(input.length()); | 365 builder.reserveCapacity(input.length()); |
| 366 if (isNegative) | 366 if (isNegative) |
| 367 builder.append("-"); | 367 builder.append('-'); |
| 368 for (unsigned i = startIndex; i < endIndex;) { | 368 for (unsigned i = startIndex; i < endIndex;) { |
| 369 unsigned symbolIndex = matchedDecimalSymbolIndex(input, i); | 369 unsigned symbolIndex = matchedDecimalSymbolIndex(input, i); |
| 370 if (symbolIndex >= DecimalSymbolsSize) | 370 if (symbolIndex >= DecimalSymbolsSize) |
| 371 return input; | 371 return input; |
| 372 if (symbolIndex == DecimalSeparatorIndex) | 372 if (symbolIndex == DecimalSeparatorIndex) |
| 373 builder.append('.'); | 373 builder.append('.'); |
| 374 else if (symbolIndex == GroupSeparatorIndex) | 374 else if (symbolIndex == GroupSeparatorIndex) |
| 375 return input; | 375 return input; |
| 376 else | 376 else |
| 377 builder.append(static_cast<UChar>('0' + symbolIndex)); | 377 builder.append(static_cast<UChar>('0' + symbolIndex)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 builder.build(formatType == FormatTypeShort ? dateTimeFormatWithoutSecon
ds() : dateTimeFormatWithSeconds()); | 411 builder.build(formatType == FormatTypeShort ? dateTimeFormatWithoutSecon
ds() : dateTimeFormatWithSeconds()); |
| 412 break; | 412 break; |
| 413 case DateComponents::Invalid: | 413 case DateComponents::Invalid: |
| 414 ASSERT_NOT_REACHED(); | 414 ASSERT_NOT_REACHED(); |
| 415 break; | 415 break; |
| 416 } | 416 } |
| 417 return builder.toString(); | 417 return builder.toString(); |
| 418 } | 418 } |
| 419 | 419 |
| 420 } | 420 } |
| OLD | NEW |