
br.com.objectos.css.io.AttributeSelectorParser Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2016 Objectos, Fábrica de Software LTDA.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package br.com.objectos.css.io;
import br.com.objectos.codereader.CodeReader;
/**
* @author [email protected] (Marcio Endo)
*/
class AttributeSelectorParser {
private final CodeReader reader;
private String attribute = "";
private String value = "";
private AttributeOperator operator = AttributeOperator.ATTRIBUTE;
public AttributeSelectorParser(CodeReader reader) {
this.reader = reader;
}
public AttributeSelector parse() {
parseAttribute();
parseValue();
return new AttributeSelector(attribute, value, operator);
}
private void parseAttribute() {
AttributeOperator[] operators = AttributeOperator.values();
outer: while (reader.hasNext()) {
reader.consume();
for (AttributeOperator op : operators) {
if (op.matches(reader)) {
op.deleteKeyword(reader);
attribute = reader.get();
operator = op;
break outer;
}
}
}
}
private void parseValue() {
if (operator.hasValue()) {
parseValue0();
}
}
private void parseValue0() {
while (reader.hasNext()) {
reader.consume();
if (CssKeywords.stringDelimiter().matches(reader)) {
reader.deleteKeyword(CssKeywords.stringDelimiter());
value = reader.getUntil(CssKeywords.stringDelimiter());
reader.deleteKeyword(CssKeywords.stringDelimiter());
reader.skipOver(CssKeywords.attributeEnd());
break;
}
if (CssKeywords.attributeEnd().matches(reader)) {
reader.deleteKeyword(CssKeywords.attributeEnd());
value = reader.get();
break;
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy