Chromium Code Reviews| Index: pkg/analysis_services/lib/src/correction/strings.dart |
| diff --git a/pkg/analysis_services/lib/src/correction/strings.dart b/pkg/analysis_services/lib/src/correction/strings.dart |
| index a72b6f6837bc3dbdd5e47bb23bfb4df03b3e3c6c..e6ede208ba25477cf2a13869546d69a9b77337e4 100644 |
| --- a/pkg/analysis_services/lib/src/correction/strings.dart |
| +++ b/pkg/analysis_services/lib/src/correction/strings.dart |
| @@ -42,6 +42,34 @@ int compareStrings(String a, String b) { |
| } |
| /** |
| + * Inserts the given arguments into [pattern]. |
| + * |
| + * format('Hello, {0}!', 'John') = 'Hello, John!' |
| + * format('{0} are you {1}ing?', 'How', 'do') = 'How are you doing?' |
| + * format('{0} are you {1}ing?', 'What', 'read') = 'What are you reading?' |
| + */ |
| +String format(String pattern, [arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7]) |
|
Brian Wilkerson
2014/08/13 18:39:19
(Is it really the case that there is no built-in s
scheglov
2014/08/13 18:53:22
Will do.
In the next CL.
|
| + { |
| + return formatList(pattern, [arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7]); |
| +} |
| + |
| +/** |
| + * Inserts the given [args] into [pattern]. |
| + * |
| + * format('Hello, {0}!', ['John']) = 'Hello, John!' |
| + * format('{0} are you {1}ing?', ['How', 'do']) = 'How are you doing?' |
| + * format('{0} are you {1}ing?', ['What', 'read']) = 'What are you reading?' |
| + */ |
| +String formatList(String pattern, List args) { |
| + return pattern.replaceAllMapped(new RegExp(r'\{(\d+)\}'), (match) { |
| + String indexStr = match.group(1); |
| + int index = int.parse(indexStr); |
| + var arg = args[index]; |
| + return arg != null ? arg.toString() : null; |
| + }); |
| +} |
| + |
| +/** |
| * Checks if [str] is `null`, empty or is whitespace. |
| */ |
| bool isBlank(String str) { |