Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(549)

Unified Diff: pkg/analysis_server/lib/src/services/correction/strings.dart

Issue 1394933003: Move getCamelWords() to the strings.dart file. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/services/correction/strings.dart
diff --git a/pkg/analysis_server/lib/src/services/correction/strings.dart b/pkg/analysis_server/lib/src/services/correction/strings.dart
index 3c44fb626d5875c576330e55f5a55d44537e355f..c2ea6cbcb49b5395005f10e9132241192df26b74 100644
--- a/pkg/analysis_server/lib/src/services/correction/strings.dart
+++ b/pkg/analysis_server/lib/src/services/correction/strings.dart
@@ -119,6 +119,46 @@ int findCommonSuffix(String a, String b) {
}
/**
+ * Returns a list of words for the given camel case string.
+ *
+ * 'getCamelWords' => ['get', 'Camel', 'Words']
+ * 'getHTMLText' => ['get', 'HTML', 'Text']
+ */
+List<String> getCamelWords(String str) {
+ if (str == null || str.isEmpty) {
+ return <String>[];
+ }
+ List<String> parts = <String>[];
+ bool wasLowerCase = false;
+ bool wasUpperCase = false;
+ int wordStart = 0;
+ for (int i = 0; i < str.length; i++) {
+ int c = str.codeUnitAt(i);
+ var newLowerCase = isLowerCase(c);
+ var newUpperCase = isUpperCase(c);
+ // myWord
+ // | ^
+ if (wasLowerCase && newUpperCase) {
+ parts.add(str.substring(wordStart, i));
+ wordStart = i;
+ }
+ // myHTMLText
+ // | ^
+ if (wasUpperCase &&
+ newUpperCase &&
+ i + 1 < str.length &&
+ isLowerCase(str.codeUnitAt(i + 1))) {
+ parts.add(str.substring(wordStart, i));
+ wordStart = i;
+ }
+ wasLowerCase = newLowerCase;
+ wasUpperCase = newUpperCase;
+ }
+ parts.add(str.substring(wordStart));
+ return parts;
+}
+
+/**
* Checks if [str] is `null`, empty or is whitespace.
*/
bool isBlank(String str) {

Powered by Google App Engine
This is Rietveld 408576698