OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 String dotsToCamelCase(String input, [bool capitalize = false]) => |
| 6 _toCamelCase(input, ".", capitalize); |
| 7 String underscoresToCamelCase(String input, [bool capitalize = false]) => |
| 8 _toCamelCase(input, "_", capitalize); |
| 9 String _toCamelCase(String input, String separator, bool capitalize) { |
| 10 bool capNextLetter = capitalize; |
| 11 int separatorCode = separator.charCodes()[0]; |
| 12 List<int> sb = []; |
| 13 for (int i = 0; i < input.length; i++) { |
| 14 int char = input.charCodeAt(i); |
| 15 if (_StringUtils.isUppercaseLetter(char)) { |
| 16 if (capNextLetter) { |
| 17 sb.add(char); |
| 18 } else { |
| 19 sb.add(_StringUtils.toLowercase(char)); |
| 20 } |
| 21 capNextLetter = false; |
| 22 } else if (_StringUtils.isLowercaseLetter(char)) { |
| 23 if (capNextLetter) { |
| 24 sb.add(_StringUtils.toUppercase(char)); |
| 25 } else { |
| 26 sb.add(char); |
| 27 } |
| 28 capNextLetter = false; |
| 29 } else { |
| 30 if (char != separatorCode) { |
| 31 sb.add(char); |
| 32 } |
| 33 capNextLetter = true; |
| 34 } |
| 35 } |
| 36 |
| 37 return new String.fromCharCodes(sb); |
| 38 } |
| 39 |
| 40 String titlecase(String input) { |
| 41 if (input.length > 0) { |
| 42 int initial = input.charCodeAt(0); |
| 43 if (_StringUtils.isLowercaseLetter(initial)) { |
| 44 return "${new String.fromCharCodes([_StringUtils.toUppercase(initial)])}" |
| 45 "${input.substring(1)}"; |
| 46 } |
| 47 } |
| 48 return input; |
| 49 } |
| 50 |
| 51 class FilenameUtils { |
| 52 static String basename(String filename) { |
| 53 int b = filename.lastIndexOf("/", filename.length - 1); |
| 54 int e = filename.lastIndexOf(".", filename.length - 1); |
| 55 if (e <= 0) e = filename.length - 1; |
| 56 return filename.substring(b + 1, e); |
| 57 } |
| 58 } |
| 59 |
| 60 class _StringUtils { |
| 61 static final int char_A = 65; // "A".charCodeAt(0); |
| 62 static final int char_Z = 90; // "Z".charCodeAt(0); |
| 63 |
| 64 static final int char_a = 97; // "a".charCodeAt(0); |
| 65 static final int char_z = 122; // "z".charCodeAt(0); |
| 66 |
| 67 static final int char_0 = 48; // "0".charCodeAt(0); |
| 68 static final int char_9 = 58; // "9".charCodeAt(0); |
| 69 |
| 70 static bool isLowercaseLetter(int char) => |
| 71 (char_a <= char) && (char <= char_z); |
| 72 static bool isNumeric(int char) => (char_0 <= char) && (char <= char_9); |
| 73 static bool isUppercaseLetter(int char) => |
| 74 (char_A <= char) && (char <= char_Z); |
| 75 static int toLowercase(int char) => char + (char_a - char_A); |
| 76 static int toUppercase(int char) => char - (char_a - char_A); |
| 77 } |
| 78 |
| 79 class _Bitmask { |
| 80 _Bitmask(); |
| 81 String operator[](int index) => "0x${(1 << (index - 1)).toRadixString(16)}"; |
| 82 } |
| 83 |
| 84 class _BitmaskUtils { |
| 85 static _Bitmask _bitmask; |
| 86 |
| 87 static _Bitmask get bit_masks() { |
| 88 if (_bitmask == null) { |
| 89 _bitmask = new _Bitmask(); |
| 90 } |
| 91 return _bitmask; |
| 92 } |
| 93 } |
OLD | NEW |