7b1f275aaf02c87a8679d0391aa5a4ed12757236
[phpeclipse.git] /
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.core.IBuffer;
14 import net.sourceforge.phpdt.internal.corext.util.Strings;
15
16
17 /**
18  * Reads a java doc comment from a java doc comment. Skips star-character
19  * on begin of line
20  */
21 public class PHPDocCommentReader extends SingleCharReader {
22
23         private IBuffer fBuffer;
24         
25         private int fCurrPos;
26         private int fStartPos;
27         private int fEndPos;
28         
29         private boolean fWasNewLine;
30                 
31         public PHPDocCommentReader(IBuffer buf, int start, int end) {
32                 fBuffer= buf;
33                 fStartPos= start + 3;
34                 fEndPos= end - 2;
35                 
36                 reset();
37         }
38                 
39         /**
40          * @see java.io.Reader#read()
41          */
42         public int read() {
43                 if (fCurrPos < fEndPos) {
44                         char ch;
45                         if (fWasNewLine) {
46                                 do {
47                                         ch= fBuffer.getChar(fCurrPos++);
48                                 } while (fCurrPos < fEndPos && Character.isWhitespace(ch));
49                                 if (ch == '*') {
50                                         if (fCurrPos < fEndPos) {
51                                                 do {
52                                                         ch= fBuffer.getChar(fCurrPos++);
53                                                 } while (ch == '*');
54                                         } else {
55                                                 return -1;
56                                         }
57                                 }
58                         } else {
59                                 ch= fBuffer.getChar(fCurrPos++);
60                         }
61                         fWasNewLine= Strings.isLineDelimiterChar(ch);
62                         
63                         return ch;
64                 }
65                 return -1;
66         }
67                 
68         /**
69          * @see java.io.Reader#close()
70          */             
71         public void close() {
72                 fBuffer= null;
73         }
74         
75         /**
76          * @see java.io.Reader#reset()
77          */             
78         public void reset() {
79                 fCurrPos= fStartPos;
80                 fWasNewLine= true;
81         }       
82                 
83                 
84 }