src/windows/classes/sun/nio/fs/WindowsPathParser.java

Print this page




  57 
  58         /**
  59          * The root component
  60          */
  61         String root() {
  62             return root;
  63         }
  64 
  65         /**
  66          * The normalized path (includes root)
  67          */
  68         String path() {
  69             return path;
  70         }
  71     }
  72 
  73     /**
  74      * Parses the given input as a Windows path
  75      */
  76     static Result parse(String input) {
  77         if (input == null || input.length() == 0)
  78             throw new InvalidPathException(input, "Empty or null path");
  79         return parse(input, true);
  80     }
  81 
  82     /**
  83      * Parses the given input as a Windows path where it is known that the
  84      * path is already normalized.
  85      */
  86     static Result parseNormalizedPath(String input) {
  87         return parse(input, false);
  88     }
  89 
  90     /**
  91      * Parses the given input as a Windows path.
  92      *
  93      * @param   requireToNormalize
  94      *          Indicates if the path requires to be normalized
  95      */
  96     private static Result parse(String input, boolean requireToNormalize) {
  97         String root = "";
  98         WindowsPathType type = null;


 118                 next = nextSlash(input, off, len);
 119                 if (off == next)
 120                     throw new InvalidPathException(input, "UNC path is missing sharename");
 121                 root = "\\\\" + host + "\\" + input.substring(off, next) + "\\";
 122                 off = next;
 123             } else {
 124                 if (isLetter(c0) && c1 == ':') {
 125                     root = input.substring(0, 2);
 126                     if (len > 2 && isSlash(input.charAt(2))) {
 127                         off = 3;
 128                         root += "\\";
 129                         type = WindowsPathType.ABSOLUTE;
 130                     } else {
 131                         off = 2;
 132                         type = WindowsPathType.DRIVE_RELATIVE;
 133                     }
 134                 }
 135             }
 136         }
 137         if (off == 0) {
 138             if (isSlash(input.charAt(0))) {
 139                 type = WindowsPathType.DIRECTORY_RELATIVE;
 140                 root = "\\";
 141             } else {
 142                 type = WindowsPathType.RELATIVE;
 143             }
 144         }
 145 
 146         if (requireToNormalize) {
 147             StringBuilder sb = new StringBuilder(input.length());
 148             sb.append(root);
 149             return new Result(type, root, normalize(sb, input, off));
 150         } else {
 151             return new Result(type, root, input);
 152         }
 153     }
 154 
 155     /**
 156      * Remove redundant slashes from the rest of the path, forcing all slashes
 157      * into the preferred slash.
 158     */




  57 
  58         /**
  59          * The root component
  60          */
  61         String root() {
  62             return root;
  63         }
  64 
  65         /**
  66          * The normalized path (includes root)
  67          */
  68         String path() {
  69             return path;
  70         }
  71     }
  72 
  73     /**
  74      * Parses the given input as a Windows path
  75      */
  76     static Result parse(String input) {


  77         return parse(input, true);
  78     }
  79 
  80     /**
  81      * Parses the given input as a Windows path where it is known that the
  82      * path is already normalized.
  83      */
  84     static Result parseNormalizedPath(String input) {
  85         return parse(input, false);
  86     }
  87 
  88     /**
  89      * Parses the given input as a Windows path.
  90      *
  91      * @param   requireToNormalize
  92      *          Indicates if the path requires to be normalized
  93      */
  94     private static Result parse(String input, boolean requireToNormalize) {
  95         String root = "";
  96         WindowsPathType type = null;


 116                 next = nextSlash(input, off, len);
 117                 if (off == next)
 118                     throw new InvalidPathException(input, "UNC path is missing sharename");
 119                 root = "\\\\" + host + "\\" + input.substring(off, next) + "\\";
 120                 off = next;
 121             } else {
 122                 if (isLetter(c0) && c1 == ':') {
 123                     root = input.substring(0, 2);
 124                     if (len > 2 && isSlash(input.charAt(2))) {
 125                         off = 3;
 126                         root += "\\";
 127                         type = WindowsPathType.ABSOLUTE;
 128                     } else {
 129                         off = 2;
 130                         type = WindowsPathType.DRIVE_RELATIVE;
 131                     }
 132                 }
 133             }
 134         }
 135         if (off == 0) {
 136             if (len > 0 && isSlash(input.charAt(0))) {
 137                 type = WindowsPathType.DIRECTORY_RELATIVE;
 138                 root = "\\";
 139             } else {
 140                 type = WindowsPathType.RELATIVE;
 141             }
 142         }
 143 
 144         if (requireToNormalize) {
 145             StringBuilder sb = new StringBuilder(input.length());
 146             sb.append(root);
 147             return new Result(type, root, normalize(sb, input, off));
 148         } else {
 149             return new Result(type, root, input);
 150         }
 151     }
 152 
 153     /**
 154      * Remove redundant slashes from the rest of the path, forcing all slashes
 155      * into the preferred slash.
 156     */