Stop using Match.group.

The `Match.operator[]` does the same thing and is
generally recommended (and shorter).
(I want to deprecate `group` and `groups`)

Tested: Refactoring.
CoreLibraryReviewExempt: Calling equivalent function.
Change-Id: I4c758968ae622fe16b7322be1b29b05b91e7fcd9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/489021
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
This commit is contained in:
Lasse R.H. Nielsen
2026-03-20 09:09:46 -07:00
committed by Commit Queue
parent 7cad9ad43d
commit 56505e0575
97 changed files with 313 additions and 332 deletions
@@ -320,7 +320,7 @@ abstract class DiagnosticCode {
if (correctionMessage != null) correctionMessage,
]) {
for (RegExpMatch match in _positionalArgumentRegExp.allMatches(s)) {
result = max(result, int.parse(match.group(1)!) + 1);
result = max(result, int.parse(match[1]!) + 1);
}
}
return result;
@@ -459,7 +459,7 @@ String applyArgumentsToTemplate(
return template;
}
return template.replaceAllMapped(templateKey, (Match match) {
String? key = match.group(1);
String? key = match[1];
Object? value = arguments[key];
assert(value != null, "No value for '$key' found in $arguments");
return value.toString();
+1 -1
View File
@@ -144,7 +144,7 @@ String computeLocation() {
'_locationRegExp failed to match $stackLine in $callStack',
);
}
return match.group(0)!;
return match[0]!;
}
Statement continue_([Label? target]) =>
@@ -370,7 +370,7 @@ lsp.CompletionItem? toLspCompletionItem(
if (labelMatch != null) {
cleanedDoc = null;
labelDetails = (
detail: labelMatch.group(1)!,
detail: labelMatch[1]!,
truncatedParams: labelDetails.truncatedParams,
truncatedSignature: labelDetails.truncatedSignature,
autoImportUri: labelDetails.autoImportUri,
@@ -634,7 +634,7 @@ CompletionDetail _getCompletionDetail(
if (returnType == null &&
element.kind == ElementKind.SETTER &&
parameters != null) {
returnType = completionSetterTypePattern.firstMatch(parameters)?.group(1);
returnType = completionSetterTypePattern.firstMatch(parameters)?[1];
parameters = null;
}
} else if (suggestion is FunctionCall) {
+1 -4
View File
@@ -17,10 +17,7 @@ String? cleanDartdoc(String? doc) {
// Remove any code block section names like ```dart preamble that Flutter
// docs contain.
doc = doc.replaceAllMapped(
_dartdocCodeBlockSections,
(match) => match.group(1)!,
);
doc = doc.replaceAllMapped(_dartdocCodeBlockSections, (match) => match[1]!);
return doc;
}
+2 -2
View File
@@ -568,7 +568,7 @@ CompletionDetail getCompletionDetail(
if (returnType == null &&
element?.kind == server.ElementKind.SETTER &&
parameters != null) {
returnType = completionSetterTypePattern.firstMatch(parameters)?.group(1);
returnType = completionSetterTypePattern.firstMatch(parameters)?[1];
parameters = null;
}
@@ -1275,7 +1275,7 @@ lsp.CompletionItem toCompletionItem(
if (labelMatch != null) {
cleanedDoc = null;
labelDetails = (
detail: labelMatch.group(1)!,
detail: labelMatch[1]!,
truncatedParams: labelDetails.truncatedParams,
truncatedSignature: labelDetails.truncatedSignature,
autoImportUri: labelDetails.autoImportUri,
@@ -25,7 +25,7 @@ List<CompletionSuggestionBuilder> fuzzyFilterSort({
if (suggestion.kind == CompletionSuggestionKind.KEYWORD ||
suggestion.kind == CompletionSuggestionKind.NAMED_ARGUMENT) {
var identifier = _identifierPattern.matchAsPrefix(textToMatch)?.group(1);
var identifier = _identifierPattern.matchAsPrefix(textToMatch)?[1];
if (identifier == null) {
return -1;
}
@@ -650,7 +650,7 @@ class StatementCompletionProcessor {
// emptyCondition, emptyInitializersEmptyCondition
replacementLength = match.end - match.start;
sb = SourceBuilder(file, forParts.leftSeparator.offset);
sb.append('; ${match.group(1) ?? ''}; )');
sb.append('; ${match[1] ?? ''}; )');
var suffix = text.substring(match.end);
if (suffix.trim().isNotEmpty) {
sb.append(' ');
@@ -45,6 +45,6 @@ class ReplaceWithNamedConstant extends ResolvedCorrectionProducer {
if (match == null) {
return null;
}
return match.group(1);
return match[1];
}
}
@@ -69,8 +69,8 @@ class TextExpectationsCollector {
fail('Cannot parse: $invocationTraceLine');
}
var path = Uri.parse(locationMatch.group(1)!).toFilePath();
var line = int.parse(locationMatch.group(2)!);
var path = Uri.parse(locationMatch[1]!).toFilePath();
var line = int.parse(locationMatch[2]!);
var file = _getFile(path);
var invocation = file.findInvocation(invocationLine: line);
@@ -43,8 +43,8 @@ class BlobDiff {
var currentHunk = hunks.isEmpty ? null : hunks.last;
if (line.startsWith('@@')) {
var match = hunkHeaderRegExp.matchAsPrefix(line)!;
var srcLine = int.parse(match.group(1)!);
var dstLine = int.parse(match.group(2)!);
var srcLine = int.parse(match[1]!);
var dstLine = int.parse(match[2]!);
hunks.add(DiffHunk(srcLine, dstLine));
} else if (currentHunk != null && line.startsWith('+')) {
currentHunk.addLines.add(line.substring(1));
@@ -72,7 +72,7 @@ Future<void> main(List<String> args) async {
print('found ${absFileMatches.length} absolute file paths remaining:');
}
for (var match in absFileMatches.take(5)) {
print('- ${match.group(0)}');
print('- ${match[0]}');
}
}
@@ -309,8 +309,8 @@ String _memberNameForType(TypeBase type) {
String _rewriteCommentReference(String comment) {
var commentReferencePattern = RegExp(r'\[([\w ]+)\]\(#(\w+)\)');
return comment.replaceAllMapped(commentReferencePattern, (m) {
var description = m.group(1);
var reference = m.group(2);
var description = m[1];
var reference = m[2];
if (description == reference) {
return '[$reference]';
} else {
@@ -114,18 +114,18 @@ class LspMetaModelCleaner {
// spaces.
text = text.replaceAllMapped(
_sourceCommentWrappingNewlinesPattern,
(match) => match.group(0)!.replaceAll('\n', ' '),
(match) => match[0]!.replaceAll('\n', ' '),
);
// Replace any references to other types with a format that's valid for
// Dart.
text = text.replaceAllMapped(
_sourceCommentDocumentLinksPattern,
(match) => '[${match.group(1)!}]',
(match) => '[${match[1]!}]',
);
text = text.replaceAllMapped(
_sourceCommentReferencesPattern,
(match) => '[${match.group(1)!}]',
(match) => '[${match[1]!}]',
);
// Replace any references to Thenable/Promise to Future.
@@ -129,7 +129,7 @@ class DartdocDirectiveInfo {
} else {
var match = macroRegExp.firstMatch(line);
if (match != null) {
var name = match.group(1)!;
var name = match[1]!;
var value = templateMap[name];
if (value != null) {
lines[i] = value;
@@ -139,7 +139,7 @@ class DartdocDirectiveInfo {
match = videoRegExp.firstMatch(line);
if (match != null) {
var uri = match.group(2);
var uri = match[2];
if (uri != null && uri.isNotEmpty) {
String label = uri;
if (label.startsWith('https://')) {
@@ -87,7 +87,7 @@ class TestCode {
var rangeEndOffsets = <int, int>{};
late int start;
int scannedNumber() => int.parse(scanner.lastMatch!.group(1)!);
int scannedNumber() => int.parse(scanner.lastMatch![1]!);
void recordPosition(int number) {
if (positionOffsets.containsKey(number)) {
@@ -532,7 +532,7 @@ class _TokenStream {
int _index = 0;
factory _TokenStream.fromString(String input) {
var tokens = _tokenizer.allMatches(input).map((m) => m.group(0)!).toList();
var tokens = _tokenizer.allMatches(input).map((m) => m[0]!).toList();
return _TokenStream._(tokens);
}
+1 -1
View File
@@ -580,7 +580,7 @@ class BlazeWorkspace extends Workspace
var pattern = RegExp(r'(^|\s+)_version\s*=\s*"(\d+\.\d+)"');
for (var match in pattern.allMatches(content)) {
return Version.parse('${match.group(2)}.0');
return Version.parse('${match[2]}.0');
}
return null;
@@ -267,8 +267,8 @@ class NodeTextExpectationsCollector {
fail('Cannot parse: $invocationTraceLine');
}
var path = Uri.parse(locationMatch.group(1)!).toFilePath();
var line = int.parse(locationMatch.group(2)!);
var path = Uri.parse(locationMatch[1]!).toFilePath();
var line = int.parse(locationMatch[2]!);
var file = _getFile(path);
var invocation = file.findInvocation(invocationLine: line);
@@ -207,7 +207,7 @@ class _GraphGenerator extends TypeInformationVisitor<void> {
/// Escapes characters in [text] so it can be used as part of a label.
String escapeLabel(String text) {
return text.replaceAllMapped(escapeRegexp, (m) => '\\${m.group(0)}');
return text.replaceAllMapped(escapeRegexp, (m) => '\\${m[0]}');
}
/// Creates an edge from [src] to [dst].
@@ -238,9 +238,8 @@ checkerForAbsentPresent(String test) {
Expect.fail("No 'absent:' or 'present:' directives in '$test'");
}
for (Match match in matches) {
String? directive = match.group(1);
Pattern pattern = match.groups([2, 3, 4]).where((s) => s != null).single!;
if (match.group(4) != null) pattern = RegExp(pattern as String);
String? directive = match[1];
Pattern pattern = match[2] ?? match[3] ?? RegExp(match[4]!);
if (directive == 'present') {
Expect.isTrue(
generated.contains(pattern),
@@ -384,15 +384,15 @@ class LibraryBlock extends AbstractEntity {
BasicEntity? next;
Match? matchFunction = TOP_LEVEL_FUNCTION.firstMatch(line);
if (matchFunction != null) {
next = TopLevelFunction(matchFunction.group(1)!, index);
next = TopLevelFunction(matchFunction[1]!, index);
} else {
Match? matchClass = TOP_LEVEL_CLASS.firstMatch(line);
if (matchClass != null) {
next = LibraryClass(matchClass.group(1)!, index);
next = LibraryClass(matchClass[1]!, index);
} else {
Match? matchValue = TOP_LEVEL_VALUE.firstMatch(line);
if (matchValue != null) {
next = TopLevelValue(matchValue.group(1)!, index);
next = TopLevelValue(matchValue[1]!, index);
}
}
}
@@ -511,7 +511,7 @@ class LibraryClass extends BasicEntity {
BasicEntity? next;
Match? match = MEMBER_FUNCTION.firstMatch(line);
if (match != null) {
next = MemberFunction(match.group(1)!, index);
next = MemberFunction(match[1]!, index);
} else {
match = STATICS.firstMatch(line);
if (match != null) {
@@ -519,11 +519,11 @@ class LibraryClass extends BasicEntity {
} else {
match = MEMBER_OBJECT.firstMatch(line);
if (match != null) {
next = MemberObject(match.group(1)!, index);
next = MemberObject(match[1]!, index);
} else {
match = MEMBER_VALUE.firstMatch(line);
if (match != null) {
next = MemberValue(match.group(1)!, index);
next = MemberValue(match[1]!, index);
}
}
}
@@ -595,7 +595,7 @@ class Statics extends BasicEntity {
BasicEntity? next;
Match? matchFunction = STATIC_FUNCTION.firstMatch(line);
if (matchFunction != null) {
next = MemberFunction(matchFunction.group(1)!, index);
next = MemberFunction(matchFunction[1]!, index);
}
if (next != null) {
if (current != null) {
@@ -70,10 +70,10 @@ RegExp _nameMatcher = RegExp("// Expected deobfuscated name: (.*)\n");
Future runTest(String code) async {
var patternMatch = _patternMatcher.firstMatch(code);
Expect.isNotNull(patternMatch, "Could not find the error pattern.");
var pattern = RegExp(patternMatch!.group(1)!);
var pattern = RegExp(patternMatch![1]!);
var kindMatch = _kindMatcher.firstMatch(code);
Expect.isNotNull(kindMatch, "Could not find the expected minified kind.");
var kind = kindMatch!.group(1)!;
var kind = kindMatch![1]!;
// TODO(sigmund): add support for "other" when we encode symbol information
// directly for each field and local variable.
@@ -85,7 +85,7 @@ Future runTest(String code) async {
var nameMatch = _nameMatcher.firstMatch(code);
Expect.isNotNull(nameMatch, "Could not find the expected deobfuscated name.");
var expectedName = nameMatch!.group(1)!;
var expectedName = nameMatch![1]!;
var test = MinifiedNameTest(pattern, kind, expectedName, code);
print('expectations: ${pattern.pattern} $kind $expectedName');
await checkExpectation(test, false);
@@ -114,7 +114,7 @@ checkExpectation(MinifiedNameTest test, bool minified) async {
'Error didn\'t match the test pattern'
'\nerror: $error\npattern:${test.pattern}',
);
var name = match!.group(1)!;
var name = match![1]!;
print(' obfuscated-name: $name');
Expect.isNotNull(name, 'Error didn\'t contain a name\nerror: $error');
@@ -68,8 +68,8 @@ main(List<String> arguments) async {
continue;
}
Match m = ms.first;
int l = int.parse(m.group(1)!);
int c = int.parse(m.group(2)!);
int l = int.parse(m[1]!);
int c = int.parse(m[2]!);
SourceMapSpan? span = sourceMap.spanFor(l, c);
if (span == null) {
if (options['inline']) {
@@ -115,8 +115,8 @@ class LibrarySizeCommand extends Command<void> with PrintUsageException {
final match = group.matcher.firstMatch('${lib.uri}');
if (match != null) {
var name = group.name;
if (name == null && match.groupCount > 0) name = match.group(1);
name ??= match.group(0);
if (name == null && match.groupCount > 0) name = match[1];
name ??= match[0];
sizes.putIfAbsent(name, () => _SizeEntry(name, group.cluster));
sizes[name].size += lib.size;
}
+6 -6
View File
@@ -85,7 +85,7 @@ class MinifiedNameDecoder extends ErrorMapDecoder {
StackTraceLine? line,
TargetEntry? entry,
) {
var minifiedName = match.group(1);
var minifiedName = match[1];
return mapping!.globalNames[minifiedName];
}
}
@@ -101,7 +101,7 @@ class CannotReadPropertyDecoder extends ErrorMapDecoder {
StackTraceLine? line,
TargetEntry? entry,
) {
var minifiedName = match.group(1);
var minifiedName = match[1];
var name = mapping!.instanceNames[minifiedName];
if (name == null) return null;
return "Cannot read property '$name' of";
@@ -176,8 +176,8 @@ class NoSuchMethodDecoder1 extends NoSuchMethodDecoderBase {
StackTraceLine? line,
TargetEntry? entry,
) {
var minifiedName = match.group(1);
var suffix = match.group(2) ?? '';
var minifiedName = match[1];
var suffix = match[2] ?? '';
var name = _translateMinifiedName(mapping!, minifiedName);
if (name == null) return null;
return "NoSuchMethodError: method not found: $name$suffix";
@@ -197,7 +197,7 @@ class NoSuchMethodDecoder2 extends NoSuchMethodDecoderBase {
StackTraceLine? line,
TargetEntry? entry,
) {
var minifiedName = match.group(1);
var minifiedName = match[1];
var name = _translateMinifiedName(mapping!, minifiedName);
if (name == null) return null;
return "NoSuchMethodError: method not found: $name";
@@ -215,7 +215,7 @@ class UnhandledNotAFunctionError extends ErrorMapDecoder {
StackTraceLine? line,
TargetEntry? entry,
) {
var minifiedName = match.group(1);
var minifiedName = match[1];
var name = mapping!.instanceNames[minifiedName];
if (name == null) return null;
return "Error: $name is not a function";
+4 -4
View File
@@ -764,10 +764,10 @@ class GitSshUrl {
}
return GitSshUrl(
user: match.group(1)!,
host: match.group(2)!,
owner: match.group(3)!,
repository: match.group(4)!,
user: match[1]!,
host: match[2]!,
owner: match[3]!,
repository: match[4]!,
fullUrl: url,
);
}
+1 -1
View File
@@ -135,7 +135,7 @@ Map<Architecture?, List<String>> parseOtoolArchitectureSections(String output) {
'Expected a single architecture section in otool output: $output',
);
}
final String? architectureString = architectureHeader.group(2);
final String? architectureString = architectureHeader[2];
if (architectureString != null) {
currentArchitecture = outputArchitectures[architectureString];
if (currentArchitecture == null) {
+1 -1
View File
@@ -79,7 +79,7 @@ String sanitizeStacktrace(dynamic st, {bool shorten = true}) {
iter = iter.toList().reversed;
for (var match in iter) {
var replacement = match.group(1)!;
var replacement = match[1]!;
str =
str.substring(0, match.start) + replacement + str.substring(match.end);
}
+1 -1
View File
@@ -241,7 +241,7 @@ Future<void> main() async {
if (event.contains(dartVMServiceRegExp)) {
await sub.cancel();
serviceUriCompleter.complete(
dartVMServiceRegExp.firstMatch(event)!.group(1),
dartVMServiceRegExp.firstMatch(event)![1],
);
}
});
@@ -176,7 +176,7 @@ Future<String> _readLspMessage(Stream<List<int>> stream) {
final headers = parts[0];
final body = parts[1];
final length = int.parse(
contentLengthRegExp.firstMatch(headers)!.group(1)!,
contentLengthRegExp.firstMatch(headers)![1]!,
);
// Check if we're already had the full payload.
if (body.length >= length) {
+1 -1
View File
@@ -534,7 +534,7 @@ void main(List<String> args) => print("$b $args");
);
void onData(event) {
if (event.contains('The Dart VM service is listening on')) {
final vmServicePort = int.parse(regexp.firstMatch(event)!.group(1)!);
final vmServicePort = int.parse(regexp.firstMatch(event)![1]!);
expect(server.port != vmServicePort, isTrue);
p.kill();
}
+1 -1
View File
@@ -217,7 +217,7 @@ void main() {
if (line.contains(vmServiceUriRegExp)) {
await sub.cancel();
final httpUri = Uri.parse(
vmServiceUriRegExp.firstMatch(line)!.group(0)!,
vmServiceUriRegExp.firstMatch(line)![0]!,
);
completer.complete(
httpUri.replace(scheme: 'ws', path: '${httpUri.path}ws'),
+2 -2
View File
@@ -1212,7 +1212,7 @@ abstract class DartDebugAdapter<TL extends LaunchRequestArguments,
/// If no message could be extracted, returns the whole original error.
String extractEvaluationErrorMessage(String rawError) {
final match = _evalErrorMessagePattern.firstMatch(rawError);
final shortError = match?.group(1);
final shortError = match?[1];
return shortError ?? rawError;
}
@@ -1221,7 +1221,7 @@ abstract class DartDebugAdapter<TL extends LaunchRequestArguments,
/// If no message could be extracted, returns the whole original error.
String extractUnhandledExceptionMessage(String rawError) {
final match = _exceptionMessagePattern.firstMatch(rawError);
final shortError = match?.group(1);
final shortError = match?[1];
return shortError ?? rawError;
}
+2 -2
View File
@@ -931,7 +931,7 @@ class IsolateManager {
final terseMessageMatch =
_terseBreakpointFailureRegex.firstMatch(userMessage);
if (terseMessageMatch != null) {
userMessage = terseMessageMatch.group(1) ?? userMessage;
userMessage = terseMessageMatch[1] ?? userMessage;
}
final updatedBreakpoint = Breakpoint(
@@ -1008,7 +1008,7 @@ class IsolateManager {
// avoid any clever parsing, just prefix them with $ and treat them
// like other Dart interpolation expressions.
.replaceAllMapped(_braceNotPrefixedByDollarOrBackslashPattern,
(match) => '${match.group(1)}\${')
(match) => '${match[1]}\${')
// Remove any backslashes the user added to "escape" braces.
.replaceAll(r'\\{', '{');
return _evaluateAndPrintErrors(thread, expression, 'log message');
+3 -3
View File
@@ -100,9 +100,9 @@ StackFrameLocation? _parseStackFrame(String input) {
final match = _stackFrameLocationPattern.firstMatch(input);
if (match == null) return null;
final uriMatch = match.group(1);
final lineMatch = match.group(2);
final colMatch = match.group(3);
final uriMatch = match[1];
final lineMatch = match[2];
final colMatch = match[3];
var uri = uriMatch != null ? Uri.tryParse(uriMatch) : null;
final line = lineMatch != null ? int.tryParse(lineMatch) : null;
+2 -2
View File
@@ -142,8 +142,8 @@ class EvaluationExpression {
/// format a value should be presented in.
factory EvaluationExpression.parse(String expression) {
final match = _expressionWithFormatSpecifierRegex.firstMatch(expression);
expression = match?.group(1) ?? expression;
final formatSpecifiers = match?.group(2)?.split(',').toSet() ?? const {};
expression = match?[1] ?? expression;
final formatSpecifiers = match?[2]?.split(',').toSet() ?? const {};
final format = formatSpecifiers.isEmpty
? null
: VariableFormat(
+1 -1
View File
@@ -792,5 +792,5 @@ Uri _extractVmServiceUri(OutputEventBody vmConnectionBanner) {
// TODO(dantup): Change this to use the dart.debuggerUris custom event
// if implemented (which VS Code also needs).
final match = dapVmServiceBannerPattern.firstMatch(vmConnectionBanner.output);
return Uri.parse(match!.group(1)!);
return Uri.parse(match![1]!);
}
@@ -123,7 +123,7 @@ Future<Uri> waitForStdoutVmServiceBanner(Process process) {
(line) {
final match = vmServiceBannerPattern.firstMatch(line);
if (match != null) {
vmServiceUriCompleter.complete(Uri.parse(match.group(1)!));
vmServiceUriCompleter.complete(Uri.parse(match[1]!));
vmServiceBannerSub.cancel();
}
},
@@ -42,7 +42,7 @@ void main() {
(String line) {
final match = devToolsBannerRegex.firstMatch(line);
if (match != null) {
completer.complete(match.group(1)!);
completer.complete(match[1]!);
}
},
onDone: () {
@@ -98,7 +98,7 @@ void main() {
// Extract the base href so if the test failures, we get a simpler error
// than just the entire content.
final actualBaseHref = baseHrefRegex.firstMatch(bodyContent)!.group(1);
final actualBaseHref = baseHrefRegex.firstMatch(bodyContent)![1];
expect(actualBaseHref, htmlEscape.convert(expectedBaseHref));
}, timeout: const Timeout.factor(10));
}
@@ -85,7 +85,7 @@ void main() {
// Extract the base href so if the test failures, we get a simpler error
// than just the entire content.
final actualBaseHref = baseHrefRegex.firstMatch(bodyContent)!.group(1);
final actualBaseHref = baseHrefRegex.firstMatch(bodyContent)![1];
expect(actualBaseHref, htmlEscape.convert(expectedBaseHref));
}, timeout: const Timeout.factor(10));
}
@@ -1186,7 +1186,7 @@ Map<String, Object?> placeSourceMap(
// The source location is part of a different package.
var match = _crossPackageLib.matchAsPrefix(relativeUriPath);
if (match != null) {
var crossPackageName = match.group(1);
var crossPackageName = match[1];
return relativeUriPath.replaceFirst(
'../../$crossPackageName/lib/',
'../$crossPackageName/',
@@ -46,7 +46,7 @@ void main() {
if (line.startsWith('The Dart Tooling Daemon is listening on')) {
final match = uriRegex.firstMatch(line);
if (match != null) {
uri = match.group(1);
uri = match[1];
}
} else if (line.startsWith('Trusted Client Secret')) {
break; // We have both the URI (printed first) and the secret.
+1 -1
View File
@@ -210,7 +210,7 @@ MessagesWork? _createMessagesTestWork(List<String> changedFiles) {
List<String> filters = [];
for (String file in changedFiles) {
if (_messagesYamlPathRegExp.matchAsPrefix(file) case var match?) {
filters.add('messages/${match.group(1)}/...');
filters.add('messages/${match[1]}/...');
}
}
@@ -204,7 +204,7 @@ class BinaryMdDillReader {
String? nameExtends = null;
Match? extendsMatch = (new RegExp("extends (.+)[ \{]")).firstMatch(name);
if (extendsMatch != null) {
nameExtends = extendsMatch.group(1);
nameExtends = extendsMatch[1];
}
name = _getType(name);
if (name.contains("<")) {
@@ -52,13 +52,13 @@ Future<void> main() async {
while (true) {
RegExpMatch? match = tagParser.firstMatch(line);
if (match != null) {
int value = int.parse(match.group(2)!);
int value = int.parse(match[2]!);
int end = value + 1;
if (uses8Tags(match.group(1)!)) {
if (uses8Tags(match[1]!)) {
end = value + 8;
}
for (int j = value; j < end; j++) {
vmTagToName[j] = match.group(1)!;
vmTagToName[j] = match[1]!;
}
}
if (!vmTagLines[i].trim().endsWith(r"\")) {
@@ -71,7 +71,7 @@ Future<void> main() async {
while (true) {
RegExpMatch? match = constantTagParser.firstMatch(line);
if (match != null) {
vmConstantTagToName[int.parse(match.group(2)!)] = match.group(1)!;
vmConstantTagToName[int.parse(match[2]!)] = match[1]!;
}
if (vmTagLines[i].trim().startsWith("}")) {
break;
+1 -1
View File
@@ -84,7 +84,7 @@ abstract class TestCase {
var portLine = await lines[0];
Expect.isTrue(dartVMServicePortRegExp.hasMatch(portLine));
var match = dartVMServicePortRegExp.firstMatch(portLine);
return int.parse(match!.group(1)!);
return int.parse(match![1]!);
}
/// Request vm to resume execution
+1 -1
View File
@@ -259,7 +259,7 @@ class ErrorCommentChecker
"'$plainTextProblem' with '$extractLineRegExp'";
}
for (RegExpMatch match in matches) {
String lineString = match.group(0)!;
String lineString = match[0]!;
notYetSeen.remove(lineString);
if (expectNoProblemOn.contains(lineString)) {
failures.add(
+2 -2
View File
@@ -466,8 +466,8 @@ Map<String, num> _benchmark(
line = line.substring(0, pos);
}
for (RegExpMatch match in _extractPerfNumbers.allMatches(line)) {
String stringValue = match.group(1)!.trim();
String caption = match.group(2)!.trim();
String stringValue = match[1]!.trim();
String caption = match[2]!.trim();
stringValue = stringValue.replaceAll(",", "");
num value;
if (stringValue.contains(".")) {
+1 -1
View File
@@ -92,7 +92,7 @@ ${result.stderr}
final uriRegExp = RegExp('Serving `web` on (http://.*)');
final sub = process.stdout.transform(utf8.decoder).listen((e) {
if (uriRegExp.hasMatch(e)) {
uriCompleter.complete(uriRegExp.firstMatch(e)!.group(1));
uriCompleter.complete(uriRegExp.firstMatch(e)![1]);
}
});
@@ -79,16 +79,16 @@ class DebuggerLocation {
Match match, {
bool package = false,
}) async {
var scriptName = match.group(1);
var scriptName = match[1];
if (package) {
scriptName = "package:$scriptName";
}
if (scriptName != null) {
scriptName = scriptName.substring(0, scriptName.length - 1);
}
var lineStr = match.group(2);
var lineStr = match[2];
assert(lineStr != null);
var colStr = match.group(3);
var colStr = match[3];
if (colStr != null) {
colStr = colStr.substring(1);
}
@@ -245,8 +245,8 @@ class DebuggerLocation {
Match match,
) {
Isolate isolate = debugger.isolate;
var base = match.group(1)!;
var qualifier = match.group(2);
var base = match[1]!;
var qualifier = match[2];
return _lookupClass(isolate, base).then((classes) {
var functions = [];
@@ -269,7 +269,7 @@ class DebuggerLocation {
for (var function in cls.functions) {
if (function.kind == M.FunctionKind.constructor) {
// Constructor names are class-qualified.
if (match.group(0) == function.name) {
if (match[0] == function.name) {
functions.add(function);
}
} else {
@@ -281,15 +281,13 @@ class DebuggerLocation {
}
}
if (functions.length == 0) {
return new DebuggerLocation.error(
"Function '${match.group(0)}' not found",
);
return new DebuggerLocation.error("Function '${match[0]}' not found");
} else if (functions.length == 1) {
return new DebuggerLocation.func(functions[0]);
} else {
// TODO(turnidge): Allow the user to disambiguate.
return new DebuggerLocation.error(
"Function '${match.group(0)}' is ambiguous",
"Function '${match[0]}' is ambiguous",
);
}
});
@@ -327,8 +325,8 @@ class DebuggerLocation {
Match match,
) {
Isolate isolate = debugger.isolate;
var base = match.group(1) ?? '';
var qualifier = match.group(2);
var base = match[1] ?? '';
var qualifier = match[2];
if (qualifier == null) {
return _lookupClass(isolate, base, allowPrefix: true).then((classes) {
@@ -353,11 +351,11 @@ class DebuggerLocation {
for (var cls in classes) {
for (var function in cls.functions) {
if (function.kind == M.FunctionKind.constructor) {
if (function.name!.startsWith(match.group(0)!)) {
if (function.name!.startsWith(match[0]!)) {
completions.add(function.name!);
}
} else {
if (function.qualifiedName!.startsWith(match.group(0)!)) {
if (function.qualifiedName!.startsWith(match[0]!)) {
completions.add(function.qualifiedName!);
}
}
@@ -382,7 +380,7 @@ class DebuggerLocation {
var lineStr;
var lineStrComplete = false;
var colStr;
if (_startsWithDigit(match.group(1)!)) {
if (_startsWithDigit(match[1]!)) {
// CASE 1: We have matched a prefix of (lineStr:)(colStr)
var frame = await _currentFrame(debugger);
if (frame == null) {
@@ -390,21 +388,21 @@ class DebuggerLocation {
}
scriptName = frame.location!.script.name;
scriptNameComplete = true;
lineStr = match.group(1) ?? '';
lineStr = match[1] ?? '';
if (lineStr.endsWith(':')) {
lineStr = lineStr.substring(0, lineStr.length - 1);
lineStrComplete = true;
}
colStr = match.group(2) ?? '';
colStr = match[2] ?? '';
} else {
// CASE 2: We have matched a prefix of (scriptName:)(lineStr)(:colStr)
scriptName = match.group(1) ?? '';
scriptName = match[1] ?? '';
if (scriptName.endsWith(':')) {
scriptName = scriptName.substring(0, scriptName.length - 1);
scriptNameComplete = true;
}
lineStr = match.group(2) ?? '';
colStr = match.group(3) ?? '';
lineStr = match[2] ?? '';
colStr = match[3] ?? '';
if (colStr.startsWith(':')) {
lineStrComplete = true;
colStr = colStr.substring(1);
@@ -369,8 +369,8 @@ List<_DartStackTraceDataEntry> _extractStackTrace(
continue;
}
Match m = ms.first;
int l = int.parse(m.group(1)!);
int c = int.parse(m.group(2)!);
int l = int.parse(m[1]!);
int c = int.parse(m[2]!);
SourceMapSpan? span = _getColumnOrPredecessor(sourceMap, l, c);
if (span?.start == null) {
result.add(
+5 -5
View File
@@ -563,7 +563,7 @@ main() {
if (s.startsWith(kDartVMServiceListening)) {
expect(dartVMServicePortRegExp.hasMatch(s), isTrue);
final match = dartVMServicePortRegExp.firstMatch(s)!;
port = int.parse(match.group(1)!);
port = int.parse(match[1]!);
await collectAndCheckCoverageData(port, true);
if (!portLineCompleter.isCompleted) {
portLineCompleter.complete("done");
@@ -673,7 +673,7 @@ main() {
if (s.startsWith(kDartVMServiceListening)) {
expect(dartVMServicePortRegExp.hasMatch(s), isTrue);
final match = dartVMServicePortRegExp.firstMatch(s)!;
port = int.parse(match.group(1)!);
port = int.parse(match[1]!);
await collectAndCheckCoverageData(
port,
true,
@@ -958,7 +958,7 @@ main() {
if (s.startsWith(kDartVMServiceListening)) {
expect(dartVMServicePortRegExp.hasMatch(s), isTrue);
final match = dartVMServicePortRegExp.firstMatch(s)!;
port = int.parse(match.group(1)!);
port = int.parse(match[1]!);
Set<int> hits1 = await collectAndCheckCoverageData(
port,
true,
@@ -1063,7 +1063,7 @@ main() {
);
expect(dartVMServicePortRegExp.hasMatch(portLine), isTrue);
final match = dartVMServicePortRegExp.firstMatch(portLine)!;
final port = int.parse(match.group(1)!);
final port = int.parse(match[1]!);
var remoteVm = new RemoteVm(port);
await remoteVm.resume();
@@ -1491,7 +1491,7 @@ main() {
if (s.startsWith(kDartVMServiceListening)) {
expect(dartVMServicePortRegExp.hasMatch(s), isTrue);
final match = dartVMServicePortRegExp.firstMatch(s)!;
port = int.parse(match.group(1)!);
port = int.parse(match[1]!);
RemoteVm remoteVm = new RemoteVm(port);
// Wait for the script to have loaded.
@@ -41,7 +41,7 @@ final tests = <IsolateTest>[
r'A timer should have fired (\d+) ms ago, but just fired now.',
);
final millisecondsOverdueAsString =
detailsRegex.firstMatch(event.details!)!.group(1)!;
detailsRegex.firstMatch(event.details!)![1]!;
expect(
int.parse(millisecondsOverdueAsString),
greaterThanOrEqualTo(100),
@@ -25,6 +25,6 @@ mixin ApiParseUtil {
if (match == null) throw 'Unable to locate service protocol version';
// Append a `.0`.
return Version.parse('${match.group(0)}.0');
return Version.parse('${match[0]}.0');
}
}
@@ -57,9 +57,9 @@ List<String> generateReloadVersions(String fileContent) {
final line = lines[i];
final m = includeIn.firstMatch(line);
if (m != null) {
final annotation = int.parse(m.group(1) as String);
final annotation = int.parse(m[1] as String);
reloadAnnotation[i] = annotation;
reloadPlusAnnotation[i] = m.group(2) == '+';
reloadPlusAnnotation[i] = m[2] == '+';
} else {
// No annotation means include always.
reloadPlusAnnotation[i] = true;
@@ -539,11 +539,11 @@ Map<int, Iterable<int>> parseUsingAddressRegExp(
for (final line in lines) {
var match = re.firstMatch(line);
if (match != null) {
final address = int.parse(match.group(1)!, radix: 16);
final address = int.parse(match[1]!, radix: 16);
var unitId = rootLoadingUnitId;
match = _unitRE.firstMatch(line);
if (match != null) {
unitId = int.parse(match.group(1)!);
unitId = int.parse(match[1]!);
}
result[unitId] ??= <int>[];
result[unitId]!.add(address);
@@ -391,7 +391,7 @@ String buildId(Iterable<String> lines) {
for (final line in lines) {
final match = _buildIdRE.firstMatch(line);
if (match != null) {
return match.group(1)!;
return match[1]!;
}
}
return '';
@@ -409,7 +409,7 @@ Iterable<String> removeColumns(Iterable<String> lines) sync* {
for (final line in lines) {
final match = _columnsRE.firstMatch(line);
if (match != null) {
yield line.replaceRange(match.start, match.end, '(${match.group(1)!})');
yield line.replaceRange(match.start, match.end, '(${match[1]!})');
} else {
yield line;
}
@@ -420,7 +420,7 @@ Iterable<int> parseUsingAddressRegExp(RegExp re, Iterable<String> lines) sync* {
for (final line in lines) {
final match = re.firstMatch(line);
if (match != null) {
yield int.parse(match.group(1)!, radix: 16);
yield int.parse(match[1]!, radix: 16);
}
}
}
@@ -244,13 +244,13 @@ void checkDebugMaps(List<TestCase> testCases) {
for (int i = 0; i < expected.length; i++) {
final expectedLine = expected[i];
final isSymbol = _symbolLineRegExp.hasMatch(expectedLine);
final expectedTriple = _tripleLineRegExp.firstMatch(expectedLine)?.group(1);
final expectedTriple = _tripleLineRegExp.firstMatch(expectedLine)?[1];
final expectedTimestampMatch = _timestampLineRegExp.firstMatch(
expectedLine,
);
if (expectedTimestampMatch != null) {
final expectedTimestamp = int.tryParse(expectedTimestampMatch.group(1)!);
final expectedTimestamp = int.tryParse(expectedTimestampMatch[1]!);
// The timestamp (value of the N_OSO symbol) in our snapshots is always 0.
Expect.equals(0, expectedTimestamp);
}
@@ -265,7 +265,7 @@ void checkDebugMaps(List<TestCase> testCases) {
for (final c in got) {
final gotLine = c[i];
if (expectedTriple != null) {
final gotTriple = _tripleLineRegExp.firstMatch(gotLine)?.group(1);
final gotTriple = _tripleLineRegExp.firstMatch(gotLine)?[1];
Expect.equals(expectedTriple, gotTriple);
} else if (isSymbol) {
Expect.isTrue(_symbolLineRegExp.hasMatch(gotLine));
@@ -343,9 +343,7 @@ testMacros() async {
.transform(LineSplitter())) {
Match? match = matchComplete(fieldEntry, line);
if (match != null) {
fields
.putIfAbsent(match.group(1)!, () => Set<String>())
.add(match.group(2)!);
fields.putIfAbsent(match[1]!, () => Set<String>()).add(match[2]!);
}
}
@@ -370,7 +368,7 @@ testMacros() async {
.transform(LineSplitter())) {
Match? match = matchComplete(classStart, line);
if (match != null) {
currentClass = match.group(1);
currentClass = match[1];
continue;
}
@@ -387,9 +385,9 @@ testMacros() async {
print("$currentClass is missing entirely.");
continue;
}
if (!fields[currentClass]!.contains(match.group(2)!)) {
if (!fields[currentClass]!.contains(match[2]!)) {
hasMissingFields = true;
print("$currentClass is missing ${match.group(2)!}.");
print("$currentClass is missing ${match[2]!}.");
}
}
}
@@ -156,7 +156,7 @@ class JSSyntaxRegExp implements RegExp {
String? stringMatch(String string) {
var match = firstMatch(string);
if (match != null) return match.group(0);
if (match != null) return match[0];
return null;
}
@@ -28,20 +28,22 @@ class StringMatch implements Match {
const StringMatch(int this.start, String this.input, String this.pattern);
int get end => start + pattern.length;
String operator [](int g) => group(g);
int get groupCount => 0;
String group(int group_) {
if (group_ != 0) {
throw RangeError.value(group_);
String operator [](int group) {
if (group != 0) {
throw RangeError.value(group);
}
return pattern;
}
List<String> groups(List<int> groups_) {
int get groupCount => 0;
String group(int group) => this[group];
List<String> groups(List<int> groupIndices) {
List<String> result = <String>[];
for (int g in groups_) {
result.add(group(g));
for (int g in groupIndices) {
result.add(this[g]);
}
return result;
}
@@ -163,7 +163,7 @@ class JSSyntaxRegExp implements RegExp {
String? stringMatch(String string) {
var match = firstMatch(string);
if (match != null) return match.group(0);
if (match != null) return match[0];
return null;
}
@@ -237,16 +237,16 @@ class _MatchImplementation implements RegExpMatch {
// The JS below changes the static type to avoid an implicit cast.
// TODO(sra): Find a nicer way to do this, e.g. unsafeCast.
String? group(int index) => JS('String|Null', '#', _match[index]);
String? group(int index) => this[index];
String? operator [](int index) => group(index);
String? operator [](int index) => JS('String|Null', '#', _match[index]);
int get groupCount => _match.length - 1;
List<String?> groups(List<int> groups) {
List<String?> out = [];
for (int i in groups) {
out.add(group(i));
out.add(this[i]);
}
return out;
}
@@ -42,20 +42,21 @@ class StringMatch implements Match {
const StringMatch(int this.start, String this.input, String this.pattern);
int get end => start + pattern.length;
String operator [](int g) => group(g);
int get groupCount => 0;
String group(int group_) {
if (group_ != 0) {
throw RangeError.value(group_);
String operator [](int group) {
if (group != 0) {
throw RangeError.value(group);
}
return pattern;
}
List<String> groups(List<int> groups_) {
int get groupCount => 0;
String group(int group) => this[group];
List<String> groups(List<int> groupIndices) {
List<String> result = <String>[];
for (int g in groups_) {
result.add(group(g));
for (int g in groupIndices) {
result.add(this[g]);
}
return result;
}
+6 -6
View File
@@ -94,6 +94,10 @@ class _RegExpMatch implements RegExpMatch {
}
String? group(int groupIdx) {
return this[groupIdx];
}
String? operator [](int groupIdx) {
if (groupIdx < 0 || groupIdx > _regexp._groupCount) {
throw RangeError.value(groupIdx);
}
@@ -106,14 +110,10 @@ class _RegExpMatch implements RegExpMatch {
return input._substringUnchecked(startIndex, endIndex);
}
String? operator [](int groupIdx) {
return this.group(groupIdx);
}
List<String?> groups(List<int> groupsSpec) {
var groupsList = List<String?>.filled(groupsSpec.length, null);
for (int i = 0; i < groupsSpec.length; i++) {
groupsList[i] = group(groupsSpec[i]);
groupsList[i] = this[groupsSpec[i]];
}
return groupsList;
}
@@ -131,7 +131,7 @@ class _RegExpMatch implements RegExpMatch {
var groupIndex = nameList[i + 1] as int;
if (name == groupName) {
if (_start(groupIndex) >= 0) {
return group(groupIndex);
return this[groupIndex];
}
// Keeping looking for a duplicated name.
exists = true;
+6 -5
View File
@@ -1406,20 +1406,21 @@ final class _StringMatch implements Match {
const _StringMatch(this.start, this.input, this.pattern);
int get end => start + pattern.length;
String operator [](int g) => group(g);
int get groupCount => 0;
String group(int group) {
String operator [](int group) {
if (group != 0) {
throw RangeError.value(group);
}
return pattern;
}
int get groupCount => 0;
String group(int group) => this[group];
List<String> groups(List<int> groups) {
List<String> result = <String>[];
for (int g in groups) {
result.add(group(g));
result.add(this[g]);
}
return result;
}
@@ -147,7 +147,7 @@ class JSSyntaxRegExp implements RegExp {
String? stringMatch(String string) {
var match = firstMatch(string);
if (match != null) return match.group(0);
if (match != null) return match[0];
return null;
}
@@ -199,20 +199,20 @@ class _MatchImplementation implements RegExpMatch {
int get end => (start + (_match[0].toString()).length);
String? group(int index) {
String? group(int index) => this[index];
String? operator [](int index) {
// index < 0 || index >= _match.length
IndexErrorUtils.checkIndex(index, _match.length);
return _match[index]?.toString();
}
String? operator [](int index) => group(index);
int get groupCount => _match.length - 1;
List<String?> groups(List<int> groups) {
List<String?> out = [];
for (int i in groups) {
out.add(group(i));
out.add(this[i]);
}
return out;
}
@@ -11,18 +11,19 @@ class StringMatch implements Match {
const StringMatch(this.start, this.input, this.pattern);
int get end => start + pattern.length;
String operator [](int g) => group(g);
int get groupCount => 0;
String group(int group) {
IndexErrorUtils.checkIndex(group, 1);
String operator [](int g) {
IndexErrorUtils.checkIndex(g, 1);
return pattern;
}
int get groupCount => 0;
String group(int group) => this[group];
List<String> groups(List<int> groups) {
List<String> result = <String>[];
for (int g in groups) {
result.add(group(g));
result.add(this[g]);
}
return result;
}
+5 -5
View File
@@ -100,11 +100,11 @@ abstract interface class Match {
/// final string = '[00:13.37] This is a chat message.';
/// final regExp = RegExp(r'^\[\s*(\d+):(\d+)\.(\d+)\]\s*(.*)$');
/// final match = regExp.firstMatch(string)!;
/// final message = jsonEncode(match[0]!); // '[00:13.37] This is a chat message.'
/// final hours = jsonEncode(match[1]!); // '00'
/// final minutes = jsonEncode(match[2]!); // '13'
/// final seconds = jsonEncode(match[3]!); // '37'
/// final text = jsonEncode(match[4]!); // 'This is a chat message.'
/// final message = jsonEncode(match.group(0)!); // '[00:13.37] This is a chat message.'
/// final hours = jsonEncode(match.group(1)!); // '00'
/// final minutes = jsonEncode(match.group(2)!); // '13'
/// final seconds = jsonEncode(match.group(3)!); // '37'
/// final text = jsonEncode(match.group(4)!); // 'This is a chat message.'
/// ```
String? group(int group);
+1 -1
View File
@@ -2677,7 +2677,7 @@ class SvgElement extends Element implements GlobalEventHandlers, NoncedElement {
final match = _START_TAG_REGEXP.firstMatch(svg);
Element parentElement;
if (match != null && match.group(1)!.toLowerCase() == 'svg') {
if (match != null && match[1]!.toLowerCase() == 'svg') {
parentElement = document.body!;
} else {
parentElement = new SvgSvgElement();
+15 -15
View File
@@ -17,9 +17,9 @@ class RegExpAllMatchesTest {
Expect.isNull(it.current);
}
Expect.isTrue(it.moveNext());
Expect.equals('foo', it.current.group(0));
Expect.equals('foo', it.current[0]);
Expect.isTrue(it.moveNext());
Expect.equals('foo', it.current.group(0));
Expect.equals('foo', it.current[0]);
Expect.isFalse(it.moveNext());
// Run two iterators over the same results.
@@ -27,12 +27,12 @@ class RegExpAllMatchesTest {
Iterator it2 = matches.iterator;
Expect.isTrue(it.moveNext());
Expect.isTrue(it2.moveNext());
Expect.equals('foo', it.current.group(0));
Expect.equals('foo', it2.current.group(0));
Expect.equals('foo', it.current[0]);
Expect.equals('foo', it2.current[0]);
Expect.isTrue(it.moveNext());
Expect.isTrue(it2.moveNext());
Expect.equals('foo', it.current.group(0));
Expect.equals('foo', it2.current.group(0));
Expect.equals('foo', it.current[0]);
Expect.equals('foo', it2.current[0]);
Expect.equals(false, it.moveNext());
Expect.equals(false, it2.moveNext());
}
@@ -41,14 +41,14 @@ class RegExpAllMatchesTest {
var matches = new RegExp("foo").allMatches("foo foo");
var strbuf = new StringBuffer();
matches.forEach((Match m) {
strbuf.write(m.group(0));
strbuf.write(m[0]);
});
Expect.equals("foofoo", strbuf.toString());
}
static testMap() {
var matches = new RegExp("foo?").allMatches("foo fo foo fo");
var mapped = matches.map((Match m) => "${m.group(0)}bar");
var mapped = matches.map((Match m) => "${m[0]}bar");
Expect.equals(4, mapped.length);
var strbuf = new StringBuffer();
for (String s in mapped) {
@@ -60,12 +60,12 @@ class RegExpAllMatchesTest {
static testFilter() {
var matches = new RegExp("foo?").allMatches("foo fo foo fo");
var filtered = matches.where((Match m) {
return m.group(0) == 'foo';
return m[0] == 'foo';
});
Expect.equals(2, filtered.length);
var strbuf = new StringBuffer();
for (Match m in filtered) {
strbuf.write(m.group(0));
strbuf.write(m[0]);
}
Expect.equals("foofoo", strbuf.toString());
}
@@ -75,13 +75,13 @@ class RegExpAllMatchesTest {
Expect.equals(
true,
matches.every((Match m) {
return m.group(0)!.startsWith("fo");
return m[0]!.startsWith("fo");
}),
);
Expect.equals(
false,
matches.every((Match m) {
return m.group(0)!.startsWith("foo");
return m[0]!.startsWith("foo");
}),
);
}
@@ -91,19 +91,19 @@ class RegExpAllMatchesTest {
Expect.equals(
true,
matches.any((Match m) {
return m.group(0)!.startsWith("fo");
return m[0]!.startsWith("fo");
}),
);
Expect.equals(
true,
matches.any((Match m) {
return m.group(0)!.startsWith("foo");
return m[0]!.startsWith("foo");
}),
);
Expect.equals(
false,
matches.any((Match m) {
return m.group(0)!.startsWith("fooo");
return m[0]!.startsWith("fooo");
}),
);
}
+3 -3
View File
@@ -9,9 +9,9 @@ import "package:expect/expect.dart";
class RegExpGroupTest {
static testMain() {
var match = new RegExp("(a(b)((c|de)+))").firstMatch("abcde")!;
Expect.equals('abcde', match.group(0));
Expect.equals('abcde', match.group(1));
Expect.equals('b', match.group(2));
Expect.equals('abcde', match[0]);
Expect.equals('abcde', match[1]);
Expect.equals('b', match[2]);
Expect.equals('cde', match[3]);
Expect.equals('de', match[4]);
}
+4
View File
@@ -11,9 +11,13 @@ class RegExpGroupsTest {
var match = new RegExp("(a(b)((c|de)+))").firstMatch("abcde")!;
var groups = match.groups([0, 4, 2, 3]);
Expect.equals('abcde', groups[0]);
Expect.equals('abcde', match.group(0));
Expect.equals('de', groups[1]);
Expect.equals('de', match.group(4));
Expect.equals('b', groups[2]);
Expect.equals('b', match.group(2));
Expect.equals('cde', groups[3]);
Expect.equals('cde', match.group(3));
}
}
@@ -55,7 +55,7 @@ void main() {
var regex06 = new RegExp(r"^(a+)\1*,\1+$");
Expect.equals(
"aaaaaaaaaa,aaaaaaaaaaaaaaa".replaceAllMapped(regex06, (m) => m.group(1)!),
"aaaaaaaaaa,aaaaaaaaaaaaaaa".replaceAllMapped(regex06, (m) => m[1]!),
"aaaaa",
);
@@ -33,18 +33,15 @@ void main() {
shouldBeNull((new RegExp("[\u0100-\u0101]")).firstMatch("a"));
shouldBeNull((new RegExp("[\u0100]")).firstMatch("a"));
shouldBeNull((new RegExp("\u0100")).firstMatch("a"));
assertEquals((new RegExp("[\u0061]")).firstMatch("a")!.group(0), "a");
assertEquals((new RegExp("[\u0100-\u0101a]")).firstMatch("a")!.group(0), "a");
assertEquals((new RegExp("[\u0100a]")).firstMatch("a")!.group(0), "a");
assertEquals((new RegExp("\u0061")).firstMatch("a")!.group(0), "a");
assertEquals((new RegExp("[a-\u0100]")).firstMatch("a")!.group(0), "a");
assertEquals((new RegExp("[\u0061]")).firstMatch("a")![0], "a");
assertEquals((new RegExp("[\u0100-\u0101a]")).firstMatch("a")![0], "a");
assertEquals((new RegExp("[\u0100a]")).firstMatch("a")![0], "a");
assertEquals((new RegExp("\u0061")).firstMatch("a")![0], "a");
assertEquals((new RegExp("[a-\u0100]")).firstMatch("a")![0], "a");
assertEquals((new RegExp("[\u0100]")).firstMatch("\u0100")![0], "\u0100");
assertEquals(
(new RegExp("[\u0100]")).firstMatch("\u0100")!.group(0),
(new RegExp("[\u0100-\u0101]")).firstMatch("\u0100")![0],
"\u0100",
);
assertEquals(
(new RegExp("[\u0100-\u0101]")).firstMatch("\u0100")!.group(0),
"\u0100",
);
assertEquals((new RegExp("\u0100")).firstMatch("\u0100")!.group(0), "\u0100");
assertEquals((new RegExp("\u0100")).firstMatch("\u0100")![0], "\u0100");
}
+15 -15
View File
@@ -43,7 +43,7 @@ void main() {
str = "It was a pleasure to burn.";
str = str.replaceAllMapped(
new RegExp(r"(?=(\w+))\b"),
(Match m) => m.group(1)!.length.toString(),
(Match m) => m[1]!.length.toString(),
);
assertEquals("2It 3was 1a 8pleasure 2to 4burn.", str);
@@ -52,9 +52,9 @@ void main() {
str = str.replaceAllMapped(
new RegExp(r"(not?)|(do)|(try)", caseSensitive: false),
(m) {
if (m.group(1) != null) return "-";
if (m.group(2) != null) return "+";
if (m.group(3) != null) return "=";
if (m[1] != null) return "-";
if (m[2] != null) return "+";
if (m[3] != null) return "=";
throw 'Unexpected match $m';
},
);
@@ -63,9 +63,9 @@ void main() {
// Test multiple alternate captures.
str = "FOUR LEGS GOOD, TWO LEGS BAD!";
str = str.replaceAllMapped(new RegExp(r"(FOUR|TWO) LEGS (GOOD|BAD)"), (m) {
if (m.group(1) == "FOUR") assertTrue(m.group(2) == "GOOD");
if (m.group(1) == "TWO") assertTrue(m.group(2) == "BAD");
return (m.group(0)!.length - 10).toString();
if (m[1] == "FOUR") assertTrue(m[2] == "GOOD");
if (m[1] == "TWO") assertTrue(m[2] == "BAD");
return (m[0]!.length - 10).toString();
});
assertEquals("4, 2!", str);
@@ -84,7 +84,7 @@ void main() {
str = "It was a pleasure to \u70e7.";
str = str.replaceAllMapped(
new RegExp(r"(?=(\w+))\b"),
(m) => "${m.group(1)!.length}",
(m) => "${m[1]!.length}",
);
assertEquals("2It 3was 1a 8pleasure 2to \u70e7.", str);
@@ -93,9 +93,9 @@ void main() {
str = str.replaceAllMapped(
new RegExp(r"(not?)|(d\u26aa)|(try)", caseSensitive: false),
(m) {
if (m.group(1) != null) return "-";
if (m.group(2) != null) return "+";
if (m.group(3) != null) return "=";
if (m[1] != null) return "-";
if (m[2] != null) return "+";
if (m[3] != null) return "=";
throw 'Unexpected match $m';
},
);
@@ -104,9 +104,9 @@ void main() {
// Test multiple alternate captures.
str = "FOUR \u817f GOOD, TWO \u817f BAD!";
str = str.replaceAllMapped(new RegExp(r"(FOUR|TWO) \u817f (GOOD|BAD)"), (m) {
if (m.group(1) == "FOUR") assertTrue(m.group(2) == "GOOD");
if (m.group(1) == "TWO") assertTrue(m.group(2) == "BAD");
return (m.group(0)!.length - 7).toString();
if (m[1] == "FOUR") assertTrue(m[2] == "GOOD");
if (m[1] == "TWO") assertTrue(m[2] == "BAD");
return (m[0]!.length - 7).toString();
});
assertEquals("4, 2!", str);
@@ -120,7 +120,7 @@ void main() {
str = "up up up up";
str = str.replaceAllMapped(
new RegExp(r"\b(?=u(p))"),
(m) => "${m.group(1)!.length}",
(m) => "${m[1]!.length}",
);
assertEquals("1up 1up 1up 1up", str);
+1 -1
View File
@@ -43,7 +43,7 @@ void main() {
var length = matches[idx][1];
var expected = str.substring(from, from + length);
var name = "$str[$from..${from + length}]";
assertEquals(expected, result[idx].group(0), name);
assertEquals(expected, result[idx][0], name);
}
} else {
assertTrue(result.isEmpty);
+6 -4
View File
@@ -32,13 +32,15 @@ void main() {
var re = new RegExp(r"[^\s$]+");
var accumulate = "";
var match;
for (var match in re.allMatches(" abcdefg"))
accumulate += match.group(0)! + "; ";
for (var match in re.allMatches(" abcdefg")) {
accumulate += match[0]! + "; ";
}
assertEquals(accumulate, "abcdefg; ");
re = new RegExp(r"\d");
accumulate = "";
for (var match in re.allMatches("123456789"))
accumulate += match.group(0)! + "; ";
for (var match in re.allMatches("123456789")) {
accumulate += match[0]! + "; ";
}
assertEquals(accumulate, "1; 2; 3; 4; 5; 6; 7; 8; 9; ");
}
@@ -93,7 +93,7 @@ void main() {
assertTrue(m1 != null);
assertEquals(m1!.groupCount, m2.groupCount);
for (int i = 0; i < m1.groupCount; i++) {
assertEquals(m1.group(i), m2.group(i));
assertEquals(m1[i], m2[i]);
}
}
}
+26 -32
View File
@@ -33,70 +33,64 @@ void main() {
);
shouldBeNull(new RegExp(r"\\x{41}").firstMatch("yA1"));
assertEquals(new RegExp(r"[\x{41}]").firstMatch("yA1")!.group(0), "1");
assertEquals(new RegExp(r"\x1g").firstMatch("x1g")!.group(0), "x1g");
assertEquals(new RegExp(r"[\x1g]").firstMatch("x")!.group(0), "x");
assertEquals(new RegExp(r"[\x1g]").firstMatch("1")!.group(0), "1");
assertEquals(new RegExp(r"[\x{41}]").firstMatch("yA1")![0], "1");
assertEquals(new RegExp(r"\x1g").firstMatch("x1g")![0], "x1g");
assertEquals(new RegExp(r"[\x1g]").firstMatch("x")![0], "x");
assertEquals(new RegExp(r"[\x1g]").firstMatch("1")![0], "1");
assertEquals(
new RegExp(
r"\2147483648",
).firstMatch(new String.fromCharCode(140) + "7483648")!.group(0),
).firstMatch(new String.fromCharCode(140) + "7483648")![0],
new String.fromCharCode(140) + "7483648",
);
assertEquals(
new RegExp(r"\4294967296").firstMatch("\"94967296")!.group(0),
new RegExp(r"\4294967296").firstMatch("\"94967296")![0],
"\"94967296",
);
assertEquals(
new RegExp(r"\8589934592").firstMatch("\8589934592")!.group(0),
new RegExp(r"\8589934592").firstMatch("\8589934592")![0],
"\8589934592",
);
assertEquals(
"\nAbc\n".replaceAllMapped(new RegExp(r"(\n)[^\n]+$"), (m) => m.group(1)!),
"\nAbc\n".replaceAllMapped(new RegExp(r"(\n)[^\n]+$"), (m) => m[1]!),
"\nAbc\n",
);
shouldBeNull(new RegExp(r"x$").firstMatch("x\n"));
assertThrows(() => new RegExp(r"x++"));
shouldBeNull(new RegExp(r"[]]").firstMatch("]"));
assertEquals(new RegExp(r"\060").firstMatch("y01")!.group(0), "0");
assertEquals(new RegExp(r"[\060]").firstMatch("y01")!.group(0), "0");
assertEquals(new RegExp(r"\606").firstMatch("y06")!.group(0), "06");
assertEquals(new RegExp(r"[\606]").firstMatch("y06")!.group(0), "0");
assertEquals(new RegExp(r"[\606]").firstMatch("y6")!.group(0), "6");
assertEquals(new RegExp(r"\101").firstMatch("yA1")!.group(0), "A");
assertEquals(new RegExp(r"[\101]").firstMatch("yA1")!.group(0), "A");
assertEquals(new RegExp(r"\1011").firstMatch("yA1")!.group(0), "A1");
assertEquals(new RegExp(r"[\1011]").firstMatch("yA1")!.group(0), "A");
assertEquals(new RegExp(r"[\1011]").firstMatch("y1")!.group(0), "1");
assertEquals(new RegExp(r"\060").firstMatch("y01")![0], "0");
assertEquals(new RegExp(r"[\060]").firstMatch("y01")![0], "0");
assertEquals(new RegExp(r"\606").firstMatch("y06")![0], "06");
assertEquals(new RegExp(r"[\606]").firstMatch("y06")![0], "0");
assertEquals(new RegExp(r"[\606]").firstMatch("y6")![0], "6");
assertEquals(new RegExp(r"\101").firstMatch("yA1")![0], "A");
assertEquals(new RegExp(r"[\101]").firstMatch("yA1")![0], "A");
assertEquals(new RegExp(r"\1011").firstMatch("yA1")![0], "A1");
assertEquals(new RegExp(r"[\1011]").firstMatch("yA1")![0], "A");
assertEquals(new RegExp(r"[\1011]").firstMatch("y1")![0], "1");
assertEquals(
new RegExp(
r"\10q",
).firstMatch("y" + new String.fromCharCode(8) + "q")!.group(0),
new RegExp(r"\10q").firstMatch("y" + new String.fromCharCode(8) + "q")![0],
new String.fromCharCode(8) + "q",
);
assertEquals(
new RegExp(
r"[\10q]",
).firstMatch("y" + new String.fromCharCode(8) + "q")!.group(0),
).firstMatch("y" + new String.fromCharCode(8) + "q")![0],
new String.fromCharCode(8),
);
assertEquals(
new RegExp(
r"\1q",
).firstMatch("y" + new String.fromCharCode(1) + "q")!.group(0),
new RegExp(r"\1q").firstMatch("y" + new String.fromCharCode(1) + "q")![0],
new String.fromCharCode(1) + "q",
);
assertEquals(
new RegExp(
r"[\1q]",
).firstMatch("y" + new String.fromCharCode(1) + "q")!.group(0),
new RegExp(r"[\1q]").firstMatch("y" + new String.fromCharCode(1) + "q")![0],
new String.fromCharCode(1),
);
assertEquals(new RegExp(r"[\1q]").firstMatch("yq")!.group(0), "q");
assertEquals(new RegExp(r"\8q").firstMatch("\8q")!.group(0), "\8q");
assertEquals(new RegExp(r"[\8q]").firstMatch("y8q")!.group(0), "8");
assertEquals(new RegExp(r"[\8q]").firstMatch("yq")!.group(0), "q");
assertEquals(new RegExp(r"[\1q]").firstMatch("yq")![0], "q");
assertEquals(new RegExp(r"\8q").firstMatch("\8q")![0], "\8q");
assertEquals(new RegExp(r"[\8q]").firstMatch("y8q")![0], "8");
assertEquals(new RegExp(r"[\8q]").firstMatch("yq")![0], "q");
shouldBe(new RegExp(r"(x)\1q").firstMatch("xxq"), ["xxq", "x"]);
shouldBe(new RegExp(r"(x)[\1q]").firstMatch("xxq"), ["xq", "x"]);
shouldBe(
+6 -18
View File
@@ -36,28 +36,16 @@ void main() {
var surrogatePair =
new String.fromCharCode(0xD800) + new String.fromCharCode(0xDC00);
assertEquals(new RegExp(r".").firstMatch(surrogatePair)!.group(0)!.length, 1);
assertEquals(
new RegExp(r"\D").firstMatch(surrogatePair)!.group(0)!.length,
1,
);
assertEquals(
new RegExp(r"\S").firstMatch(surrogatePair)!.group(0)!.length,
1,
);
assertEquals(
new RegExp(r"\W").firstMatch(surrogatePair)!.group(0)!.length,
1,
);
assertEquals(
new RegExp(r"[^x]").firstMatch(surrogatePair)!.group(0)!.length,
1,
);
assertEquals(new RegExp(r".").firstMatch(surrogatePair)![0]!.length, 1);
assertEquals(new RegExp(r"\D").firstMatch(surrogatePair)![0]!.length, 1);
assertEquals(new RegExp(r"\S").firstMatch(surrogatePair)![0]!.length, 1);
assertEquals(new RegExp(r"\W").firstMatch(surrogatePair)![0]!.length, 1);
assertEquals(new RegExp(r"[^x]").firstMatch(surrogatePair)![0]!.length, 1);
assertEquals(
new RegExp(
r".{1,2}",
).firstMatch("!!" + new String.fromCharCode(0xA1))!.group(0)!.length,
).firstMatch("!!" + new String.fromCharCode(0xA1))![0]!.length,
2,
);
shouldBeNull(new RegExp(r".").firstMatch(""));
@@ -42,15 +42,15 @@ void main() {
assertEquals("y".indexOf(new RegExp(r"(x)?\1y")), 0);
assertEquals("y".replaceAll(new RegExp(r"(x)?\1y"), "z"), "z");
assertEquals(
"y".replaceAllMapped(new RegExp(r"(x)?y"), (m) => m.group(1) ?? "null"),
"y".replaceAllMapped(new RegExp(r"(x)?y"), (m) => m[1] ?? "null"),
"null",
);
assertEquals(
"y".replaceAllMapped(new RegExp(r"(x)?\1y"), (m) => m.group(1) ?? "null"),
"y".replaceAllMapped(new RegExp(r"(x)?\1y"), (m) => m[1] ?? "null"),
"null",
);
assertEquals(
"y".replaceAllMapped(new RegExp(r"(x)?y"), (m) => m.group(1) ?? "null"),
"y".replaceAllMapped(new RegExp(r"(x)?y"), (m) => m[1] ?? "null"),
"null",
);
}
+1 -1
View File
@@ -394,7 +394,7 @@ void main() {
Expect.listEquals(
regexp59
.allMatches('Y aaa X Match1 Y aaa Y Match2 Z')
.map((m) => m.group(0))
.map((m) => m[0])
.toList(),
['X Match1 Y', 'Y Match2 Z'],
);
+1 -1
View File
@@ -850,7 +850,7 @@ void main() {
input1 = "\u0100aY\u0256Z";
results = ["\u0100", "Y\u0256Z"];
Expect.listEquals(
regexGlobal0.allMatches(input1).map((m) => m.group(0)).toList(),
regexGlobal0.allMatches(input1).map((m) => m[0]).toList(),
results,
);
+10 -10
View File
@@ -40,45 +40,45 @@ void main() {
var pattern = new RegExp(r"^\d", multiLine: true);
var resultList = pattern.allMatches(string).toList();
assertEquals(2, resultList.length, "1");
assertEquals('7', resultList[0].group(0), "2");
assertEquals('3', resultList[1].group(0), "3");
assertEquals('7', resultList[0][0], "2");
assertEquals('3', resultList[1][0], "3");
pattern = new RegExp(r"\d$", multiLine: true);
resultList = pattern.allMatches(string).toList();
assertEquals(2, resultList.length, "4");
assertEquals('9', resultList[0].group(0), "5");
assertEquals('5', resultList[1].group(0), "6");
assertEquals('9', resultList[0][0], "5");
assertEquals('5', resultList[1][0], "6");
string = 'aaa\n789\r\nccc\r\nddd';
pattern = new RegExp(r"^\d", multiLine: true);
resultList = pattern.allMatches(string).toList();
assertEquals(1, resultList.length, "7");
assertEquals('7', resultList[0].group(0), "8");
assertEquals('7', resultList[0][0], "8");
pattern = new RegExp(r"\d$", multiLine: true);
resultList = pattern.allMatches(string).toList();
assertEquals(1, resultList.length, "9");
assertEquals('9', resultList[0].group(0), "10");
assertEquals('9', resultList[0][0], "10");
// Tests from ecma_3/RegExp/regress-72964.js
pattern = new RegExp(r"[\S]+");
string = '\u00BF\u00CD\u00BB\u00A7';
var resultMatch = pattern.firstMatch(string)!;
assertEquals(1, resultMatch.groupCount + 1, "11");
assertEquals(string, resultMatch.group(0), "12");
assertEquals(string, resultMatch[0], "12");
string = '\u00BF\u00CD \u00BB\u00A7';
resultMatch = pattern.firstMatch(string)!;
assertEquals(1, resultMatch.groupCount + 1, "13");
assertEquals('\u00BF\u00CD', resultMatch.group(0), "14");
assertEquals('\u00BF\u00CD', resultMatch[0], "14");
string = '\u4e00\uac00\u4e03\u4e00';
resultMatch = pattern.firstMatch(string)!;
assertEquals(1, resultMatch.groupCount + 1, "15");
assertEquals(string, resultMatch.group(0), "16");
assertEquals(string, resultMatch[0], "16");
string = '\u4e00\uac00 \u4e03\u4e00';
resultMatch = pattern.firstMatch(string)!;
assertEquals(1, resultMatch.groupCount + 1, "17");
assertEquals('\u4e00\uac00', resultMatch.group(0), "18");
assertEquals('\u4e00\uac00', resultMatch[0], "18");
}
@@ -53,7 +53,7 @@ void main() {
var b = I3.firstMatch(a);
if (b != null) {
a = b.group(2);
a = b[2];
}
return Gn(a);
@@ -66,12 +66,12 @@ void main() {
var sample = "sample bm\u2820p cm\\u2820p";
var inlineRe = new RegExp(r".m\u2820p");
assertEquals(inlineRe.firstMatch(sample)!.group(0), 'bm\u2820p');
assertEquals(inlineRe.firstMatch(sample)![0], 'bm\u2820p');
// Test handling of \u007c "|"
var bsample = "sample bm\u007cp cm\\u007cp";
var binlineRe = new RegExp(r".m\u007cp");
assertEquals(binlineRe.firstMatch(bsample)!.group(0), 'bm|p');
assertEquals(binlineRe.firstMatch(bsample)![0], 'bm|p');
}
+3 -3
View File
@@ -33,7 +33,7 @@ void assertNull(actual, [num? testid = null]) {
void assertToStringEquals(str, match, num? testid) {
var actual = [];
for (int i = 0; i <= match.groupCount; i++) {
var g = match.group(i);
var g = match[i];
actual.add((g == null) ? "" : g);
}
Expect.equals(str, actual.join(","), "Test $testid");
@@ -57,13 +57,13 @@ void shouldBe(actual, expected, [String message = '']) {
} else {
Expect.equals(expected.length, actual.groupCount + 1);
for (int i = 0; i <= actual.groupCount; i++) {
Expect.equals(expected[i], actual.group(i), message);
Expect.equals(expected[i], actual[i], message);
}
}
}
Match? firstMatch(String str, RegExp pattern) => pattern.firstMatch(str);
List<String?> allStringMatches(String str, RegExp pattern) =>
pattern.allMatches(str).map((Match m) => m.group(0)).toList();
pattern.allMatches(str).map((Match m) => m[0]).toList();
void description(str) {}
+2 -2
View File
@@ -12,8 +12,8 @@ class RegEx2Test {
print("got match");
int groupCount = match.groupCount;
print("groupCount is $groupCount");
print("group 0 is ${match.group(0)}");
print("group 1 is ${match.group(1)}");
print("group 0 is ${match[0]}");
print("group 1 is ${match[1]}");
} else {
print("match not round");
}
+3 -3
View File
@@ -10,9 +10,9 @@ void main() {
String str = "Parse my string";
List<Match> matches = exp.allMatches(str).toList();
Expect.equals(3, matches.length);
Expect.equals("Parse", matches[0].group(0));
Expect.equals("my", matches[1].group(0));
Expect.equals("string", matches[2].group(0));
Expect.equals("Parse", matches[0][0]);
Expect.equals("my", matches[1][0]);
Expect.equals("string", matches[2][0]);
// Check that allMatches progresses correctly for empty matches, and that
// it includes the empty match at the end position.
+1 -1
View File
@@ -284,7 +284,7 @@ Iterable<int> parseUsingAddressRegExp(RegExp re, Iterable<String> lines) sync* {
for (final line in lines) {
final match = re.firstMatch(line);
if (match == null) continue;
final s = match.group(1);
final s = match[1];
if (s == null) continue;
yield int.parse(s, radix: 16);
}
+6 -6
View File
@@ -105,19 +105,19 @@ testVersion() {
if (match == null) {
throw new FormatException();
}
var major = int.parse(match.group(1)!);
var major = int.parse(match[1]!);
// Major version.
Expect.isTrue(major == 1 || major == 2 || major == 3);
// Minor version.
Expect.isTrue(int.parse(match.group(2)!) >= 0);
Expect.isTrue(int.parse(match[2]!) >= 0);
// Patch version.
Expect.isTrue(int.parse(match.group(3)!) >= 0);
Expect.isTrue(int.parse(match[3]!) >= 0);
// Dev
if (match.group(4) != null) {
if (match[4] != null) {
// Dev prerelease minor version
Expect.isTrue(int.parse(match.group(5)!) >= 0);
Expect.isTrue(int.parse(match[5]!) >= 0);
// Dev prerelease patch version
Expect.isTrue(int.parse(match.group(6)!) >= 0);
Expect.isTrue(int.parse(match[6]!) >= 0);
}
}
@@ -81,7 +81,7 @@ void setup() {
expectTypeName(expectedName, s) {
var m = new RegExp(r"Instance of '(.*)'").firstMatch(s);
Expect.isNotNull(m);
var name = m!.group(1);
var name = m![1];
Expect.isTrue(
expectedName == name || name!.length <= 3 || name!.startsWith('minified:'),
"Is '$expectedName' or minified: '$name'",
+2 -2
View File
@@ -127,7 +127,7 @@ List<(String?, int?, int?, String?)?> parseStack(
if (hexOffsetMatch == null) {
throw 'Unable to parse hex offset in frame "$line"';
}
final hexOffsetStr = hexOffsetMatch.group(1)!; // includes '0x'
final hexOffsetStr = hexOffsetMatch[1]!; // includes '0x'
final offset = int.tryParse(hexOffsetStr);
if (offset == null) {
throw 'Unable to parse hex number in frame "$line"';
@@ -136,7 +136,7 @@ List<(String?, int?, int?, String?)?> parseStack(
if (moduleIdMatch == null) {
throw 'Unable to parse module name in frame "$line"';
}
final moduleIdString = moduleIdMatch.group(1)!;
final moduleIdString = moduleIdMatch[1]!;
final moduleId = isMinified
? parseMinifiedModule(moduleIdString)
: int.parse(moduleIdString.replaceAll('module', ''));
@@ -53,5 +53,5 @@ final RegExp classRegexp = RegExp(r'minified:(Class\d+)');
String unminify(String input, Dart2jsMapping mapping) => input.replaceAllMapped(
classRegexp,
(match) => mapping.globalNames[match.group(1)!]!,
(match) => mapping.globalNames[match[1]!]!,
);
+1 -2
View File
@@ -38,8 +38,7 @@ class CodeGenerator {
name
.replaceAll(RegExp(r'^_+'), '')
// Also replace any other underscores to make camelCase
.replaceAllMapped(
RegExp(r'_(.)'), (m) => m.group(1)!.toUpperCase());
.replaceAllMapped(RegExp(r'_(.)'), (m) => m[1]!.toUpperCase());
}
/// Re-wraps [lines] at [maxLength] to help keep comments for indented code
+3 -3
View File
@@ -388,13 +388,13 @@ class Package implements Comparable<Package> {
var match = importRegex1.firstMatch(line);
if (match != null) {
results.add(match.group(2)!);
results.add(match[2]!);
continue;
}
match = importRegex2.firstMatch(line);
if (match != null) {
results.add(match.group(2)!);
results.add(match[2]!);
continue;
}
}
@@ -444,7 +444,7 @@ class SdkDeps {
var pkgDep = pkgRegExp.firstMatch(line);
if (pkgDep != null) {
pkgs.add(pkgDep.group(1)!);
pkgs.add(pkgDep[1]!);
}
}
+1 -1
View File
@@ -157,7 +157,7 @@ Set<String> calculatePinnedDeps() {
return depsFile
.readAsLinesSync()
.where((line) => packageRevision.hasMatch(line) && line.contains('", #'))
.map((line) => packageRevision.firstMatch(line)!.group(1)!)
.map((line) => packageRevision.firstMatch(line)![1]!)
.toSet();
}