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 // Generic utility functions. | 5 // Generic utility functions. |
6 | 6 |
7 /** Turns [name] into something that's safe to use as a file name. */ | 7 /** Turns [name] into something that's safe to use as a file name. */ |
8 String sanitize(String name) => name.replaceAll(':', '_').replaceAll('/', '_'); | 8 String sanitize(String name) => name.replaceAll(':', '_').replaceAll('/', '_'); |
9 | 9 |
10 /** Returns the number of times [search] occurs in [text]. */ | 10 /** Returns the number of times [search] occurs in [text]. */ |
(...skipping 20 matching lines...) Expand all Loading... |
31 buffer.add(text); | 31 buffer.add(text); |
32 if ((i < count - 1) && (separator !== null)) buffer.add(separator); | 32 if ((i < count - 1) && (separator !== null)) buffer.add(separator); |
33 } | 33 } |
34 | 34 |
35 return buffer.toString(); | 35 return buffer.toString(); |
36 } | 36 } |
37 | 37 |
38 /** Removes up to [indentation] leading whitespace characters from [text]. */ | 38 /** Removes up to [indentation] leading whitespace characters from [text]. */ |
39 String unindent(String text, int indentation) { | 39 String unindent(String text, int indentation) { |
40 var start; | 40 var start; |
41 for (start = 0; start < Math.min(indentation, text.length); start++) { | 41 for (start = 0; start < min(indentation, text.length); start++) { |
42 // Stop if we hit a non-whitespace character. | 42 // Stop if we hit a non-whitespace character. |
43 if (text[start] != ' ') break; | 43 if (text[start] != ' ') break; |
44 } | 44 } |
45 | 45 |
46 return text.substring(start); | 46 return text.substring(start); |
47 } | 47 } |
48 | 48 |
49 /** Sorts the map by the key, doing a case-insensitive comparison. */ | 49 /** Sorts the map by the key, doing a case-insensitive comparison. */ |
50 List<Mirror> orderByName(Collection<Mirror> list) { | 50 List<Mirror> orderByName(Collection<Mirror> list) { |
51 final elements = new List<Mirror>.from(list); | 51 final elements = new List<Mirror>.from(list); |
(...skipping 16 matching lines...) Expand all Loading... |
68 if (items.length == 2) return "${items[0]} $conjunction ${items[1]}"; | 68 if (items.length == 2) return "${items[0]} $conjunction ${items[1]}"; |
69 return '${Strings.join(items.getRange(0, items.length - 1), ', ')}' | 69 return '${Strings.join(items.getRange(0, items.length - 1), ', ')}' |
70 ', $conjunction ${items[items.length - 1]}'; | 70 ', $conjunction ${items[items.length - 1]}'; |
71 } | 71 } |
72 | 72 |
73 void writeString(File file, String text) { | 73 void writeString(File file, String text) { |
74 var randomAccessFile = file.openSync(FileMode.WRITE); | 74 var randomAccessFile = file.openSync(FileMode.WRITE); |
75 randomAccessFile.writeStringSync(text); | 75 randomAccessFile.writeStringSync(text); |
76 randomAccessFile.closeSync(); | 76 randomAccessFile.closeSync(); |
77 } | 77 } |
OLD | NEW |