| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2014, 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 library services.src.correction.strings; | |
| 6 | |
| 7 | |
| 8 /** | |
| 9 * "$" | |
| 10 */ | |
| 11 const int CHAR_DOLLAR = 0x24; | |
| 12 | |
| 13 /** | |
| 14 * "." | |
| 15 */ | |
| 16 const int CHAR_DOT = 0x2E; | |
| 17 | |
| 18 /** | |
| 19 * "_" | |
| 20 */ | |
| 21 const int CHAR_UNDERSCORE = 0x5F; | |
| 22 | |
| 23 | |
| 24 String capitalize(String str) { | |
| 25 if (isEmpty(str)) { | |
| 26 return str; | |
| 27 } | |
| 28 return str.substring(0, 1).toUpperCase() + str.substring(1); | |
| 29 } | |
| 30 | |
| 31 int compareStrings(String a, String b) { | |
| 32 if (a == b) { | |
| 33 return 0; | |
| 34 } | |
| 35 if (a == null) { | |
| 36 return 1; | |
| 37 } | |
| 38 if (b == null) { | |
| 39 return -1; | |
| 40 } | |
| 41 return a.compareTo(b); | |
| 42 } | |
| 43 | |
| 44 /** | |
| 45 * Checks if [str] is `null`, empty or is whitespace. | |
| 46 */ | |
| 47 bool isBlank(String str) { | |
| 48 if (str == null) { | |
| 49 return true; | |
| 50 } | |
| 51 if (str.isEmpty) { | |
| 52 return true; | |
| 53 } | |
| 54 return str.codeUnits.every(isSpace); | |
| 55 } | |
| 56 | |
| 57 bool isDigit(int c) { | |
| 58 return c >= 0x30 && c <= 0x39; | |
| 59 } | |
| 60 | |
| 61 bool isEmpty(String str) { | |
| 62 return str == null || str.isEmpty; | |
| 63 } | |
| 64 | |
| 65 bool isLetter(int c) { | |
| 66 return (c >= 0x41 && c <= 0x5A) || (c >= 0x61 && c <= 0x7A); | |
| 67 } | |
| 68 | |
| 69 bool isLetterOrDigit(int c) { | |
| 70 return isLetter(c) || isDigit(c); | |
| 71 } | |
| 72 | |
| 73 bool isLowerCase(int c) { | |
| 74 return c >= 0x61 && c <= 0x7A; | |
| 75 } | |
| 76 | |
| 77 bool isSpace(int c) => c == 0x20 || c == 0x09; | |
| 78 | |
| 79 bool isUpperCase(int c) { | |
| 80 return c >= 0x41 && c <= 0x5A; | |
| 81 } | |
| 82 | |
| 83 bool isWhitespace(int c) { | |
| 84 return isSpace(c) || c == 0x0D || c == 0x0A; | |
| 85 } | |
| 86 | |
| 87 String remove(String str, String remove) { | |
| 88 if (isEmpty(str) || isEmpty(remove)) { | |
| 89 return str; | |
| 90 } | |
| 91 return str.replaceAll(remove, ''); | |
| 92 } | |
| 93 | |
| 94 String removeStart(String str, String remove) { | |
| 95 if (isEmpty(str) || isEmpty(remove)) { | |
| 96 return str; | |
| 97 } | |
| 98 if (str.startsWith(remove)) { | |
| 99 return str.substring(remove.length); | |
| 100 } | |
| 101 return str; | |
| 102 } | |
| 103 | |
| 104 String repeat(String s, int n) { | |
| 105 StringBuffer sb = new StringBuffer(); | |
| 106 for (int i = 0; i < n; i++) { | |
| 107 sb.write(s); | |
| 108 } | |
| 109 return sb.toString(); | |
| 110 } | |
| OLD | NEW |