Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: pkg/intl/lib/date_format.dart

Issue 12918018: Update Intl's json data file generation to current APIs (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Also remove polyfill reversing method Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/intl/tool/generate_locale_data_files.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // TODO(efortuna): Customized pattern system -- suggested by i18n needs 7 // TODO(efortuna): Customized pattern system -- suggested by i18n needs
8 // feedback on appropriateness. 8 // feedback on appropriateness.
9 /** 9 /**
10 * DateFormat is for formatting and parsing dates in a locale-sensitive 10 * DateFormat is for formatting and parsing dates in a locale-sensitive
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 } 551 }
552 552
553 static List get _fieldConstructors => [ 553 static List get _fieldConstructors => [
554 (pattern, parent) => new _DateFormatQuotedField(pattern, parent), 554 (pattern, parent) => new _DateFormatQuotedField(pattern, parent),
555 (pattern, parent) => new _DateFormatPatternField(pattern, parent), 555 (pattern, parent) => new _DateFormatPatternField(pattern, parent),
556 (pattern, parent) => new _DateFormatLiteralField(pattern, parent)]; 556 (pattern, parent) => new _DateFormatLiteralField(pattern, parent)];
557 557
558 /** Parse the template pattern and return a list of field objects.*/ 558 /** Parse the template pattern and return a list of field objects.*/
559 List parsePattern(String pattern) { 559 List parsePattern(String pattern) {
560 if (pattern == null) return null; 560 if (pattern == null) return null;
561 return _reverse(_parsePatternHelper(pattern)); 561 return _parsePatternHelper(pattern).reversed.toList();
562 } 562 }
563 563
564 /** Recursive helper for parsing the template pattern. */ 564 /** Recursive helper for parsing the template pattern. */
565 List _parsePatternHelper(String pattern) { 565 List _parsePatternHelper(String pattern) {
566 if (pattern.isEmpty) return []; 566 if (pattern.isEmpty) return [];
567 567
568 var matched = _match(pattern); 568 var matched = _match(pattern);
569 if (matched == null) return []; 569 if (matched == null) return [];
570 570
571 var parsed = _parsePatternHelper( 571 var parsed = _parsePatternHelper(
572 pattern.substring(matched.fullPattern().length)); 572 pattern.substring(matched.fullPattern().length));
573 parsed.add(matched); 573 parsed.add(matched);
574 return parsed; 574 return parsed;
575 } 575 }
576 576
577 /** Find elements in a string that are patterns for specific fields.*/ 577 /** Find elements in a string that are patterns for specific fields.*/
578 _DateFormatField _match(String pattern) { 578 _DateFormatField _match(String pattern) {
579 for (var i = 0; i < _matchers.length; i++) { 579 for (var i = 0; i < _matchers.length; i++) {
580 var regex = _matchers[i]; 580 var regex = _matchers[i];
581 var match = regex.firstMatch(pattern); 581 var match = regex.firstMatch(pattern);
582 if (match != null) { 582 if (match != null) {
583 return _fieldConstructors[i](match.group(0), this); 583 return _fieldConstructors[i](match.group(0), this);
584 } 584 }
585 } 585 }
586 } 586 }
587
588 /** Polyfill for missing library function. */
589 List _reverse(List list) {
Emily Fortuna 2013/03/18 22:45:15 yay!
590 // TODO(alanknight): Use standardized list reverse when implemented.
591 // See Issue 2804.
592 var result = new List();
593 for (var i = list.length-1; i >= 0; i--) {
594 result.addLast(list[i]);
595 }
596 return result;
597 }
598 } 587 }
OLDNEW
« no previous file with comments | « no previous file | pkg/intl/tool/generate_locale_data_files.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698