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

Unified Diff: pkg/analyzer/lib/src/generated/java_core.dart

Issue 475543002: New analyzer snapshot, add format/formatList. (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/analyzer/lib/src/generated/java_core.dart
diff --git a/pkg/analyzer/lib/src/generated/java_core.dart b/pkg/analyzer/lib/src/generated/java_core.dart
index 64ae98686aa798848e87c9cf1c59ae72e2ac0a38..a1a74ad85831e6f476280e146119d0ef498bc4e1 100644
--- a/pkg/analyzer/lib/src/generated/java_core.dart
+++ b/pkg/analyzer/lib/src/generated/java_core.dart
@@ -132,21 +132,6 @@ class CharBuffer extends CharSequence {
}
class JavaString {
- static String format(String fmt, List args) {
- var index = 0;
- return fmt.replaceAllMapped(new RegExp(r'%(.)'), (match) {
- switch (match.group(1)) {
- case '%': return '%';
- case 'd':
- case 's':
- if (index >= args.length) {
- throw new MissingFormatArgumentException(match.group(0));
- }
- return args[index++].toString();
- default: return match.group(1);
- }
- });
- }
static int indexOf(String target, String str, int fromIndex) {
if (fromIndex > target.length) return -1;
if (fromIndex < 0) fromIndex = 0;
@@ -523,3 +508,31 @@ class JavaPatternMatcher {
int start() => _match.start;
int end() => _match.end;
}
+
+/**
+ * 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])
+ {
+ 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;
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698