OLD | NEW |
| (Empty) |
1 part of dart.core; | |
2 abstract class String implements Comparable<String>, Pattern {external factory
String.fromCharCodes(Iterable<int> charCodes, [int start = 0, int end]); | |
3 external factory String.fromCharCode(int charCode); | |
4 external const factory String.fromEnvironment(String name, { | |
5 String defaultValue} | |
6 ); | |
7 String operator [](int index); | |
8 int codeUnitAt(int index); | |
9 int get length; | |
10 int get hashCode; | |
11 bool operator ==(Object other); | |
12 bool endsWith(String other); | |
13 bool startsWith(Pattern pattern, [int index = 0]); | |
14 int indexOf(Pattern pattern, [int start]); | |
15 int lastIndexOf(Pattern pattern, [int start]); | |
16 bool get isEmpty; | |
17 bool get isNotEmpty; | |
18 String operator +(String other); | |
19 String substring(int startIndex, [int endIndex]); | |
20 String trim(); | |
21 String trimLeft(); | |
22 String trimRight(); | |
23 String operator *(int times); | |
24 String padLeft(int width, [String padding = ' ']); | |
25 String padRight(int width, [String padding = ' ']); | |
26 bool contains(Pattern other, [int startIndex = 0]); | |
27 String replaceFirst(Pattern from, String to, [int startIndex = 0]); | |
28 String replaceAll(Pattern from, String replace); | |
29 String replaceAllMapped(Pattern from, String replace(Match match)); | |
30 List<String> split(Pattern pattern); | |
31 String splitMapJoin(Pattern pattern, { | |
32 String onMatch(Match match), String onNonMatch(String nonMatch)} | |
33 ); | |
34 List<int> get codeUnits; | |
35 Runes get runes; | |
36 String toLowerCase(); | |
37 String toUpperCase(); | |
38 } | |
39 class Runes extends IterableBase<int> {final String string; | |
40 Runes(this.string); | |
41 RuneIterator get iterator => new RuneIterator(string); | |
42 int get last { | |
43 if (string.length == 0) { | |
44 throw new StateError('No elements.'); | |
45 } | |
46 int length = string.length; | |
47 int code = string.codeUnitAt(length - 1); | |
48 if (_isTrailSurrogate(code) && string.length > 1) { | |
49 int previousCode = string.codeUnitAt(length - 2); | |
50 if (_isLeadSurrogate(previousCode)) { | |
51 return _combineSurrogatePair(previousCode, code); | |
52 } | |
53 } | |
54 return code; | |
55 } | |
56 } | |
57 bool _isLeadSurrogate(int code) => (code & 0xFC00) == 0xD800; | |
58 bool _isTrailSurrogate(int code) => (code & 0xFC00) == 0xDC00; | |
59 int _combineSurrogatePair(int start, int end) { | |
60 return 0x10000 + ((start & 0x3FF) << 10) + (end & 0x3FF); | |
61 } | |
62 class RuneIterator implements BidirectionalIterator<int> {final String string; | |
63 int _position; | |
64 int _nextPosition; | |
65 num _currentCodePoint; | |
66 RuneIterator(String string) : this.string = string, _position = 0, _nextPositio
n = 0; | |
67 RuneIterator.at(String string, int index) : string = string, _position = index,
_nextPosition = index { | |
68 RangeError.checkValueInInterval(index, 0, string.length); | |
69 _checkSplitSurrogate(index); | |
70 } | |
71 void _checkSplitSurrogate(int index) { | |
72 if (index > 0 && index < string.length && _isLeadSurrogate(string.codeUnitAt(ind
ex - 1)) && _isTrailSurrogate(string.codeUnitAt(index))) { | |
73 throw new ArgumentError('Index inside surrogate pair: $index'); | |
74 } | |
75 } | |
76 int get rawIndex => (_position != _nextPosition) ? _position : null; | |
77 void set rawIndex(int rawIndex) { | |
78 RangeError.checkValidIndex(rawIndex, string, "rawIndex"); | |
79 reset(rawIndex); | |
80 moveNext(); | |
81 } | |
82 void reset([int rawIndex = 0]) { | |
83 RangeError.checkValueInInterval(rawIndex, 0, string.length, "rawIndex"); | |
84 _checkSplitSurrogate(rawIndex); | |
85 _position = _nextPosition = rawIndex; | |
86 _currentCodePoint = null; | |
87 } | |
88 int get current => DEVC$RT.cast(_currentCodePoint, num, int, "ImplicitCast", ""
"line 702, column 22 of dart:core/string.dart: """, _currentCodePoint is int, tr
ue); | |
89 int get currentSize => _nextPosition - _position; | |
90 String get currentAsString { | |
91 if (_position == _nextPosition) return null; | |
92 if (_position + 1 == _nextPosition) return string[_position]; | |
93 return string.substring(_position, _nextPosition); | |
94 } | |
95 bool moveNext() { | |
96 _position = _nextPosition; | |
97 if (_position == string.length) { | |
98 _currentCodePoint = null; | |
99 return false; | |
100 } | |
101 int codeUnit = string.codeUnitAt(_position); | |
102 int nextPosition = _position + 1; | |
103 if (_isLeadSurrogate(codeUnit) && nextPosition < string.length) { | |
104 int nextCodeUnit = string.codeUnitAt(nextPosition); | |
105 if (_isTrailSurrogate(nextCodeUnit)) { | |
106 _nextPosition = nextPosition + 1; | |
107 _currentCodePoint = _combineSurrogatePair(codeUnit, nextCodeUnit); | |
108 return true; | |
109 } | |
110 } | |
111 _nextPosition = nextPosition; | |
112 _currentCodePoint = codeUnit; | |
113 return true; | |
114 } | |
115 bool movePrevious() { | |
116 _nextPosition = _position; | |
117 if (_position == 0) { | |
118 _currentCodePoint = null; | |
119 return false; | |
120 } | |
121 int position = _position - 1; | |
122 int codeUnit = string.codeUnitAt(position); | |
123 if (_isTrailSurrogate(codeUnit) && position > 0) { | |
124 int prevCodeUnit = string.codeUnitAt(position - 1); | |
125 if (_isLeadSurrogate(prevCodeUnit)) { | |
126 _position = position - 1; | |
127 _currentCodePoint = _combineSurrogatePair(prevCodeUnit, codeUnit); | |
128 return true; | |
129 } | |
130 } | |
131 _position = position; | |
132 _currentCodePoint = codeUnit; | |
133 return true; | |
134 } | |
135 } | |
OLD | NEW |