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 /** | 5 /** |
6 * This is a private class internal to DateFormat which is used for formatting | 6 * This is a private class internal to DateFormat which is used for formatting |
7 * particular fields in a template. e.g. if the format is hh:mm:ss then the | 7 * particular fields in a template. e.g. if the format is hh:mm:ss then the |
8 * fields would be "hh", ":", "mm", ":", and "ss". Each type of field knows | 8 * fields would be "hh", ":", "mm", ":", and "ss". Each type of field knows |
9 * how to format that portion of a date. | 9 * how to format that portion of a date. |
10 */ | 10 */ |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 * We are given [input] as a stream from which we want to read a date. We | 212 * We are given [input] as a stream from which we want to read a date. We |
213 * can't dynamically build up a date, so we are given a list [dateFields] of | 213 * can't dynamically build up a date, so we are given a list [dateFields] of |
214 * the constructor arguments and an [position] at which to set it | 214 * the constructor arguments and an [position] at which to set it |
215 * (year,month,day,hour,minute,second,fractionalSecond) | 215 * (year,month,day,hour,minute,second,fractionalSecond) |
216 * then after all parsing is done we construct a date from the arguments. | 216 * then after all parsing is done we construct a date from the arguments. |
217 * This method handles reading any of string fields from an enumerated set. | 217 * This method handles reading any of string fields from an enumerated set. |
218 */ | 218 */ |
219 int parseEnumeratedString(_Stream input, List possibilities) { | 219 int parseEnumeratedString(_Stream input, List possibilities) { |
220 var results = new _Stream(possibilities).findIndexes( | 220 var results = new _Stream(possibilities).findIndexes( |
221 (each) => input.peek(each.length) == each); | 221 (each) => input.peek(each.length) == each); |
222 if (results.isEmpty()) throwFormatException(input); | 222 if (results.isEmpty) throwFormatException(input); |
223 results.sort( | 223 results.sort( |
224 (a, b) => possibilities[a].length.compareTo(possibilities[b].length)); | 224 (a, b) => possibilities[a].length.compareTo(possibilities[b].length)); |
225 var longestResult = results.last(); | 225 var longestResult = results.last(); |
226 input.read(possibilities[longestResult].length); | 226 input.read(possibilities[longestResult].length); |
227 return longestResult; | 227 return longestResult; |
228 } | 228 } |
229 | 229 |
230 String formatMonth(Date date) { | 230 String formatMonth(Date date) { |
231 switch (width) { | 231 switch (width) { |
232 case 5: return symbols.NARROWMONTHS[date.month-1]; | 232 case 5: return symbols.NARROWMONTHS[date.month-1]; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 var basicString = toBePrinted.toString(); | 395 var basicString = toBePrinted.toString(); |
396 if (basicString.length >= width) return basicString; | 396 if (basicString.length >= width) return basicString; |
397 var buffer = new StringBuffer(); | 397 var buffer = new StringBuffer(); |
398 for (var i = 0; i < width - basicString.length; i++) { | 398 for (var i = 0; i < width - basicString.length; i++) { |
399 buffer.add('0'); | 399 buffer.add('0'); |
400 } | 400 } |
401 buffer.add(basicString); | 401 buffer.add(basicString); |
402 return buffer.toString(); | 402 return buffer.toString(); |
403 } | 403 } |
404 } | 404 } |
OLD | NEW |