| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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 library services.src.correction.strings; | 5 library services.src.correction.strings; |
| 6 | 6 |
| 7 import 'dart:math'; | 7 import 'dart:math'; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * "$" | 10 * "$" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 int n = min(a_length, b_length); | 112 int n = min(a_length, b_length); |
| 113 for (int i = 1; i <= n; i++) { | 113 for (int i = 1; i <= n; i++) { |
| 114 if (a.codeUnitAt(a_length - i) != b.codeUnitAt(b_length - i)) { | 114 if (a.codeUnitAt(a_length - i) != b.codeUnitAt(b_length - i)) { |
| 115 return i - 1; | 115 return i - 1; |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 return n; | 118 return n; |
| 119 } | 119 } |
| 120 | 120 |
| 121 /** | 121 /** |
| 122 * Returns a list of words for the given camel case string. |
| 123 * |
| 124 * 'getCamelWords' => ['get', 'Camel', 'Words'] |
| 125 * 'getHTMLText' => ['get', 'HTML', 'Text'] |
| 126 */ |
| 127 List<String> getCamelWords(String str) { |
| 128 if (str == null || str.isEmpty) { |
| 129 return <String>[]; |
| 130 } |
| 131 List<String> parts = <String>[]; |
| 132 bool wasLowerCase = false; |
| 133 bool wasUpperCase = false; |
| 134 int wordStart = 0; |
| 135 for (int i = 0; i < str.length; i++) { |
| 136 int c = str.codeUnitAt(i); |
| 137 var newLowerCase = isLowerCase(c); |
| 138 var newUpperCase = isUpperCase(c); |
| 139 // myWord |
| 140 // | ^ |
| 141 if (wasLowerCase && newUpperCase) { |
| 142 parts.add(str.substring(wordStart, i)); |
| 143 wordStart = i; |
| 144 } |
| 145 // myHTMLText |
| 146 // | ^ |
| 147 if (wasUpperCase && |
| 148 newUpperCase && |
| 149 i + 1 < str.length && |
| 150 isLowerCase(str.codeUnitAt(i + 1))) { |
| 151 parts.add(str.substring(wordStart, i)); |
| 152 wordStart = i; |
| 153 } |
| 154 wasLowerCase = newLowerCase; |
| 155 wasUpperCase = newUpperCase; |
| 156 } |
| 157 parts.add(str.substring(wordStart)); |
| 158 return parts; |
| 159 } |
| 160 |
| 161 /** |
| 122 * Checks if [str] is `null`, empty or is whitespace. | 162 * Checks if [str] is `null`, empty or is whitespace. |
| 123 */ | 163 */ |
| 124 bool isBlank(String str) { | 164 bool isBlank(String str) { |
| 125 if (str == null) { | 165 if (str == null) { |
| 126 return true; | 166 return true; |
| 127 } | 167 } |
| 128 if (str.isEmpty) { | 168 if (str.isEmpty) { |
| 129 return true; | 169 return true; |
| 130 } | 170 } |
| 131 return str.codeUnits.every(isSpace); | 171 return str.codeUnits.every(isSpace); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 246 } |
| 207 if (isEmpty(separator)) { | 247 if (isEmpty(separator)) { |
| 208 return ''; | 248 return ''; |
| 209 } | 249 } |
| 210 int pos = str.lastIndexOf(separator); | 250 int pos = str.lastIndexOf(separator); |
| 211 if (pos == -1) { | 251 if (pos == -1) { |
| 212 return str; | 252 return str; |
| 213 } | 253 } |
| 214 return str.substring(pos + separator.length); | 254 return str.substring(pos + separator.length); |
| 215 } | 255 } |
| OLD | NEW |