bugfix 1423269, http://sourceforge.net/tracker/index.php?func=detail&aid=1423269...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / text / BufferedDocumentScanner.java
index 26116e0..b4fe57d 100644 (file)
@@ -1,19 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * 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-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
 package net.sourceforge.phpdt.internal.ui.text;
 
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
 
+import org.eclipse.jface.text.Assert;
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.rules.ICharacterScanner;
-import org.eclipse.jface.util.Assert;
 
 
 
 /**
- * A buffered document scanner. The buffer always contains a section 
+ * A buffered document scanner. The buffer always contains a section
  * of a fixed size of the document to be scanned.
  */
 
@@ -37,11 +43,11 @@ public final class BufferedDocumentScanner implements ICharacterScanner {
        /** The offset of the scanner within the buffer. */
        private int fOffset;
 
-       
+
        /**
         * Creates a new buffered document scanner.
         * The buffer size is set to the given number of characters.
-        * 
+        *
         * @param size the buffer size
         */
        public BufferedDocumentScanner(int size) {
@@ -57,7 +63,7 @@ public final class BufferedDocumentScanner implements ICharacterScanner {
        private final void updateBuffer(int offset) {
 
                fBufferOffset= offset;
-               
+
                if (fBufferOffset + fBuffer.length > fRangeOffset + fRangeLength)
                        fBufferLength= fRangeLength - (fBufferOffset - fRangeOffset);
                else
@@ -65,7 +71,9 @@ public final class BufferedDocumentScanner implements ICharacterScanner {
 
                try {
                        final String content= fDocument.get(fBufferOffset, fBufferLength);
-                       content.getChars(0, fBufferLength, fBuffer, 0);
+                       if (content!=null) {
+                         content.getChars(0, fBufferLength, fBuffer, 0);
+                       }
                } catch (BadLocationException e) {
                }
        }
@@ -105,8 +113,13 @@ public final class BufferedDocumentScanner implements ICharacterScanner {
                                fOffset= 0;
                        }
                }
-
+        try {
                return fBuffer[fOffset++];
+        } catch (ArrayIndexOutOfBoundsException e) {
+          System.out.println("Offset:"+fOffset);
+          System.out.println("Buffer:"+fBuffer.toString());
+          throw e;
+        }
        }
 
        /*
@@ -121,7 +134,7 @@ public final class BufferedDocumentScanner implements ICharacterScanner {
                                updateBuffer(fBufferOffset - fBuffer.length);
                                fOffset= fBuffer.length - 1;
                        }
-               } else {                        
+               } else {
                        --fOffset;
                }
        }
@@ -148,4 +161,4 @@ public final class BufferedDocumentScanner implements ICharacterScanner {
        public final char[][] getLegalLineDelimiters() {
                return fDelimiters;
        }
-}
\ No newline at end of file
+}