int rootLength()

in lib/src/style/windows.dart [47:71]


  int rootLength(String path, {bool withDrive = false}) {
    if (path.isEmpty) return 0;
    if (path.codeUnitAt(0) == chars.slash) return 1;
    if (path.codeUnitAt(0) == chars.backslash) {
      if (path.length < 2 || path.codeUnitAt(1) != chars.backslash) return 1;
      // The path is a network share. Search for up to two '\'s, as they are
      // the server and share - and part of the root part.
      var index = path.indexOf('\\', 2);
      if (index > 0) {
        index = path.indexOf('\\', index + 1);
        if (index > 0) return index;
      }
      return path.length;
    }
    // If the path is of the form 'C:/' or 'C:\', with C being any letter, it's
    // a root part.
    if (path.length < 3) return 0;
    // Check for the letter.
    if (!isAlphabetic(path.codeUnitAt(0))) return 0;
    // Check for the ':'.
    if (path.codeUnitAt(1) != chars.colon) return 0;
    // Check for either '/' or '\'.
    if (!isSeparator(path.codeUnitAt(2))) return 0;
    return 3;
  }