X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/util/Util.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/util/Util.java index ec4ecbb..85f7fad 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/util/Util.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/util/Util.java @@ -1,13 +1,13 @@ /******************************************************************************* - * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others. + * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 + * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html + * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation - ******************************************************************************/ + *******************************************************************************/ package net.sourceforge.phpdt.internal.compiler.util; import java.io.BufferedInputStream; @@ -23,26 +23,30 @@ import java.util.ResourceBundle; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import net.sourceforge.phpdt.core.compiler.CharOperation; +import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil; + public class Util { public static String LINE_SEPARATOR = System.getProperty("line.separator"); //$NON-NLS-1$ public static char[] LINE_SEPARATOR_CHARS = LINE_SEPARATOR.toCharArray(); - public final static char[] SUFFIX_class = ".class".toCharArray(); //$NON-NLS-1$ - public final static char[] SUFFIX_CLASS = ".CLASS".toCharArray(); //$NON-NLS-1$ +// public final static char[] SUFFIX_class = ".class".toCharArray(); //$NON-NLS-1$ +// public final static char[] SUFFIX_CLASS = ".CLASS".toCharArray(); //$NON-NLS-1$ public final static char[] SUFFIX_java = ".java".toCharArray(); //$NON-NLS-1$ public final static char[] SUFFIX_JAVA = ".JAVA".toCharArray(); //$NON-NLS-1$ - public final static char[] SUFFIX_jar = ".jar".toCharArray(); //$NON-NLS-1$ - public final static char[] SUFFIX_JAR = ".JAR".toCharArray(); //$NON-NLS-1$ +// public final static char[] SUFFIX_jar = ".jar".toCharArray(); //$NON-NLS-1$ +// public final static char[] SUFFIX_JAR = ".JAR".toCharArray(); //$NON-NLS-1$ public final static char[] SUFFIX_zip = ".zip".toCharArray(); //$NON-NLS-1$ public final static char[] SUFFIX_ZIP = ".ZIP".toCharArray(); //$NON-NLS-1$ private final static char[] DOUBLE_QUOTES = "''".toCharArray(); //$NON-NLS-1$ private final static char[] SINGLE_QUOTE = "'".toCharArray(); //$NON-NLS-1$ - + private static final int DEFAULT_READING_SIZE = 8192; + /* Bundle containing messages */ protected static ResourceBundle bundle; private final static String bundleName = - "org.eclipse.jdt.internal.compiler.util.messages"; //$NON-NLS-1$ + "net.sourceforge.phpdt.internal.compiler.util.messages"; //$NON-NLS-1$ static { relocalize(); } @@ -121,7 +125,12 @@ public class Util { * Creates a NLS catalog for the given locale. */ public static void relocalize() { - bundle = ResourceBundle.getBundle(bundleName, Locale.getDefault()); + try { + bundle = ResourceBundle.getBundle(bundleName, Locale.getDefault()); + } catch(MissingResourceException e) { + System.out.println("Missing resource : " + bundleName.replace('.', '/') + ".properties for locale " + Locale.getDefault()); //$NON-NLS-1$//$NON-NLS-2$ + throw e; + } } /** * Returns the given bytes as a char array using a given encoding (null means platform default). @@ -181,28 +190,28 @@ public class Util { if (length == -1) { contents = new byte[0]; int contentsLength = 0; - int bytesRead = -1; + int amountRead = -1; do { - int available = stream.available(); - + int amountRequested = Math.max(stream.available(), DEFAULT_READING_SIZE); // read at least 8K + // resize contents if needed - if (contentsLength + available > contents.length) { + if (contentsLength + amountRequested > contents.length) { System.arraycopy( contents, 0, - contents = new byte[contentsLength + available], + contents = new byte[contentsLength + amountRequested], 0, contentsLength); } // read as many bytes as possible - bytesRead = stream.read(contents, contentsLength, available); + amountRead = stream.read(contents, contentsLength, amountRequested); - if (bytesRead > 0) { + if (amountRead > 0) { // remember length of contents - contentsLength += bytesRead; + contentsLength += amountRead; } - } while (bytesRead > 0); + } while (amountRead != -1); // resize contents if necessary if (contentsLength < contents.length) { @@ -242,30 +251,30 @@ public class Util { : new InputStreamReader(stream, encoding); char[] contents; if (length == -1) { - contents = new char[0]; + contents = CharOperation.NO_CHAR; int contentsLength = 0; - int charsRead = -1; + int amountRead = -1; do { - int available = stream.available(); + int amountRequested = Math.max(stream.available(), DEFAULT_READING_SIZE); // read at least 8K // resize contents if needed - if (contentsLength + available > contents.length) { + if (contentsLength + amountRequested > contents.length) { System.arraycopy( contents, 0, - contents = new char[contentsLength + available], + contents = new char[contentsLength + amountRequested], 0, contentsLength); } // read as many chars as possible - charsRead = reader.read(contents, contentsLength, available); + amountRead = reader.read(contents, contentsLength, amountRequested); - if (charsRead > 0) { + if (amountRead > 0) { // remember length of contents - contentsLength += charsRead; + contentsLength += amountRead; } - } while (charsRead > 0); + } while (amountRead != -1); // resize contents if necessary if (contentsLength < contents.length) { @@ -320,60 +329,62 @@ public class Util { * Returns true iff str.toLowerCase().endsWith(".jar") || str.toLowerCase().endsWith(".zip") * implementation is not creating extra strings. */ - public final static boolean isArchiveFileName(String name) { - int nameLength = name == null ? 0 : name.length(); - int suffixLength = SUFFIX_JAR.length; - if (nameLength < suffixLength) return false; - - // try to match as JAR file - for (int i = 0; i < suffixLength; i++) { - char c = name.charAt(nameLength - i - 1); - int suffixIndex = suffixLength - i - 1; - if (c != SUFFIX_jar[suffixIndex] && c != SUFFIX_JAR[suffixIndex]) { - - // try to match as ZIP file - suffixLength = SUFFIX_ZIP.length; - if (nameLength < suffixLength) return false; - for (int j = 0; j < suffixLength; j++) { - c = name.charAt(nameLength - j - 1); - suffixIndex = suffixLength - j - 1; - if (c != SUFFIX_zip[suffixIndex] && c != SUFFIX_ZIP[suffixIndex]) return false; - } - return true; - } - } - return true; - } +// public final static boolean isArchiveFileName(String name) { +// int nameLength = name == null ? 0 : name.length(); +// int suffixLength = SUFFIX_JAR.length; +// if (nameLength < suffixLength) return false; +// +// // try to match as JAR file +// for (int i = 0; i < suffixLength; i++) { +// char c = name.charAt(nameLength - i - 1); +// int suffixIndex = suffixLength - i - 1; +// if (c != SUFFIX_jar[suffixIndex] && c != SUFFIX_JAR[suffixIndex]) { +// +// // try to match as ZIP file +// suffixLength = SUFFIX_ZIP.length; +// if (nameLength < suffixLength) return false; +// for (int j = 0; j < suffixLength; j++) { +// c = name.charAt(nameLength - j - 1); +// suffixIndex = suffixLength - j - 1; +// if (c != SUFFIX_zip[suffixIndex] && c != SUFFIX_ZIP[suffixIndex]) return false; +// } +// return true; +// } +// } +// return true; +// } /** * Returns true iff str.toLowerCase().endsWith(".class") * implementation is not creating extra strings. */ - public final static boolean isClassFileName(String name) { - int nameLength = name == null ? 0 : name.length(); - int suffixLength = SUFFIX_CLASS.length; - if (nameLength < suffixLength) return false; - - for (int i = 0; i < suffixLength; i++) { - char c = name.charAt(nameLength - i - 1); - int suffixIndex = suffixLength - i - 1; - if (c != SUFFIX_class[suffixIndex] && c != SUFFIX_CLASS[suffixIndex]) return false; - } - return true; - } +// public final static boolean isClassFileName(String name) { +// int nameLength = name == null ? 0 : name.length(); +// int suffixLength = SUFFIX_CLASS.length; +// if (nameLength < suffixLength) return false; +// +// for (int i = 0; i < suffixLength; i++) { +// char c = name.charAt(nameLength - i - 1); +// int suffixIndex = suffixLength - i - 1; +// if (c != SUFFIX_class[suffixIndex] && c != SUFFIX_CLASS[suffixIndex]) return false; +// } +// return true; +// } + /** * Returns true iff str.toLowerCase().endsWith(".java") * implementation is not creating extra strings. */ public final static boolean isJavaFileName(String name) { - int nameLength = name == null ? 0 : name.length(); - int suffixLength = SUFFIX_JAVA.length; - if (nameLength < suffixLength) return false; - - for (int i = 0; i < suffixLength; i++) { - char c = name.charAt(nameLength - i - 1); - int suffixIndex = suffixLength - i - 1; - if (c != SUFFIX_java[suffixIndex] && c != SUFFIX_JAVA[suffixIndex]) return false; - } - return true; + return PHPFileUtil.isPHPFileName(name); +// int nameLength = name == null ? 0 : name.length(); +// int suffixLength = SUFFIX_JAVA.length; +// if (nameLength < suffixLength) return false; +// +// for (int i = 0; i < suffixLength; i++) { +// char c = name.charAt(nameLength - i - 1); +// int suffixIndex = suffixLength - i - 1; +// if (c != SUFFIX_java[suffixIndex] && c != SUFFIX_JAVA[suffixIndex]) return false; +// } +// return true; } -} \ No newline at end of file +}