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

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

Issue 11086033: Make verifiedLocale work differently depending on what it's verifying for (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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
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 #library("number_format"); 5 #library("number_format");
6 6
7 #import('dart:math'); 7 #import('dart:math');
8 8
9 #import("intl.dart"); 9 #import("intl.dart");
10 #import("number_symbols.dart"); 10 #import("number_symbols.dart");
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 * of formatting then there will only ever be one number being formatted 45 * of formatting then there will only ever be one number being formatted
46 * at a time. In languages with threads we'd need to pass this on the stack. 46 * at a time. In languages with threads we'd need to pass this on the stack.
47 */ 47 */
48 StringBuffer _buffer; 48 StringBuffer _buffer;
49 49
50 /** 50 /**
51 * Create a number format that prints in [newPattern] as it applies in 51 * Create a number format that prints in [newPattern] as it applies in
52 * [locale]. 52 * [locale].
53 */ 53 */
54 NumberFormat([String newPattern, String locale]): 54 NumberFormat([String newPattern, String locale]):
55 _locale = Intl.verifiedLocale(locale) { 55 _locale = Intl.verifiedLocale(locale, localeExists) {
56 // TODO(alanknight): There will need to be some kind of async setup 56 // TODO(alanknight): There will need to be some kind of async setup
57 // operations so as not to bring along every locale in every program. 57 // operations so as not to bring along every locale in every program.
58 _symbols = numberFormatSymbols[_locale]; 58 _symbols = numberFormatSymbols[_locale];
59 _setPattern(newPattern); 59 _setPattern(newPattern);
60 } 60 }
61 61
62 /** 62 /**
63 * Return the locale code in which we operate, e.g. 'en_US' or 'pt'. 63 * Return the locale code in which we operate, e.g. 'en_US' or 'pt'.
64 */ 64 */
65 String get locale => _locale; 65 String get locale => _locale;
66 66
67 /** 67 /**
68 * Return true if the locale exists, or if it is null. The null case
69 * is interpreted to mean that we use the default locale.
70 */
71 static bool localeExists(localeName) {
72 if (localeName == null) return false;
73 return numberFormatSymbols.containsKey(localeName);
74 }
75
76 /**
68 * Return the symbols which are used in our locale. Cache them to avoid 77 * Return the symbols which are used in our locale. Cache them to avoid
69 * repeated lookup. 78 * repeated lookup.
70 */ 79 */
71 NumberSymbols get symbols { 80 NumberSymbols get symbols {
72 return _symbols; 81 return _symbols;
73 } 82 }
74 83
75 // TODO(alanknight): Actually use the pattern and locale. 84 // TODO(alanknight): Actually use the pattern and locale.
76 _setPattern(String x) {} 85 _setPattern(String x) {}
77 86
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 } 272 }
264 273
265 /** 274 /**
266 * Returns the suffix for [x] based on wether it's positive or negative. 275 * Returns the suffix for [x] based on wether it's positive or negative.
267 * In en_US there are no suffixes for positive or negative. 276 * In en_US there are no suffixes for positive or negative.
268 */ 277 */
269 String _signSuffix(num x) { 278 String _signSuffix(num x) {
270 return x.isNegative() ? _negativeSuffix : _positiveSuffix; 279 return x.isNegative() ? _negativeSuffix : _positiveSuffix;
271 } 280 }
272 } 281 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698