001    /*
002     * To change this template, choose Tools | Templates
003     * and open the template in the editor.
004     */
005    
006    package org.util.xml.parse;
007    
008    import java.io.IOException;
009    import org.util.xml.parse.ElementParser;
010    
011    /**
012     * parse space.
013     * S ::= (#x20 | #x9 | #xD | #xA)+
014     * <a href="http://www.fxis.co.jp/xmlcafe/tmp/rec-xml.html#NT-S">W3C REC-xml-980210</a>
015     * @author masaru
016     */
017    public class SpaceParser extends ParseElement {
018    
019        public boolean match(char c) {
020            return isSpace(c);
021        }
022    
023        @Override
024            public int parse(int c, ElementParser parser) throws XMLParseException, IOException {
025            int next_word_ = -1;
026            int state = 0;
027            while(true) {
028                if(state == 0) {
029                    if(isSpace(c)) state = 1;
030                    else throw new XMLParseException("parse error: cannot read space("+(char)c+")");
031                }else if(state == 1) {
032                    if(isSpace(c));
033                    else {
034                        next_word_ = c;
035                        break;
036                    }
037                }
038                c = parser.getChar();
039            }
040            return next_word_;
041        }
042        
043    
044    }