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

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

Issue 1431673003: Compute covering offsets/lengths. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/correction/util.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 23 matching lines...) Expand all
34 } 34 }
35 if (a == null) { 35 if (a == null) {
36 return 1; 36 return 1;
37 } 37 }
38 if (b == null) { 38 if (b == null) {
39 return -1; 39 return -1;
40 } 40 }
41 return a.compareTo(b); 41 return a.compareTo(b);
42 } 42 }
43 43
44 int countLeadingWhitespaces(String str) {
45 int i = 0;
46 for (; i < str.length; i++) {
47 int c = str.codeUnitAt(i);
48 if (!isWhitespace(c)) {
49 break;
50 }
51 }
52 return i;
53 }
54
44 /** 55 /**
45 * Counts how many times [sub] appears in [str]. 56 * Counts how many times [sub] appears in [str].
46 */ 57 */
47 int countMatches(String str, String sub) { 58 int countMatches(String str, String sub) {
48 if (isEmpty(str) || isEmpty(sub)) { 59 if (isEmpty(str) || isEmpty(sub)) {
49 return 0; 60 return 0;
50 } 61 }
51 int count = 0; 62 int count = 0;
52 int idx = 0; 63 int idx = 0;
53 while ((idx = str.indexOf(sub, idx)) != -1) { 64 while ((idx = str.indexOf(sub, idx)) != -1) {
54 count++; 65 count++;
55 idx += sub.length; 66 idx += sub.length;
56 } 67 }
57 return count; 68 return count;
58 } 69 }
59 70
71 int countTrailingWhitespaces(String str) {
72 int i = 0;
73 for (; i < str.length; i++) {
74 int c = str.codeUnitAt(str.length - 1 - i);
75 if (!isWhitespace(c)) {
76 break;
77 }
78 }
79 return i;
80 }
81
60 /** 82 /**
61 * Returns the number of characters common to the end of [a] and the start 83 * Returns the number of characters common to the end of [a] and the start
62 * of [b]. 84 * of [b].
63 */ 85 */
64 int findCommonOverlap(String a, String b) { 86 int findCommonOverlap(String a, String b) {
65 int a_length = a.length; 87 int a_length = a.length;
66 int b_length = b.length; 88 int b_length = b.length;
67 // all empty 89 // all empty
68 if (a_length == 0 || b_length == 0) { 90 if (a_length == 0 || b_length == 0) {
69 return 0; 91 return 0;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 } 268 }
247 if (isEmpty(separator)) { 269 if (isEmpty(separator)) {
248 return ''; 270 return '';
249 } 271 }
250 int pos = str.lastIndexOf(separator); 272 int pos = str.lastIndexOf(separator);
251 if (pos == -1) { 273 if (pos == -1) {
252 return str; 274 return str;
253 } 275 }
254 return str.substring(pos + separator.length); 276 return str.substring(pos + separator.length);
255 } 277 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/correction/util.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698