blob: 7f85405ab34dd437caf719d6a1e298005909bb60 [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';
import 'package:path/path.dart' as path;
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;
}
String normalizePath(String rootPath, String relativePath) {
return path.normalize(path.join(rootPath, relativePath));
}