new PartitionScanner version
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / corext / phpdoc / PHPDocCharArrayCommentReader.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.corext.phpdoc;
12
13 import net.sourceforge.phpdt.internal.corext.util.Strings;
14
15 /**
16  * Reads a phpdoc comment from a phpdoc comment. Skips star-character
17  * on begin of line
18  */
19 public class PHPDocCharArrayCommentReader extends SingleCharReader {
20
21   private char[] fCharArray;
22   private int fCurrPos;
23   private int fStartPos;
24   private int fEndPos;
25
26   private boolean fWasNewLine;
27
28         public PHPDocCharArrayCommentReader(char[] buf) {
29                 this(buf, 0, buf.length);
30         }
31         
32   public PHPDocCharArrayCommentReader(char[] buf, int start, int end) {
33     fCharArray = buf;
34                 fStartPos= start + 3;
35                 fEndPos= end - 2;
36
37     reset();
38   }
39
40   /**
41    * @see java.io.Reader#read()
42    */
43   public int read() {
44     if (fCurrPos < fEndPos) {
45       char ch;
46       if (fWasNewLine) {
47         do {
48           ch = fCharArray[fCurrPos++];
49         } while (fCurrPos < fEndPos &&Character.isWhitespace(ch));
50         if (ch == '*') {
51           if (fCurrPos < fEndPos) {
52             do {
53               ch = fCharArray[fCurrPos++];
54             } while (ch == '*');
55           } else {
56             return -1;
57           }
58         }
59       } else {
60         ch = fCharArray[fCurrPos++];
61       }
62       fWasNewLine = Strings.isLineDelimiterChar(ch);
63
64       return ch;
65     }
66     return -1;
67   }
68
69   /**
70    * @see java.io.Reader#close()
71    */
72   public void close() {
73     fCharArray = null;
74   }
75
76   /**
77    * @see java.io.Reader#reset()
78    */
79   public void reset() {
80     fCurrPos = fStartPos;
81     fWasNewLine = true;
82   }
83
84 }