Index: runtime/lib/byte_array.dart |
=================================================================== |
--- runtime/lib/byte_array.dart (revision 3698) |
+++ runtime/lib/byte_array.dart (working copy) |
@@ -96,6 +96,10 @@ |
} |
void operator[]=(int index, int value) { |
+ if (value is! int || !(value >= 0 && value <= 255)) { |
cshapiro
2012/01/31 03:04:29
Why not simplify this expression?
if ((value is
Anders Johnsen
2012/01/31 03:34:56
Done.
|
+ throw const IllegalArgumentException( |
+ "value is not an integer in byte range"); |
+ } |
setUint8(index, value); |
} |
@@ -141,9 +145,36 @@ |
return this[length - 1]; |
} |
+ void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
+ if (length < 0) { |
+ throw new IllegalArgumentException("negative length $length"); |
+ } |
+ if (from is ByteArray) { |
+ _setRange(from, startFrom, start, length); |
+ } else { |
+ Arrays.copy(from, startFrom, this, start, length); |
+ } |
+ } |
+ |
+ List getRange(int start, int length) { |
+ if (length == 0) return []; |
+ Arrays.rangeCheck(this, start, length); |
+ ByteArray list = new ByteArray(length); |
+ list._setRange(this, start, 0, length); |
+ return list; |
+ } |
+ |
+ |
// Implementation |
int _length() native "ByteArray_getLength"; |
+ |
+ void _setRange(ByteArray src, |
+ int srcStart, |
+ int dstStart, |
+ int count) |
+ native "ByteArray_setRange"; |
+ |
} |