| Index: runtime/lib/string_patch.dart
|
| diff --git a/runtime/lib/string_patch.dart b/runtime/lib/string_patch.dart
|
| index 8542af5c494511333d05b2af5d4bb3856d7bf754..12f8d0edf8154c38d35d07434711f76c93f307af 100644
|
| --- a/runtime/lib/string_patch.dart
|
| +++ b/runtime/lib/string_patch.dart
|
| @@ -302,26 +302,17 @@ class _StringBase {
|
| }
|
| }
|
|
|
| - String repeat(int times, [String separator = ""]) {
|
| - if (times < 0) throw new RangeError.value(times);
|
| - if (times == 0) return "";
|
| + String operator*(int times) {
|
| + if (times <= 0) return "";
|
| if (times == 1) return this;
|
| StringBuffer buffer = new StringBuffer(this);
|
| - if (separator.isEmpty) {
|
| - for (int i = 1; i < times; i++) {
|
| - buffer.write(this);
|
| - }
|
| - return buffer.toString();
|
| - }
|
| for (int i = 1; i < times; i++) {
|
| - buffer.write(separator);
|
| buffer.write(this);
|
| }
|
| return buffer.toString();
|
| }
|
|
|
| - String padLeft(int newLength, String padding) {
|
| - if (padding.length != 1) throw new ArgumentError(padding);
|
| + String padLeft(int newLength, [String padding = ' ']) {
|
| int delta = newLength - this.length;
|
| if (delta <= 0) return this;
|
| StringBuffer buffer = new StringBuffer();
|
| @@ -332,12 +323,10 @@ class _StringBase {
|
| return buffer.toString();
|
| }
|
|
|
| - String padRight(int newLength, String padding, { int size }) {
|
| - if (padding.length != 1) throw new ArgumentError(padding);
|
| + String padRight(int newLength, [String padding = ' ']) {
|
| int delta = newLength - this.length;
|
| if (delta <= 0) return this;
|
| - StringBuffer buffer = new StringBuffer();
|
| - buffer.write(this);
|
| + StringBuffer buffer = new StringBuffer(this);
|
| for (int i = 0; i < delta; i++) {
|
| buffer.write(padding);
|
| }
|
| @@ -674,39 +663,14 @@ class _OneByteString extends _StringBase implements String {
|
| return super.contains(pattern, start);
|
| }
|
|
|
| - String repeat(int times, [String separator = ""]) {
|
| - if (times == 0) return "";
|
| + String operator*(int times) {
|
| + if (times <= 0) return "";
|
| if (times == 1) return this;
|
| - if (times < 0) throw new RangeError.value(times);
|
| - if (separator.isEmpty) {
|
| - int length = this.length;
|
| - if (this.isEmpty) return this; // Don't clone empty string.
|
| - _OneByteString result = _OneByteString._allocate(length * times);
|
| - int index = 0;
|
| - for (int i = 0; i < times; i ++) {
|
| - for (int j = 0; j < length; j++) {
|
| - result._setAt(index++, this.codeUnitAt(j));
|
| - }
|
| - }
|
| - return result;
|
| - }
|
| - int sepCid = separator._cid;
|
| - if (sepCid != _OneByteString._classId &&
|
| - sepCid != _ExternalOneByteString._classId) {
|
| - return super.repeat(times, separator);
|
| - }
|
| int length = this.length;
|
| - int sepLength = separator.length;
|
| - _OneByteString result =
|
| - _OneByteString._allocate(length * times + sepLength * (times - 1));
|
| + if (this.isEmpty) return this; // Don't clone empty string.
|
| + _OneByteString result = _OneByteString._allocate(length * times);
|
| int index = 0;
|
| - for (int j = 0; j < length; j++) {
|
| - result._setAt(index++, this.codeUnitAt(j));
|
| - }
|
| - for (int i = 1; i < times; i ++) {
|
| - for (int j = 0; j < sepLength; j++) {
|
| - result._setAt(index++, separator.codeUnitAt(j));
|
| - }
|
| + for (int i = 0; i < times; i ++) {
|
| for (int j = 0; j < length; j++) {
|
| result._setAt(index++, this.codeUnitAt(j));
|
| }
|
| @@ -714,8 +678,7 @@ class _OneByteString extends _StringBase implements String {
|
| return result;
|
| }
|
|
|
| - String padLeft(int newLength, String padding) {
|
| - if (padding.length != 1) throw new ArgumentError(padding);
|
| + String padLeft(int newLength, [String padding = ' ']) {
|
| int padCid = padding._cid;
|
| if (padCid != _OneByteString._classId &&
|
| padCid != _ExternalOneByteString._classId) {
|
| @@ -724,11 +687,21 @@ class _OneByteString extends _StringBase implements String {
|
| int length = this.length;
|
| int delta = newLength - length;
|
| if (delta <= 0) return this;
|
| - _OneByteString result = _OneByteString._allocate(newLength);
|
| + int padLength = padding.length;
|
| + int resultLength = padLength * delta + length;
|
| + _OneByteString result = _OneByteString._allocate(resultLength);
|
| int index = 0;
|
| - int padChar = padding.codeUnitAt(0);
|
| - for (int i = 0; i < delta; i++) {
|
| - result._setAt(index++, padChar);
|
| + if (padLength == 1) {
|
| + int padChar = padding.codeUnitAt(0);
|
| + for (int i = 0; i < delta; i++) {
|
| + result._setAt(index++, padChar);
|
| + }
|
| + } else {
|
| + for (int i = 0; i < delta; i++) {
|
| + for (int j = 0; j < padLength; j++) {
|
| + result._setAt(index++, padding.codeUnitAt(j));
|
| + }
|
| + }
|
| }
|
| for (int i = 0; i < length; i++) {
|
| result._setAt(index++, this.codeUnitAt(i));
|
| @@ -736,8 +709,7 @@ class _OneByteString extends _StringBase implements String {
|
| return result;
|
| }
|
|
|
| - String padRight(int newLength, String padding, { int size }) {
|
| - if (padding.length != 1) throw new ArgumentError(padding);
|
| + String padRight(int newLength, [String padding = ' ']) {
|
| int padCid = padding._cid;
|
| if (padCid != _OneByteString._classId &&
|
| padCid != _ExternalOneByteString._classId) {
|
| @@ -746,14 +718,24 @@ class _OneByteString extends _StringBase implements String {
|
| int length = this.length;
|
| int delta = newLength - length;
|
| if (delta <= 0) return this;
|
| - _OneByteString result = _OneByteString._allocate(newLength);
|
| + int padLength = padding.length;
|
| + int resultLength = length + padLength * delta;
|
| + _OneByteString result = _OneByteString._allocate(resultLength);
|
| int index = 0;
|
| for (int i = 0; i < length; i++) {
|
| result._setAt(index++, this.codeUnitAt(i));
|
| }
|
| - int padChar = padding.codeUnitAt(0);
|
| - for (int i = 0; i < delta; i++) {
|
| - result._setAt(index++, padChar);
|
| + if (padLength == 1) {
|
| + int padChar = padding.codeUnitAt(0);
|
| + for (int i = 0; i < delta; i++) {
|
| + result._setAt(index++, padChar);
|
| + }
|
| + } else {
|
| + for (int i = 0; i < delta; i++) {
|
| + for (int j = 0; j < padLength; j++) {
|
| + result._setAt(index++, padding.codeUnitAt(j));
|
| + }
|
| + }
|
| }
|
| return result;
|
| }
|
|
|