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

Side by Side Diff: runtime/lib/integers_patch.dart

Issue 50983002: Implement fromEnvironment on bool, int and String (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments Created 7 years, 1 month 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 // Dart core library. 4 // Dart core library.
5 5
6 // VM implementation of int. 6 // VM implementation of int.
7 7
8 patch class int { 8 patch class int {
9 9
10 static bool _isWhitespace(int codePoint) { 10 static bool _isWhitespace(int codePoint) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 if (onError == null) { 80 if (onError == null) {
81 throw new FormatException(source); 81 throw new FormatException(source);
82 } 82 }
83 return onError(source); 83 return onError(source);
84 } 84 }
85 return result; 85 return result;
86 } 86 }
87 return _slowParse(source, radix, onError); 87 return _slowParse(source, radix, onError);
88 } 88 }
89 89
90 /* patch */ const factory int.fromEnvironment(String name,
91 {int defaultValue})
92 native "Integer_fromEnvironment";
93
90 static int _slowParse(String source, int radix, int onError(String str)) { 94 static int _slowParse(String source, int radix, int onError(String str)) {
91 if (source is! String) throw new ArgumentError(source); 95 if (source is! String) throw new ArgumentError(source);
92 if (radix is! int) throw new ArgumentError("Radix is not an integer"); 96 if (radix is! int) throw new ArgumentError("Radix is not an integer");
93 if (radix < 2 || radix > 36) { 97 if (radix < 2 || radix > 36) {
94 throw new RangeError("Radix $radix not in range 2..36"); 98 throw new RangeError("Radix $radix not in range 2..36");
95 } 99 }
96 if (onError == null) { 100 if (onError == null) {
97 onError = _throwFormatException; 101 onError = _throwFormatException;
98 } 102 }
99 // Remove leading and trailing white space. 103 // Remove leading and trailing white space.
(...skipping 27 matching lines...) Expand all
127 int digit = digits[code - 0x30]; 131 int digit = digits[code - 0x30];
128 if (digit >= radix) return onError(source); 132 if (digit >= radix) return onError(source);
129 result = result * radix + digit; 133 result = result * radix + digit;
130 i++; 134 i++;
131 if (i == source.length) break; 135 if (i == source.length) break;
132 code = source.codeUnitAt(i); 136 code = source.codeUnitAt(i);
133 } while (true); 137 } while (true);
134 return negative ? -result : result; 138 return negative ? -result : result;
135 } 139 }
136 } 140 }
OLDNEW
« no previous file with comments | « runtime/lib/integers.cc ('k') | runtime/lib/string.cc » ('j') | sdk/lib/core/bool.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698