| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 patch class String { | 5 patch class String { |
| 6 /* patch */ factory String.fromCharCodes(Iterable<int> charCodes) { | 6 /* patch */ factory String.fromCharCodes(Iterable<int> charCodes) { |
| 7 return _StringBase.createFromCharCodes(charCodes); | 7 return _StringBase.createFromCharCodes(charCodes); |
| 8 } | 8 } |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 } | 460 } |
| 461 | 461 |
| 462 List<int> get codeUnits => new _CodeUnits(this); | 462 List<int> get codeUnits => new _CodeUnits(this); |
| 463 | 463 |
| 464 Runes get runes => new Runes(this); | 464 Runes get runes => new Runes(this); |
| 465 | 465 |
| 466 String toUpperCase() native "String_toUpperCase"; | 466 String toUpperCase() native "String_toUpperCase"; |
| 467 | 467 |
| 468 String toLowerCase() native "String_toLowerCase"; | 468 String toLowerCase() native "String_toLowerCase"; |
| 469 | 469 |
| 470 // Implementations of Strings methods follow below. | |
| 471 static String join(Iterable<String> strings, String separator) { | |
| 472 bool first = true; | |
| 473 List<String> stringsList = <String>[]; | |
| 474 for (String string in strings) { | |
| 475 if (first) { | |
| 476 first = false; | |
| 477 } else { | |
| 478 stringsList.add(separator); | |
| 479 } | |
| 480 | |
| 481 if (string is! String) { | |
| 482 throw new ArgumentError(Error.safeToString(string)); | |
| 483 } | |
| 484 stringsList.add(string); | |
| 485 } | |
| 486 return concatAll(stringsList); | |
| 487 } | |
| 488 | |
| 489 static String concatAll(Iterable<String> strings) { | |
| 490 _ObjectArray stringsArray; | |
| 491 final len = strings.length; | |
| 492 bool isOneByteString = true; | |
| 493 int totalLength = 0; | |
| 494 if (strings._cid == _ObjectArray._clCId) { | |
| 495 stringsArray = strings; | |
| 496 for (int i = 0; i < len; i++) { | |
| 497 var string = strings[i]; | |
| 498 if (string._cid == _OneByteString._classId) { | |
| 499 totalLength += string.length; | |
| 500 } else { | |
| 501 isOneByteString = false; | |
| 502 if (string is! String) throw new ArgumentError(string); | |
| 503 } | |
| 504 } | |
| 505 } else { | |
| 506 // Copy into an _ObjectArray. | |
| 507 stringsArray = new _ObjectArray(len); | |
| 508 int i = 0; | |
| 509 for (int i = 0; i < len; i++) { | |
| 510 var string = strings[i]; | |
| 511 if (string._cid == _OneByteString.clCid) { | |
| 512 totalLength += s.length; | |
| 513 } else { | |
| 514 isOneByteString = false; | |
| 515 if (string is! String) throw new ArgumentError(string); | |
| 516 } | |
| 517 stringsArray[i++] = string; | |
| 518 } | |
| 519 } | |
| 520 if (isOneByteString) { | |
| 521 return _OneByteString._concatAll(stringsArray, totalLength); | |
| 522 } | |
| 523 return _concatAllNative(stringsArray); | |
| 524 } | |
| 525 | |
| 526 static String _concatAll(_ObjectArray<String> strings) { | |
| 527 int totalLength = 0; | |
| 528 final stringsLength = strings.length; | |
| 529 for (int i = 0; i < stringsLength; i++) { | |
| 530 var e = strings[i]; | |
| 531 if (e._cid != _OneByteString._classId) { | |
| 532 return _concatAllNative(strings); | |
| 533 } | |
| 534 totalLength += e.length; | |
| 535 } | |
| 536 return _OneByteString._concatAll(strings, totalLength); | |
| 537 } | |
| 538 | |
| 539 // Call this method if not all list elements are OneByteString-s. | 470 // Call this method if not all list elements are OneByteString-s. |
| 540 static String _concatAllNative(_ObjectArray<String> strings) | 471 static String _concatAllNative(_ObjectArray<String> strings) |
| 541 native "Strings_concatAll"; | 472 native "Strings_concatAll"; |
| 542 } | 473 } |
| 543 | 474 |
| 544 | 475 |
| 545 class _OneByteString extends _StringBase implements String { | 476 class _OneByteString extends _StringBase implements String { |
| 546 static final int _classId = "A"._cid; | 477 static final int _classId = "A"._cid; |
| 547 | 478 |
| 548 factory _OneByteString._uninstantiable() { | 479 factory _OneByteString._uninstantiable() { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 class _CodeUnits extends Object with ListMixin<int>, | 601 class _CodeUnits extends Object with ListMixin<int>, |
| 671 UnmodifiableListMixin<int> { | 602 UnmodifiableListMixin<int> { |
| 672 /** The string that this is the code units of. */ | 603 /** The string that this is the code units of. */ |
| 673 String _string; | 604 String _string; |
| 674 | 605 |
| 675 _CodeUnits(this._string); | 606 _CodeUnits(this._string); |
| 676 | 607 |
| 677 int get length => _string.length; | 608 int get length => _string.length; |
| 678 int operator[](int i) => _string.codeUnitAt(i); | 609 int operator[](int i) => _string.codeUnitAt(i); |
| 679 } | 610 } |
| OLD | NEW |