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

Unified Diff: editor/util/plugins/com.google.dart.java2dart/resources/java_core.dart

Issue 14520017: Support a subset of String.format in java2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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: editor/util/plugins/com.google.dart.java2dart/resources/java_core.dart
diff --git a/editor/util/plugins/com.google.dart.java2dart/resources/java_core.dart b/editor/util/plugins/com.google.dart.java2dart/resources/java_core.dart
index 0c40a7e867d9c80e0a0325b580ca5fff8e470570..063c7d59ce7d3b6097c90dce01cdee14305f1f7f 100644
--- a/editor/util/plugins/com.google.dart.java2dart/resources/java_core.dart
+++ b/editor/util/plugins/com.google.dart.java2dart/resources/java_core.dart
@@ -130,7 +130,18 @@ class CharBuffer extends CharSequence {
class JavaString {
static String format(String fmt, List args) {
- return fmt;
+ var index = 0;
+ return fmt.replaceAllMapped(new RegExp(r'%(.)'), (match) {
+ switch (match.group(1)) {
+ case '%': return '%';
+ case 's':
+ if (index >= args.length) {
+ throw new MissingFormatArgumentException(match.group(0));
+ }
+ return args[index++].toString();
+ default: return match.group(1);
+ }
+ });
}
}
@@ -263,6 +274,14 @@ class IOException implements Exception {
String toString() => "IOException";
}
+class MissingFormatArgumentException implements Exception {
+ final String s;
+
+ String toString() => "MissingFormatArgumentException: $s";
+
+ MissingFormatArgumentException(this.s);
+}
+
class ListWrapper<E> extends ListBase<E> implements List<E> {
List<E> elements = new List<E>();

Powered by Google App Engine
This is Rietveld 408576698