Chromium Code Reviews| Index: sdk/lib/_internal/pub/lib/src/utils.dart |
| diff --git a/sdk/lib/_internal/pub/lib/src/utils.dart b/sdk/lib/_internal/pub/lib/src/utils.dart |
| index dc25e539b9368e0209414c94d1c5a83765a80e4f..bfe64d5c40f35596d991eee4a4a42f878cca6d25 100644 |
| --- a/sdk/lib/_internal/pub/lib/src/utils.dart |
| +++ b/sdk/lib/_internal/pub/lib/src/utils.dart |
| @@ -202,6 +202,23 @@ String pluralize(String name, int number, {String plural}) { |
| return '${name}s'; |
| } |
| +/// Escapes any regex metacharacters in [string] so that using as a [RegExp] |
| +/// pattern will match the string literally. |
| +// TODO(rnystrom): Remove when #4706 is fixed. |
| +String quoteRegExp(String string) { |
| + // Note: make sure "\" is done first so that we don't escape the other |
| + // escaped characters. We could do all of the replaces at once with a regexp |
| + // but string literal for regex that matches all regex metacharacters would |
| + // be a bit hard to read. |
| + for (var metacharacter in r"\^$.*+?()[]{}|".split("")) { |
| + string = string.replaceAll(metacharacter, "\\$metacharacter"); |
| + } |
| + |
| + return string; |
| +} |
| + |
| +const _regExpMetacharacters = const [r"\", '"', "'", r"$", r"^"]; |
|
nweiz
2014/01/06 23:34:50
Unused constant.
Bob Nystrom
2014/01/07 18:52:50
Done.
|
| + |
| /// Creates a URL string for [address]:[port]. |
| /// |
| /// Handles properly formatting IPv6 addresses. |