Chromium Code Reviews| Index: pkg/analysis_server/lib/src/services/correction/diff.dart |
| diff --git a/pkg/analysis_server/lib/src/services/correction/diff.dart b/pkg/analysis_server/lib/src/services/correction/diff.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dcce26eff11d67232ddef99f5060c090a2815aee |
| --- /dev/null |
| +++ b/pkg/analysis_server/lib/src/services/correction/diff.dart |
| @@ -0,0 +1,33 @@ |
| +library diff; |
|
Brian Wilkerson
2014/10/02 13:48:57
missing copyright
|
| + |
| +import 'dart:math'; |
| + |
| + |
| +/** |
| + * Return the number of characters common to the start of [a] and [b]. |
| + */ |
| +int findCommonPrefix(String a, String b) { |
|
Brian Wilkerson
2014/10/02 13:48:57
These seem like they belong in our StringUtilities
|
| + int n = min(a.length, b.length); |
| + for (int i = 0; i < n; i++) { |
| + if (a.codeUnitAt(i) != b.codeUnitAt(i)) { |
| + return i; |
| + } |
| + } |
| + return n; |
| +} |
| + |
| + |
| +/** |
| + * Return the number of characters common to the end of [a] and [b]. |
| + */ |
| +int findCommonSuffix(String a, String b) { |
| + int a_length = a.length; |
| + int b_length = b.length; |
| + int n = min(a_length, b_length); |
| + for (int i = 1; i <= n; i++) { |
| + if (a.codeUnitAt(a_length - i) != b.codeUnitAt(b_length - i)) { |
| + return i - 1; |
| + } |
| + } |
| + return n; |
| +} |