* Contributors:
* Igor Malinin - initial contribution
*
- * $Id: AbstractDocumentProvider.java,v 1.2 2005-05-06 00:55:41 stefanbjarni Exp $
+ * $Id: AbstractDocumentProvider.java,v 1.3 2006-10-21 23:14:13 pombredanne Exp $
*/
package net.sourceforge.phpeclipse.xml.ui.internal.text;
import org.eclipse.jface.text.rules.IWhitespaceDetector;
-
/**
*
*
return "UTF-8";
}
- public String getDeclaredEncoding( InputStream in ) throws IOException {
- if ( !in.markSupported() ) {
- in = new BufferedInputStream( in, 512 );
+ public String getDeclaredEncoding(InputStream in) throws IOException {
+ if (!in.markSupported()) {
+ in = new BufferedInputStream(in, 512);
}
- in.mark( 512 );
- String encoding = super.getDeclaredEncoding( in );
- if ( encoding != null ) {
+ in.mark(512);
+ String encoding = super.getDeclaredEncoding(in);
+ if (encoding != null) {
return encoding;
}
in.reset();
// check Prolog-Start <?xml
- if ( !skipXMLDecl(in) ) {
+ if (!skipXMLDecl(in)) {
return null;
}
// detect 'encoding'
- skipEncoding( in );
+ skipEncoding(in);
// read encoding
int delimiter;
- while ( true ) {
+ while (true) {
int ch = in.read();
- if ( ch < 0 ) {
+ if (ch < 0) {
return null;
}
- if ( detector.isWhitespace((char) ch) ) {
+ if (detector.isWhitespace((char) ch)) {
continue;
}
- if ( ch == '"' || ch == '\'' ) {
+ if (ch == '"' || ch == '\'') {
delimiter = ch;
break;
}
StringBuffer buf = new StringBuffer();
- while ( true ) {
+ while (true) {
int ch = in.read();
- if ( ch < 0 ) {
+ if (ch < 0) {
return null;
}
- if ( ch == delimiter ) {
+ if (ch == delimiter) {
break;
}
- buf.append( (char) ch );
+ buf.append((char) ch);
}
return buf.toString();
}
- private boolean skipXMLDecl( InputStream in ) throws IOException {
+ private boolean skipXMLDecl(InputStream in) throws IOException {
int ch = in.read();
- if ( ch != '<' ) {
+ if (ch != '<') {
return false;
}
ch = in.read();
- if ( ch != '?' ) {
+ if (ch != '?') {
return false;
}
ch = in.read();
- if ( ch != 'x' ) {
+ if (ch != 'x') {
return false;
}
ch = in.read();
- if ( ch != 'm' ) {
+ if (ch != 'm') {
return false;
}
ch = in.read();
- if ( ch != 'l' ) {
+ if (ch != 'l') {
return false;
}
return true;
}
- private boolean skipEncoding( InputStream in ) throws IOException {
+ private boolean skipEncoding(InputStream in) throws IOException {
int ch = in.read();
boolean whitespace = false;
- while ( true ) {
- if ( ch < 0 ) {
+ while (true) {
+ if (ch < 0) {
return false;
}
- if ( detector.isWhitespace((char) ch) ) {
+ if (detector.isWhitespace((char) ch)) {
ch = in.read();
whitespace = true;
continue;
}
- if ( ch == '?' || ch == '<' ) {
+ if (ch == '?' || ch == '<') {
return false;
}
- if ( ch != 'e' ) {
+ if (ch != 'e') {
ch = in.read();
whitespace = false;
continue;
}
- if ( !whitespace ) {
+ if (!whitespace) {
ch = in.read();
continue;
}
- if ( (ch = in.read()) == 'n' &&
- (ch = in.read()) == 'c' &&
- (ch = in.read()) == 'o' &&
- (ch = in.read()) == 'd' &&
- (ch = in.read()) == 'i' &&
- (ch = in.read()) == 'n' &&
- (ch = in.read()) == 'g' ) {
+ if ((ch = in.read()) == 'n' && (ch = in.read()) == 'c'
+ && (ch = in.read()) == 'o' && (ch = in.read()) == 'd'
+ && (ch = in.read()) == 'i' && (ch = in.read()) == 'n'
+ && (ch = in.read()) == 'g') {
break;
}
}
// '='
- while ( true ) {
+ while (true) {
ch = in.read();
- if ( ch < 0 ) {
+ if (ch < 0) {
return false;
}
- if ( detector.isWhitespace((char) ch) ) {
+ if (detector.isWhitespace((char) ch)) {
continue;
}
- if ( ch == '=' ) {
+ if (ch == '=') {
break;
}