X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/Partition.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/Partition.java new file mode 100644 index 0000000..bf83815 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/Partition.java @@ -0,0 +1,233 @@ +/* + * Created on 28.04.2003 + * + */ +package net.sourceforge.phpeclipse.phpeditor.php; + +import org.eclipse.jface.text.*; +import org.eclipse.jface.text.rules.*; + + +/** + * Defines a partition in a phpdocument. This class keeps tracks of + * partitions contained within other partitions. + * + * @author Stefan Langer + * @version $Revision: 1.1 $ + */ +public abstract class Partition +{ + private IDocument fDocument; + private IToken fContentToken; + private String fParentPartition; + private char[] fTextBuffer; + private int fOffset = 0; + private char entry; + private char exit; + private boolean inDoubleString = false; + private boolean inSingleString = false; + + public Partition(IDocument document, char[] delim, String contentType, String parentPartition) + { + fDocument = document; + fContentToken = new Token(contentType); + fParentPartition = parentPartition; + entry = delim[0]; + exit = delim[1]; + } + + public Partition(IDocument document, char[] delim, String contentType) + { + this(document, delim, contentType, IPHPPartitionScannerConstants.HTML); + } + + /** + * Checks wether the specified type is allowed within this + * partition type. + * + * @param type The type of the partition to check. + * + * @return true if the partition is allowed within this + * partition otherwise false. + */ + abstract protected boolean allowedPartition(String type); + + abstract protected boolean scan(); + + protected boolean isEnd() + { + return fOffset >= fTextBuffer.length; + } + + protected int read() + { + if(fOffset > fTextBuffer.length) + return ICharacterScanner.EOF; + + char ret = fTextBuffer[fOffset++]; + switch(ret) + { + case '\'': + if(!inDoubleString) + inSingleString = !inSingleString; + break; + case '"': + if(!inSingleString) + inDoubleString = !inDoubleString; + break; + } + return ret; + } + + protected void unread(int i) + { + for (int j = 0; j < i && fOffset > 0; j++) + { + char read = fTextBuffer[--fOffset]; + + switch (read) + { + case '\'' : + if (!inDoubleString) + inSingleString = !inSingleString; + break; + case '"' : + if (!inSingleString) + inDoubleString = !inDoubleString; + break; + } + } // END FOR + } + + public boolean scanRange(int offset, int length) + throws BadLocationException + { // short circuit scanning if entry is not correct + if (fDocument.getChar(offset) != entry) + return false; + // read the full range into the internal buffer + fOffset = 0; + inSingleString = false; + inDoubleString = false; + fTextBuffer = fDocument.get(offset, length).toCharArray(); + return scan(); + } + + protected boolean checkPattern(String pattern, boolean ignoreCase) + { + char[] checkPattern = pattern.toCharArray(); + int offset = fOffset; + for(int i=0; i