| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library diff; | |
| 6 | |
| 7 import 'dart:math'; | |
| 8 | |
| 9 | |
| 10 /** | |
| 11 * Return the number of characters common to the start of [a] and [b]. | |
| 12 */ | |
| 13 int findCommonPrefix(String a, String b) { | |
| 14 int n = min(a.length, b.length); | |
| 15 for (int i = 0; i < n; i++) { | |
| 16 if (a.codeUnitAt(i) != b.codeUnitAt(i)) { | |
| 17 return i; | |
| 18 } | |
| 19 } | |
| 20 return n; | |
| 21 } | |
| 22 | |
| 23 | |
| 24 /** | |
| 25 * Return the number of characters common to the end of [a] and [b]. | |
| 26 */ | |
| 27 int findCommonSuffix(String a, String b) { | |
| 28 int a_length = a.length; | |
| 29 int b_length = b.length; | |
| 30 int n = min(a_length, b_length); | |
| 31 for (int i = 1; i <= n; i++) { | |
| 32 if (a.codeUnitAt(a_length - i) != b.codeUnitAt(b_length - i)) { | |
| 33 return i - 1; | |
| 34 } | |
| 35 } | |
| 36 return n; | |
| 37 } | |
| OLD | NEW |