classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] simplifying java.io.File windows checks


From: Dalibor Topic
Subject: [cp-patches] simplifying java.io.File windows checks
Date: Thu, 12 Aug 2004 04:53:37 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040413 Debian/1.6-5

Hi all,

the attached patch replaces all the instances of checks whether we are running on Windows with a simple private static final boolean variable test. I hope it makes the code clearer and more readable.

changelog:

2004-08-12  Dalibor Topic  <address@hidden>

        * java/io/File (ON_WINDOWS): New constant.
        Use ON_WINDOWS instead of checking separatorChar.

cheers,
dalibor topic
--- /tmp/topic/classpath/java/io/File.java      2004-07-27 10:44:08.000000000 
+0200
+++ /tmp/topic/kaffe/libraries/javalib/java/io/File.java        2004-08-12 
03:32:32.000000000 +0200
@@ -155,7 +155,7 @@
              accept '/' as separator. In that case the following code
              will fail.
           */
-          String filename = (separatorChar!='\\')?"test-dir-write":"tst";
+          String filename = (!ON_WINDOWS)?"test-dir-write":"tst";
          File test = createTempFile(filename, null, this);
          return (test != null && test.delete());
         }
@@ -264,7 +264,7 @@
   {
     // On Windows, convert any '/' to '\'.  This appears to be the same logic
     // that Sun's Win32 Java performs.
-    if (separatorChar == '\\')
+    if (ON_WINDOWS)
       {
         p = p.replace ('/', '\\');
        // We have to special case the "\c:" prefix.
@@ -288,7 +288,7 @@
         // example, is a valid and minimal path).
         if (plen > 1 && p.charAt (plen - 1) == separatorChar)
          {
-           if (! (separatorChar == '\\' && plen == 3 && p.charAt (1) == ':'))
+           if (! (ON_WINDOWS && plen == 3 && p.charAt (1) == ':'))
              return p.substring (0, plen - 1);
          }
        else
@@ -317,7 +317,7 @@
     int end;
     if (plen > 1 && p.charAt (plen - 1) == separatorChar)
     {
-      if (separatorChar == '\\' && plen == 3 && p.charAt (1) == ':')
+      if (ON_WINDOWS && plen == 3 && p.charAt (1) == ':')
         end = plen;
       else
         end = plen - 1;
@@ -401,7 +408,7 @@
   {
     if (isAbsolute())
       return path;
-    else if (separatorChar == '\\' 
+    else if (ON_WINDOWS 
              && path.length() > 0 && path.charAt (0) == '\\')
       {
         // On Windows, even if the path starts with a '\\' it is not
@@ -409,7 +416,7 @@
         // the current working directory to it.
         return System.getProperty ("user.dir").substring (0, 2) + path;
       }
-    else if (separatorChar == '\\' 
+    else if (ON_WINDOWS 
              && path.length() > 1 && path.charAt (1) == ':'
              && ((path.charAt (0) >= 'a' && path.charAt (0) <= 'z')
                  || (path.charAt (0) >= 'A' && path.charAt (0) <= 'Z')))
@@ -470,7 +477,7 @@
   {
     // On Windows, getAbsolutePath might end up calling us, so we
     // have to special case that call to avoid infinite recursion.
-    if (separatorChar == '\\' && path.length() == 2 &&
+    if (ON_WINDOWS && path.length() == 2 &&
        ((path.charAt(0) >= 'a' && path.charAt(0) <= 'z') ||
         (path.charAt(0) >= 'A' && path.charAt(0) <= 'Z')) &&
        path.charAt(1) == ':')
@@ -531,7 +538,7 @@
         prefix = "/";
         nameSeqIndex = 1;
       }
-    else if (separatorChar == '\\' && path.length() > 1)
+    else if (ON_WINDOWS && path.length() > 1)
       {
         if ((path.charAt (0) == '\\' && path.charAt (1) == '\\')
             || (((path.charAt (0) >= 'a' && path.charAt (0) <= 'z')
@@ -625,7 +632,7 @@
    */
   public boolean isAbsolute()
   {
-    if (separatorChar == '\\')
+    if (ON_WINDOWS)
        return path.startsWith(dupSeparator) || 
            (path.length() > 2 && 
             ((path.charAt(0) >= 'a' && path.charAt(0) <= 'z') ||
@@ -937,7 +944,7 @@
     if (isDirectory())
       abspath = abspath + separatorChar;
 
-    if (separatorChar == '\\')
+    if (ON_WINDOWS)
       abspath = separatorChar + abspath;
         
     try
@@ -968,7 +975,7 @@
   {
     // On Win32, Sun's JDK returns URLs of the form "file:/c:/foo/bar.txt",
     // while on UNIX, it returns URLs of the form "file:/foo/bar.txt". 
-    if (separatorChar == '\\')
+    if (ON_WINDOWS)
       return new URL ("file:/" + getAbsolutePath().replace ('\\', '/')
                      + (isDirectory() ? "/" : ""));
     else
@@ -1086,7 +1093,7 @@
        will fail.
     */
     File file;
-    if (separatorChar!='\\')
+    if (!ON_WINDOWS)
       {      
         // probably a non-DOS-filesystem, use long names
         do
@@ -1351,6 +1358,11 @@
     if (oldSeparatorChar != separatorChar)
       path = path.replace(oldSeparatorChar, separatorChar);
   }
-  
+
+  /**
+   * Used to determine whether we are running under Windows.
+   */
+  private static final boolean ON_WINDOWS = separatorChar =='\\';
+
 } // class File
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]