A massive organize imports and formatting of the sources using default Eclipse code...
[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 on begin
17  * of line
18  */
19 public class PHPDocCharArrayCommentReader extends SingleCharReader {
20
21         private char[] fCharArray;
22
23         private int fCurrPos;
24
25         private int fStartPos;
26
27         private int fEndPos;
28
29         private boolean fWasNewLine;
30
31         public PHPDocCharArrayCommentReader(char[] buf) {
32                 this(buf, 0, buf.length);
33         }
34
35         public PHPDocCharArrayCommentReader(char[] buf, int start, int end) {
36                 fCharArray = buf;
37                 fStartPos = start + 3;
38                 fEndPos = end - 2;
39
40                 reset();
41         }
42
43         /**
44          * @see java.io.Reader#read()
45          */
46         public int read() {
47                 if (fCurrPos < fEndPos) {
48                         char ch;
49                         if (fWasNewLine) {
50                                 do {
51                                         ch = fCharArray[fCurrPos++];
52                                 } while (fCurrPos < fEndPos && Character.isWhitespace(ch));
53                                 if (ch == '*') {
54                                         if (fCurrPos < fEndPos) {
55                                                 do {
56                                                         ch = fCharArray[fCurrPos++];
57                                                 } while (ch == '*');
58                                         } else {
59                                                 return -1;
60                                         }
61                                 }
62                         } else {
63                                 ch = fCharArray[fCurrPos++];
64                         }
65                         fWasNewLine = Strings.isLineDelimiterChar(ch);
66
67                         return ch;
68                 }
69                 return -1;
70         }
71
72         /**
73          * @see java.io.Reader#close()
74          */
75         public void close() {
76                 fCharArray = null;
77         }
78
79         /**
80          * @see java.io.Reader#reset()
81          */
82         public void reset() {
83                 fCurrPos = fStartPos;
84                 fWasNewLine = true;
85         }
86
87 }