new version with WorkingCopy Management
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / util / PHPFileUtil.java
1 /*
2  * Created on 09.08.2003
3  *
4  */
5 package net.sourceforge.phpdt.internal.ui.util;
6
7 import org.eclipse.core.resources.IFile;
8
9 /**
10  * @author khartlage
11  *
12  */
13 public class PHPFileUtil {
14   public final static char[] SUFFIX_php = ".php".toCharArray(); //$NON-NLS-1$
15   public final static char[] SUFFIX_PHP = ".PHP".toCharArray(); //$NON-NLS-1$
16   public final static char[] SUFFIX_php3 = ".php3".toCharArray(); //$NON-NLS-1$
17   public final static char[] SUFFIX_PHP3 = ".PHP3".toCharArray(); //$NON-NLS-1$
18   public final static char[] SUFFIX_php4 = ".php4".toCharArray(); //$NON-NLS-1$
19   public final static char[] SUFFIX_PHP4 = ".PHP4".toCharArray(); //$NON-NLS-1$
20   public final static char[] SUFFIX_inc = ".inc".toCharArray(); //$NON-NLS-1$
21   public final static char[] SUFFIX_INC = ".INC".toCharArray(); //$NON-NLS-1$
22
23   public  static boolean isPHPFile(IFile file) {
24     String extension = file.getFileExtension();
25     return isPHPFileName(file.getLocation().toString());
26   }
27
28   /**
29    * Returns true iff str.toLowerCase().endsWith(".php")
30    * implementation is not creating extra strings.
31    */
32   public final static boolean isPHPFileName(String name) {
33     return isPHP_FileName(name) || isPHP3_FileName(name) || isPHP4_FileName(name) || isINC_FileName(name);
34   }
35   //  static public boolean isPHPFile(String extension) {
36   //    if ("php".equalsIgnoreCase(extension)
37   //      || "php3".equalsIgnoreCase(extension)
38   //      || "php4".equalsIgnoreCase(extension)
39   //      || "inc".equalsIgnoreCase(extension)) {
40   //      return true;
41   //    }
42   //    return false;
43   //  }
44
45   /**
46    * Returns true iff str.toLowerCase().endsWith(".php")
47    * implementation is not creating extra strings.
48    */
49   private final static boolean isPHP_FileName(String name) {
50     int nameLength = name == null ? 0 : name.length();
51     int suffixLength = SUFFIX_PHP.length;
52     if (nameLength < suffixLength)
53       return false;
54
55     for (int i = 0, offset = nameLength - suffixLength; i < suffixLength; i++) {
56       char c = name.charAt(offset + i);
57       if (c != SUFFIX_php[i] && c != SUFFIX_PHP[i])
58         return false;
59     }
60     return true;
61   }
62
63   /**
64    * Returns true iff str.toLowerCase().endsWith(".php3")
65    * implementation is not creating extra strings.
66    */
67   private final static boolean isPHP3_FileName(String name) {
68     int nameLength = name == null ? 0 : name.length();
69     int suffixLength = SUFFIX_PHP3.length;
70     if (nameLength < suffixLength)
71       return false;
72
73     for (int i = 0, offset = nameLength - suffixLength; i < suffixLength; i++) {
74       char c = name.charAt(offset + i);
75       if (c != SUFFIX_php3[i] && c != SUFFIX_PHP3[i])
76         return false;
77     }
78     return true;
79   }
80
81   /**
82    * Returns true iff str.toLowerCase().endsWith(".php4")
83    * implementation is not creating extra strings.
84    */
85   private final static boolean isPHP4_FileName(String name) {
86     int nameLength = name == null ? 0 : name.length();
87     int suffixLength = SUFFIX_PHP4.length;
88     if (nameLength < suffixLength)
89       return false;
90
91     for (int i = 0, offset = nameLength - suffixLength; i < suffixLength; i++) {
92       char c = name.charAt(offset + i);
93       if (c != SUFFIX_php4[i] && c != SUFFIX_PHP4[i])
94         return false;
95     }
96     return true;
97   }
98
99   /**
100    * Returns true iff str.toLowerCase().endsWith(".inc")
101    * implementation is not creating extra strings.
102    */
103   private final static boolean isINC_FileName(String name) {
104     int nameLength = name == null ? 0 : name.length();
105     int suffixLength = SUFFIX_INC.length;
106     if (nameLength < suffixLength)
107       return false;
108
109     for (int i = 0, offset = nameLength - suffixLength; i < suffixLength; i++) {
110       char c = name.charAt(offset + i);
111       if (c != SUFFIX_inc[i] && c != SUFFIX_INC[i])
112         return false;
113     }
114     return true;
115   }
116 }