diff options
author | Bryce McKinlay <bryce@albatross.co.nz> | 2001-04-12 09:32:50 +0000 |
---|---|---|
committer | Bryce McKinlay <bryce@gcc.gnu.org> | 2001-04-12 10:32:50 +0100 |
commit | 52c2897732e366fd1d63140b4f10cce41c5f0e0c (patch) | |
tree | 127d25971ad8807e7f3fe74108e3b8b1196b86e0 /libjava/java | |
parent | f847167e3d5c4864f64bd950a6a0d478a6730def (diff) | |
download | gcc-52c2897732e366fd1d63140b4f10cce41c5f0e0c.zip gcc-52c2897732e366fd1d63140b4f10cce41c5f0e0c.tar.gz gcc-52c2897732e366fd1d63140b4f10cce41c5f0e0c.tar.bz2 |
Makefile.am: Make a libtool convenience library.
libffi:
* Makefile.am: Make a libtool convenience library.
* Makefile.in: Rebuilt.
libjava:
* java/io/File.java (normalizePath): New private method.
(File (String)): Use normalizePath().
(File (String, String)): Likewise.
* Makefile.am (libffi_files): Removed.
(libgcj.la): Link libffi as a convenience library instead of
refering to its object files directly.
* Makefile.in: Rebuilt.
From-SVN: r41298
Diffstat (limited to 'libjava/java')
-rw-r--r-- | libjava/java/io/File.java | 61 |
1 files changed, 54 insertions, 7 deletions
diff --git a/libjava/java/io/File.java b/libjava/java/io/File.java index 71da255..cfa7782 100644 --- a/libjava/java/io/File.java +++ b/libjava/java/io/File.java @@ -76,11 +76,56 @@ public class File implements Serializable, Comparable public File (String p) { - if (p == null) - throw new NullPointerException (); - path = p; + path = normalizePath(p); } + // Remove duplicate and redundant separator characters. + private String normalizePath(String p) + { + int dupIndex = p.indexOf(dupSeparator); + int plen = p.length(); + + // Special case: permit Windows UNC path prefix. + if (dupSeparator == "\\" && dupIndex == 0) + dupIndex = p.indexOf(dupSeparator, 1); + + if (dupIndex == -1) + { + // Ignore trailing separator. + if (plen > 1 && p.charAt(plen - 1) == separatorChar) + return p.substring(0, plen - 1); + else + return p; + } + + StringBuffer newpath = new StringBuffer(plen); + int last = 0; + while (dupIndex != -1) + { + newpath.append(p.substring(last, dupIndex)); + // Ignore the duplicate path characters. + while (p.charAt(dupIndex) == separatorChar) + { + dupIndex++; + if (dupIndex == plen) + return newpath.toString(); + } + newpath.append(separatorChar); + last = dupIndex; + dupIndex = p.indexOf(dupSeparator, last); + } + + // Again, ignore possible trailing separator. + int end; + if (plen > 1 && p.charAt(plen - 1) == separatorChar) + end = plen - 1; + else + end = plen; + newpath.append(p.substring(last, end)); + + return newpath.toString(); + } + public File (String dirPath, String name) { if (name == null) @@ -88,13 +133,14 @@ public class File implements Serializable, Comparable if (dirPath != null && dirPath.length() > 0) { // Try to be smart about the number of separator characters. - if (dirPath.charAt(dirPath.length() - 1) == separatorChar) - path = dirPath + name; + if (dirPath.charAt(dirPath.length() - 1) == separatorChar + || name.length() == 0) + path = normalizePath(dirPath + name); else - path = dirPath + separatorChar + name; + path = normalizePath(dirPath + separatorChar + name); } else - path = name; + path = normalizePath(name); } public File (File dir, String name) @@ -439,6 +485,7 @@ public class File implements Serializable, Comparable static final String tmpdir = System.getProperty("java.io.tmpdir"); static int maxPathLen; static boolean caseSensitive; + static String dupSeparator = separator + separator; static { |