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

Unified Diff: sdk/lib/_internal/lib/core_patch.dart

Issue 515183002: Make String.fromCharCodes take start/end. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Bug in dart2js version. 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: sdk/lib/_internal/lib/core_patch.dart
diff --git a/sdk/lib/_internal/lib/core_patch.dart b/sdk/lib/_internal/lib/core_patch.dart
index 85ab0b9246ffed5c5d9d55d3223eaf31032a5be7..1deb59f6eec490419bd8da1edab486aa4362ca7b 100644
--- a/sdk/lib/_internal/lib/core_patch.dart
+++ b/sdk/lib/_internal/lib/core_patch.dart
@@ -270,11 +270,32 @@ class List<E> {
@patch
class String {
@patch
- factory String.fromCharCodes(Iterable<int> charCodes) {
- if (charCodes is! JSArray) {
- charCodes = new List.from(charCodes);
+ factory String.fromCharCodes(Iterable<int> charCodes,
+ [int start = 0, int end]) {
+ if (start < 0) start = 0;
Søren Gjesse 2014/08/29 11:16:03 ArgumentError?
Lasse Reichstein Nielsen 2014/09/02 07:57:05 Done.
+ List list;
+ if (charCodes is JSArray) {
floitsch 2014/08/29 11:13:20 does it need to be a JSArray? Or can we use isJsIn
Lasse Reichstein Nielsen 2014/09/02 07:57:04 No idea - I was going by the existing code only.
+ list = charCodes;
+ // If possible, recognize typed lists too.
+ int len = list.length;
+ if (end == null || end > len) end = len;
+ if (start > 0 || end < len) {
+ if (start >= end) return "";
+ charCodes = list.sublist(start, end);
Lasse Reichstein Nielsen 2014/09/02 07:57:04 should be "list = ...".
+ }
+ } else {
+ if (end != null) {
+ if (start >= end) return "";
+ charCodes = charCodes.take(end);
+ }
+ if (start > 0) charCodes = charCodes.skip(start);
+ list = charCodes.toList(); // Try the iterable's own toList first.
+ if (list is! JSArray) {
+ // If that fails, force a JSArray.
+ list = new List.from(charCodes);
Lasse Reichstein Nielsen 2014/09/02 07:57:05 should be .from(list);
+ }
}
- return Primitives.stringFromCharCodes(charCodes);
+ return Primitives.stringFromCharCodes(list);
}
@patch

Powered by Google App Engine
This is Rietveld 408576698