| OLD | NEW |
| 1 // Copyright (c) 2011, 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 | 4 |
| 5 class JSRegExpMatch implements Match { | 5 class _JSRegExpMatch implements Match { |
| 6 JSRegExpMatch(this.regexp, this.str, this._match); | 6 _JSRegExpMatch(this.regexp, this.str, this._match); |
| 7 | 7 |
| 8 int start() { | 8 int start() { |
| 9 return _start(0); | 9 return _start(0); |
| 10 } | 10 } |
| 11 | 11 |
| 12 int end() { | 12 int end() { |
| 13 return _end(0); | 13 return _end(0); |
| 14 } | 14 } |
| 15 | 15 |
| 16 int _start(int groupIdx) { | 16 int _start(int groupIdx) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 String get pattern() => regexp.pattern; | 53 String get pattern() => regexp.pattern; |
| 54 | 54 |
| 55 final RegExp regexp; | 55 final RegExp regexp; |
| 56 final String str; | 56 final String str; |
| 57 final List<int> _match; | 57 final List<int> _match; |
| 58 static final int MATCH_PAIR = 2; | 58 static final int MATCH_PAIR = 2; |
| 59 } | 59 } |
| 60 | 60 |
| 61 | 61 |
| 62 class JSSyntaxRegExp implements RegExp { | 62 patch class JSSyntaxRegExp { |
| 63 const factory JSSyntaxRegExp( | 63 /* patch */ const factory JSSyntaxRegExp( |
| 64 String pattern, | 64 String pattern, |
| 65 [bool multiLine = false, | 65 [bool multiLine = false, |
| 66 bool ignoreCase = false]) native "JSSyntaxRegExp_factory"; | 66 bool ignoreCase = false]) native "JSSyntaxRegExp_factory"; |
| 67 | 67 |
| 68 Match firstMatch(String str) { | 68 /* patch */ Match firstMatch(String str) { |
| 69 List match = _ExecuteMatch(str, 0); | 69 List match = _ExecuteMatch(str, 0); |
| 70 if (match === null) { | 70 if (match === null) { |
| 71 return null; | 71 return null; |
| 72 } | 72 } |
| 73 return new JSRegExpMatch(this, str, match); | 73 return new _JSRegExpMatch(this, str, match); |
| 74 } | 74 } |
| 75 | 75 |
| 76 Iterable<Match> allMatches(String str) { | 76 /* patch */ Iterable<Match> allMatches(String str) { |
| 77 List<Match> result = new List<Match>(); | 77 List<Match> result = new List<Match>(); |
| 78 int length = str.length; | 78 int length = str.length; |
| 79 int startIndex = 0; | 79 int startIndex = 0; |
| 80 while (true) { | 80 while (true) { |
| 81 List match = _ExecuteMatch(str, startIndex); | 81 List match = _ExecuteMatch(str, startIndex); |
| 82 if (match == null) { | 82 if (match == null) { |
| 83 break; | 83 break; |
| 84 } | 84 } |
| 85 result.add(new JSRegExpMatch(this, str, match)); | 85 result.add(new _JSRegExpMatch(this, str, match)); |
| 86 int endIndex = match[1]; | 86 int endIndex = match[1]; |
| 87 if (endIndex == length) { | 87 if (endIndex == length) { |
| 88 break; | 88 break; |
| 89 } else if (match[0] == endIndex) { | 89 } else if (match[0] == endIndex) { |
| 90 ++startIndex; // empty match, advance and restart | 90 ++startIndex; // empty match, advance and restart |
| 91 } else { | 91 } else { |
| 92 startIndex = endIndex; | 92 startIndex = endIndex; |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 return result; | 95 return result; |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool hasMatch(String str) { | 98 /* patch */ bool hasMatch(String str) { |
| 99 List match = _ExecuteMatch(str, 0); | 99 List match = _ExecuteMatch(str, 0); |
| 100 return (match === null) ? false : true; | 100 return (match === null) ? false : true; |
| 101 } | 101 } |
| 102 | 102 |
| 103 String stringMatch(String str) { | 103 /* patch */ String stringMatch(String str) { |
| 104 List match = _ExecuteMatch(str, 0); | 104 List match = _ExecuteMatch(str, 0); |
| 105 if (match === null) { | 105 if (match === null) { |
| 106 return null; | 106 return null; |
| 107 } | 107 } |
| 108 return str.substringUnchecked_(match[0], match[1]); | 108 return str.substringUnchecked_(match[0], match[1]); |
| 109 } | 109 } |
| 110 | 110 |
| 111 String get pattern() native "JSSyntaxRegExp_getPattern"; | 111 /* patch */ String get pattern() native "JSSyntaxRegExp_getPattern"; |
| 112 | 112 |
| 113 bool get multiLine() native "JSSyntaxRegExp_multiLine"; | 113 /* patch */ bool get multiLine() native "JSSyntaxRegExp_multiLine"; |
| 114 | 114 |
| 115 bool get ignoreCase() native "JSSyntaxRegExp_ignoreCase"; | 115 /* patch */ bool get ignoreCase() native "JSSyntaxRegExp_ignoreCase"; |
| 116 | 116 |
| 117 int get _groupCount() native "JSSyntaxRegExp_getGroupCount"; | 117 int get _groupCount() native "JSSyntaxRegExp_getGroupCount"; |
| 118 | 118 |
| 119 List _ExecuteMatch(String str, int start_index) | 119 List _ExecuteMatch(String str, int start_index) |
| 120 native "JSSyntaxRegExp_ExecuteMatch"; | 120 native "JSSyntaxRegExp_ExecuteMatch"; |
| 121 } | 121 } |
| OLD | NEW |