
br.com.objectos.css.io.CssKeywords 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;
import br.com.objectos.codereader.Keyword;
import br.com.objectos.codereader.OptionalChar;
/**
* @author [email protected] (Marcio Endo)
*/
class CssKeywords {
private static final Keyword ATTR_END = Keyword.of(']');
private CssKeywords() {
}
public static Keyword attributeEnd() {
return ATTR_END;
}
public static Keyword identifierChar() {
return IdentifierCharKeyword.INSTANCE;
}
public static Keyword stringDelimiter() {
return StringDelimiterKeyword.INSTANCE;
}
private enum IdentifierCharKeyword implements Keyword {
INSTANCE;
@Override
public boolean matches(CodeReader reader) {
if (reader.empty()) {
return false;
}
return test(reader.last());
}
@Override
public boolean peek(CodeReader reader) {
OptionalChar peek = reader.peek();
return peek.isPresent()
? test(peek.getAsChar())
: test(reader.last());
}
@Override
public int size() {
return 1;
}
private boolean test(char theChar) {
return Character.isLetterOrDigit(theChar) || theChar == '_' || theChar == '-';
}
}
private enum StringDelimiterKeyword implements Keyword {
INSTANCE;
@Override
public boolean matches(CodeReader reader) {
if (reader.empty()) {
return false;
}
return test(reader.last());
}
@Override
public int size() {
return 1;
}
private boolean test(char theChar) {
return theChar == '\'' || theChar == '"';
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy