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

Unified Diff: sdk/lib/convert/utf.dart

Issue 745573002: Create generic check methods for RangeError causing checks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix long line Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/convert/latin1.dart ('k') | sdk/lib/core/errors.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/convert/utf.dart
diff --git a/sdk/lib/convert/utf.dart b/sdk/lib/convert/utf.dart
index a5b6558ed0f0c7fb9d4d6b8027f2b39fdf270b94..d16d2c67d399774e25372684723764a7bbf542d2 100644
--- a/sdk/lib/convert/utf.dart
+++ b/sdk/lib/convert/utf.dart
@@ -89,14 +89,8 @@ class Utf8Encoder extends Converter<String, List<int>> {
*/
List<int> convert(String string, [int start = 0, int end]) {
int stringLength = string.length;
- if (start < 0 || start > stringLength) {
- throw new RangeError.range(start, 0, stringLength, "start");
- }
- if (end == null) {
- end = stringLength;
- } else if (end < start || end > stringLength) {
- throw new RangeError.range(end, start, stringLength, "end");
- }
+ RangeError.checkValidRange(start, end, stringLength);
+ if (end == null) end = stringLength;
int length = end - start;
if (length == 0) return new Uint8List(0);
// Create a new encoder with a length that is guaranteed to be big enough.
@@ -338,14 +332,8 @@ class Utf8Decoder extends Converter<List<int>, String> {
*/
String convert(List<int> codeUnits, [int start = 0, int end]) {
int length = codeUnits.length;
- if (start < 0 || start > length) {
- throw new RangeError.range(start, 0, length, "start");
- }
- if (end == null) {
- end = length;
- } else if (end < start || end > length) {
- throw new RangeError.range(end, start, length, "end");
- }
+ RangeError.checkValidRange(start, end, length);
+ if (end == null) end = length;
StringBuffer buffer = new StringBuffer();
_Utf8Decoder decoder = new _Utf8Decoder(buffer, _allowMalformed);
decoder.convert(codeUnits, start, end);
« no previous file with comments | « sdk/lib/convert/latin1.dart ('k') | sdk/lib/core/errors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698