Partitionscanner Framework
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / php / PHPPartition.java
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartition.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartition.java
new file mode 100644 (file)
index 0000000..522df96
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Created on 28.04.2003
+ *
+ */
+package net.sourceforge.phpeclipse.phpeditor.php;
+
+import org.eclipse.jface.text.*;
+
+/**
+ * @author slanger
+ * @version $Revision: 1.1 $
+ */
+public class PHPPartition extends Partition
+{
+       private boolean fShortTagsEnabled = true;
+       
+    /**
+     * @param document
+     * @param delim
+     * @param contentType
+     * @param parentPartition
+     */
+    public PHPPartition(IDocument document, String parentPartition)
+    {
+        super(
+            document,
+            new char[] { '<', '>' },
+            IPHPPartitionScannerConstants.PHP,
+            parentPartition);
+    }
+
+    
+
+    /* (non-Javadoc)
+     * @see net.sourceforge.phpeclipse.phpeditor.php.Partition#allowedPartition(java.lang.String)
+     */
+    protected boolean allowedPartition(String type)
+    {
+        if(type.equals(IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT))
+               return true;
+               
+        return false;
+    }
+
+    /* (non-Javadoc)
+     * @see net.sourceforge.phpeclipse.phpeditor.php.Partition#scan()
+     */
+    protected boolean scan()
+    {
+       int ch;
+       if(fShortTagsEnabled && checkPattern("<?", true))
+       {
+               scanToEnd();
+       }
+       else if(checkPattern("<?php", false))
+       {
+               scanToEnd();
+       }    
+       else
+               return false;
+       
+       return true;    
+    }
+       
+       private void scanToEnd()
+       {
+               if(isEnd())
+                       return;
+                               
+               while(!checkPattern("?>", true))
+               {
+                       int offset = getOffset();
+                       if(checkPattern("/*", true))
+                       {       
+                               unread(2);
+                               return;
+                       }
+               }               
+       }
+}