| 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 /** | 5 /** |
| 6 * Tests for the toString methods on collections and maps. | 6 * Tests for the toString methods on collections and maps. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 library collection_to_string; | 9 library collection_to_string; |
| 10 | 10 |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 // It's an iterable, it may omit some elements. | 234 // It's an iterable, it may omit some elements. |
| 235 int end = stringRep.length; | 235 int end = stringRep.length; |
| 236 if (size > MAX_COUNT) { | 236 if (size > MAX_COUNT) { |
| 237 // Last two elements are also omitted, just find the first three or | 237 // Last two elements are also omitted, just find the first three or |
| 238 // first 60 characters. | 238 // first 60 characters. |
| 239 for (int i = MIN_COUNT; i < size; i++) { | 239 for (int i = MIN_COUNT; i < size; i++) { |
| 240 int startIndex = indices[i]; | 240 int startIndex = indices[i]; |
| 241 if (startIndex - start > MAX_LENGTH - 6) { // Limit - ", ...)".length. | 241 if (startIndex - start > MAX_LENGTH - 6) { // Limit - ", ...)".length. |
| 242 String prefix = stringRep.toString().substring(0, startIndex); | 242 String prefix = stringRep.toString().substring(0, startIndex); |
| 243 stringRep.clear(); | 243 stringRep.clear(); |
| 244 stringRep.add(prefix); | 244 stringRep.write(prefix); |
| 245 stringRep.add(", ..."); | 245 stringRep.write(", ..."); |
| 246 } | 246 } |
| 247 } | 247 } |
| 248 } else if (stringRep.length - start > MAX_LENGTH - 1) { // 80 - ")".length. | 248 } else if (stringRep.length - start > MAX_LENGTH - 1) { // 80 - ")".length. |
| 249 // Last two elements are always included. Middle ones may be omitted. | 249 // Last two elements are always included. Middle ones may be omitted. |
| 250 int lastTwoLength = end - indices[indices.length - 2]; | 250 int lastTwoLength = end - indices[indices.length - 2]; |
| 251 // Try to find first element to omit. | 251 // Try to find first element to omit. |
| 252 for (int i = 3; i <= size - 3; i++) { | 252 for (int i = 3; i <= size - 3; i++) { |
| 253 int elementEnd = indices[i + 1]; | 253 int elementEnd = indices[i + 1]; |
| 254 int lengthAfter = elementEnd - start; | 254 int lengthAfter = elementEnd - start; |
| 255 int ellipsisSize = 5; // ", ...".length | 255 int ellipsisSize = 5; // ", ...".length |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 return rand.nextBool(); | 356 return rand.nextBool(); |
| 357 } | 357 } |
| 358 | 358 |
| 359 /** Returns the alphabetized characters in a string. */ | 359 /** Returns the alphabetized characters in a string. */ |
| 360 String alphagram(String s) { | 360 String alphagram(String s) { |
| 361 // Calling [toList] to convert unmodifiable list to normal list. | 361 // Calling [toList] to convert unmodifiable list to normal list. |
| 362 List<int> chars = s.codeUnits.toList(); | 362 List<int> chars = s.codeUnits.toList(); |
| 363 chars.sort((int a, int b) => a - b); | 363 chars.sort((int a, int b) => a - b); |
| 364 return new String.fromCharCodes(chars); | 364 return new String.fromCharCodes(chars); |
| 365 } | 365 } |
| OLD | NEW |