1
1
import 'constants.dart' ;
2
2
import 'html_input_stream.dart' ;
3
3
4
- // TODO(jmesserly): I converted StopIteration to StateError("No more elements").
5
- // Seems strange to throw this from outside of an iterator though.
6
- /// String-like object with an associated position and various extra methods
4
+ /// String-like object with an associated position and various extra methods.
5
+ ///
7
6
/// If the position is ever greater than the string length then an exception is
8
7
/// raised.
9
8
class EncodingBytes {
@@ -17,7 +16,7 @@ class EncodingBytes {
17
16
String _next () {
18
17
final p = __position = __position + 1 ;
19
18
if (p >= _length) {
20
- throw StateError ('No more elements' );
19
+ throw _EncodingRangeException ('No more elements' );
21
20
} else if (p < 0 ) {
22
21
throw RangeError (p);
23
22
}
@@ -27,7 +26,7 @@ class EncodingBytes {
27
26
String _previous () {
28
27
var p = __position;
29
28
if (p >= _length) {
30
- throw StateError ('No more elements' );
29
+ throw _EncodingRangeException ('No more elements' );
31
30
} else if (p < 0 ) {
32
31
throw RangeError (p);
33
32
}
@@ -37,14 +36,14 @@ class EncodingBytes {
37
36
38
37
set _position (int value) {
39
38
if (__position >= _length) {
40
- throw StateError ('No more elements' );
39
+ throw _EncodingRangeException ('No more elements' );
41
40
}
42
41
__position = value;
43
42
}
44
43
45
44
int get _position {
46
45
if (__position >= _length) {
47
- throw StateError ('No more elements' );
46
+ throw _EncodingRangeException ('No more elements' );
48
47
}
49
48
if (__position >= 0 ) {
50
49
return __position;
@@ -108,7 +107,7 @@ class EncodingBytes {
108
107
__position = newPosition + bytes.length - 1 ;
109
108
return true ;
110
109
} else {
111
- throw StateError ('No more elements' );
110
+ throw _EncodingRangeException ('No more elements' );
112
111
}
113
112
}
114
113
@@ -161,7 +160,7 @@ class EncodingParser {
161
160
}
162
161
_data._position += 1 ;
163
162
}
164
- } on StateError catch (_) {
163
+ } on _EncodingRangeException catch (_) {
165
164
// Catch this here to match behavior of Python's StopIteration
166
165
// TODO(jmesserly): refactor to not use exceptions
167
166
}
@@ -355,12 +354,12 @@ class ContentAttrParser {
355
354
try {
356
355
data._skipUntil (isWhitespace);
357
356
return data._slice (oldPosition, data._position);
358
- } on StateError catch (_) {
357
+ } on _EncodingRangeException catch (_) {
359
358
//Return the whole remaining value
360
359
return data._slice (oldPosition);
361
360
}
362
361
}
363
- } on StateError catch (_) {
362
+ } on _EncodingRangeException catch (_) {
364
363
return null ;
365
364
}
366
365
}
@@ -371,3 +370,9 @@ bool _isSpaceOrAngleBracket(String char) {
371
370
}
372
371
373
372
typedef _CharPredicate = bool Function (String char);
373
+
374
+ class _EncodingRangeException implements Exception {
375
+ final String message;
376
+
377
+ _EncodingRangeException (this .message);
378
+ }
0 commit comments