OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of intl; | 5 part of intl; |
6 /** | 6 /** |
7 * Provides the ability to format a number in a locale-specific way. The | 7 * Provides the ability to format a number in a locale-specific way. The |
8 * format is specified as a pattern using a subset of the ICU formatting | 8 * format is specified as a pattern using a subset of the ICU formatting |
9 * patterns. | 9 * patterns. |
10 * | 10 * |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 } | 303 } |
304 // Separate out the extra integer parts from the fraction part. | 304 // Separate out the extra integer parts from the fraction part. |
305 extraIntegerDigits = remainingDigits ~/ power; | 305 extraIntegerDigits = remainingDigits ~/ power; |
306 fractionPart = remainingDigits % power; | 306 fractionPart = remainingDigits % power; |
307 } | 307 } |
308 var fractionPresent = minimumFractionDigits > 0 || fractionPart > 0; | 308 var fractionPresent = minimumFractionDigits > 0 || fractionPart > 0; |
309 | 309 |
310 var integerDigits = _integerDigits(integerPart, extraIntegerDigits); | 310 var integerDigits = _integerDigits(integerPart, extraIntegerDigits); |
311 var digitLength = integerDigits.length; | 311 var digitLength = integerDigits.length; |
312 | 312 |
313 if (_hasPrintableIntegerPart(integerPart)) { | 313 if (_hasIntegerDigits(integerDigits)) { |
314 _pad(minimumIntegerDigits - digitLength); | 314 _pad(minimumIntegerDigits - digitLength); |
315 for (var i = 0; i < digitLength; i++) { | 315 for (var i = 0; i < digitLength; i++) { |
316 _addDigit(integerDigits.codeUnitAt(i)); | 316 _addDigit(integerDigits.codeUnitAt(i)); |
317 _group(digitLength, i); | 317 _group(digitLength, i); |
318 } | 318 } |
319 } else if (!fractionPresent) { | 319 } else if (!fractionPresent) { |
320 // If neither fraction nor integer part exists, just print zero. | 320 // If neither fraction nor integer part exists, just print zero. |
321 _addZero(); | 321 _addZero(); |
322 } | 322 } |
323 | 323 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 | 379 |
380 /** Print the decimal separator if appropriate. */ | 380 /** Print the decimal separator if appropriate. */ |
381 void _decimalSeparator(bool fractionPresent) { | 381 void _decimalSeparator(bool fractionPresent) { |
382 if (_decimalSeparatorAlwaysShown || fractionPresent) { | 382 if (_decimalSeparatorAlwaysShown || fractionPresent) { |
383 _add(symbols.DECIMAL_SEP); | 383 _add(symbols.DECIMAL_SEP); |
384 } | 384 } |
385 } | 385 } |
386 | 386 |
387 /** | 387 /** |
388 * Return true if we have a main integer part which is printable, either | 388 * Return true if we have a main integer part which is printable, either |
389 * because we have digits left of the decimal point, or because there are | 389 * because we have digits left of the decimal point (this may include digits |
390 * a minimum number of printable digits greater than 1. | 390 * which have been moved left because of percent or permille formatting), |
| 391 * or because the minimum number of printable digits is greater than 1. |
391 */ | 392 */ |
392 bool _hasPrintableIntegerPart(x) => | 393 bool _hasIntegerDigits(String digits) => |
393 x > 0 || minimumIntegerDigits > 0; | 394 digits.isNotEmpty || minimumIntegerDigits > 0; |
394 | 395 |
395 /** A group of methods that provide support for writing digits and other | 396 /** A group of methods that provide support for writing digits and other |
396 * required characters into [_buffer] easily. | 397 * required characters into [_buffer] easily. |
397 */ | 398 */ |
398 void _add(String x) { _buffer.write(x);} | 399 void _add(String x) { _buffer.write(x);} |
399 void _addCharCode(int x) { _buffer.writeCharCode(x);} | 400 void _addCharCode(int x) { _buffer.writeCharCode(x);} |
400 void _addZero() { _buffer.write(symbols.ZERO_DIGIT);} | 401 void _addZero() { _buffer.write(symbols.ZERO_DIGIT);} |
401 void _addDigit(int x) { _buffer.writeCharCode(_localeZero + x - _zero);} | 402 void _addDigit(int x) { _buffer.writeCharCode(_localeZero + x - _zero);} |
402 | 403 |
403 /** Print padding up to [numberOfDigits] above what's included in [basic]. */ | 404 /** Print padding up to [numberOfDigits] above what's included in [basic]. */ |
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 String get peek => nextIndex >= input.length ? null : input[nextIndex]; | 1061 String get peek => nextIndex >= input.length ? null : input[nextIndex]; |
1061 | 1062 |
1062 Iterator<String> get iterator => this; | 1063 Iterator<String> get iterator => this; |
1063 | 1064 |
1064 static String _validate(input) { | 1065 static String _validate(input) { |
1065 if (input is! String) throw new ArgumentError(input); | 1066 if (input is! String) throw new ArgumentError(input); |
1066 return input; | 1067 return input; |
1067 } | 1068 } |
1068 | 1069 |
1069 } | 1070 } |
OLD | NEW |