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 org.util.xml.parse.ElementParser;
009    
010    /**
011     * parse space.
012     * S ::= (#x20 | #x9 | #xD | #xA)+
013     * <a href="http://www.fxis.co.jp/xmlcafe/tmp/rec-xml.html#NT-S">W3C REC-xml-980210</a>
014     * @author masaru
015     */
016    public class SpaceParser extends ParseElement {
017    
018        public boolean match(char c) {
019            return isSpace(c);
020        }
021    
022        @Override
023        public int parse(int c, ElementParser parser) throws Exception {
024            int next_word_ = -1;
025            int state = 0;
026            while(true) {
027                if(state == 0) {
028                    if(isSpace(c)) state = 1;
029                    else throw new Exception("parse error: cannot read space("+(char)c+")");
030                }else if(state == 1) {
031                    if(isSpace(c));
032                    else {
033                        next_word_ = c;
034                        break;
035                    }
036                }
037                c = parser.getChar();
038            }
039            return next_word_;
040        }
041        
042    
043    }