2 * Created on 09.08.2003
5 package net.sourceforge.phpdt.internal.ui.util;
7 import org.eclipse.core.resources.IFile;
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$
23 public static boolean isPHPFile(IFile file) {
24 String extension = file.getFileExtension();
25 return isPHPFileName(file.getLocation().toString());
29 * Returns true iff str.toLowerCase().endsWith(".php")
30 * implementation is not creating extra strings.
32 public final static boolean isPHPFileName(String name) {
33 return isPHP_FileName(name) || isPHP3_FileName(name) || isPHP4_FileName(name) || isINC_FileName(name);
35 // static public boolean isPHPFile(String extension) {
36 // if ("php".equalsIgnoreCase(extension)
37 // || "php3".equalsIgnoreCase(extension)
38 // || "php4".equalsIgnoreCase(extension)
39 // || "inc".equalsIgnoreCase(extension)) {
46 * Returns true iff str.toLowerCase().endsWith(".php")
47 * implementation is not creating extra strings.
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)
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])
64 * Returns true iff str.toLowerCase().endsWith(".php3")
65 * implementation is not creating extra strings.
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)
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])
82 * Returns true iff str.toLowerCase().endsWith(".php4")
83 * implementation is not creating extra strings.
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)
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])
100 * Returns true iff str.toLowerCase().endsWith(".inc")
101 * implementation is not creating extra strings.
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)
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])