Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 library diff; | |
|
Brian Wilkerson
2014/10/02 13:48:57
missing copyright
| |
| 2 | |
| 3 import 'dart:math'; | |
| 4 | |
| 5 | |
| 6 /** | |
| 7 * Return the number of characters common to the start of [a] and [b]. | |
| 8 */ | |
| 9 int findCommonPrefix(String a, String b) { | |
|
Brian Wilkerson
2014/10/02 13:48:57
These seem like they belong in our StringUtilities
| |
| 10 int n = min(a.length, b.length); | |
| 11 for (int i = 0; i < n; i++) { | |
| 12 if (a.codeUnitAt(i) != b.codeUnitAt(i)) { | |
| 13 return i; | |
| 14 } | |
| 15 } | |
| 16 return n; | |
| 17 } | |
| 18 | |
| 19 | |
| 20 /** | |
| 21 * Return the number of characters common to the end of [a] and [b]. | |
| 22 */ | |
| 23 int findCommonSuffix(String a, String b) { | |
| 24 int a_length = a.length; | |
| 25 int b_length = b.length; | |
| 26 int n = min(a_length, b_length); | |
| 27 for (int i = 1; i <= n; i++) { | |
| 28 if (a.codeUnitAt(a_length - i) != b.codeUnitAt(b_length - i)) { | |
| 29 return i - 1; | |
| 30 } | |
| 31 } | |
| 32 return n; | |
| 33 } | |
| OLD | NEW |