Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: pkg/analysis_services/lib/src/correction/strings.dart

Issue 464363004: 'Rename Constructor' refactoring. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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) {

Powered by Google App Engine
This is Rietveld 408576698