blob: 8c53afe69f62fe15c5003cac126df1ffd32c866b [file] [log] [blame]
// Copyright 2016 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
import 'dart:io' show Platform;
import 'dart:math';
int minLength(List<String> elements) {
if (elements == null || elements.isEmpty) return -1;
return elements.map((String e) => e.length).reduce(min);
}
bool isSystemSeparator(String letter) {
return letter == Platform.pathSeparator;
}
int beginOfDiff(List<String> elements) {
if (elements.length == 1)
return elements[0].lastIndexOf(Platform.pathSeparator) + 1;
int minL = minLength(elements);
int lastSlash = 0;
for (int i = 0; i < minL; i++) {
String letter = elements[0][i];
if (isSystemSeparator(letter)) {
lastSlash = i;
}
for (String element in elements) {
if (letter != element[i]) {
return lastSlash + 1;
}
}
}
return minL;
}