/** * Determines if the underlying input is looking at a valid character to start an identifier * <p> * By default, only letters can start identifiers * * @return <tt>true</tt> if the underlying input is looking at a valid identifier starter, <tt>false</tt> otherwise */ protected boolean isAtStartOfIdentifier() { return input.current().isLetter(); }
/** * Determines if the underlying input is looking at a valid character to start an identifier * <p> * By default, only letters can start identifiers * * @return <tt>true</tt> if the underlying input is looking at a valid identifier starter, <tt>false</tt> otherwise */ protected boolean isAtStartOfIdentifier() { return input.current().isLetter(); }
/** * Determines if the given Char is a valid identifier part. * <p> * By default, letters, digits and '_' are valid identifier parts. * * @param current the character to check * @return <tt>true</tt> if the given Char is a valid identifier part, <tt>false</tt> otherwise */ protected boolean isIdentifierChar(Char current) { return current.isDigit() || current.isLetter() || current.is('_'); }
/** * Determines if the given Char is a valid identifier part. * <p> * By default, letters, digits and '_' are valid identifier parts. * * @param current the character to check * @return <tt>true</tt> if the given Char is a valid identifier part, <tt>false</tt> otherwise */ protected boolean isIdentifierChar(Char current) { return current.isDigit() || current.isLetter() || current.is('_'); }
@Override protected boolean isAtStartOfIdentifier() { if (super.isAtStartOfIdentifier()) { return true; } // Support vendor specific and class selectors like -moz-border-radius or .test return (input.current().is('-') || input.current().is('.')) && input.next().isLetter(); }
protected Tuple<String, String> parseFieldAndValue(LookaheadReader reader) { String field = defaultField; boolean couldBeFieldNameSoFar = true; StringBuilder valueBuilder = new StringBuilder(); while (!reader.current().isEndOfInput() && !reader.current().isWhitepace() && !reader.current().is(')')) { if (reader.current().is(':') && valueBuilder.length() > 0 && couldBeFieldNameSoFar) { field = valueBuilder.toString(); valueBuilder = new StringBuilder(); // Ignore : reader.consume(); couldBeFieldNameSoFar = false; } else { if (couldBeFieldNameSoFar) { couldBeFieldNameSoFar = reader.current().is('-', '_') || reader.current().isLetter() || reader.current().isDigit(); } valueBuilder.append(reader.consume().getValue()); } } return Tuple.create(field, valueBuilder.toString()); }
/** * Determines if the given Char is a symbol character. * <p> * By default these are all non-control characters, which don't match any other class (letter, digit, whitepsace) * * @param ch the character to check * @return <tt>true</tt> if the given character is a valid symbol character, <tt>false</tt> otherwise */ @SuppressWarnings("squid:S1067") protected boolean isSymbolCharacter(Char ch) { if (ch.isEndOfInput() || ch.isDigit() || ch.isLetter() || ch.isWhitepace()) { return false; } char c = ch.getValue(); if (Character.isISOControl(c)) { return false; } return !(isAtBracket(true) || isAtStartOfBlockComment(false) || isAtStartOfLineComment(false) || isAtStartOfNumber() || isAtStartOfIdentifier() || stringDelimiters.containsKey(ch.getValue())); }
/** * Determines if the given Char is a symbol character. * <p> * By default these are all non-control characters, which don't match any other class (letter, digit, whitepsace) * * @param ch the character to check * @return <tt>true</tt> if the given character is a valid symbol character, <tt>false</tt> otherwise */ @SuppressWarnings("squid:S1067") protected boolean isSymbolCharacter(Char ch) { if (ch.isEndOfInput() || ch.isDigit() || ch.isLetter() || ch.isWhitepace()) { return false; } char c = ch.getValue(); if (Character.isISOControl(c)) { return false; } return !(isAtBracket(true) || isAtStartOfBlockComment(false) || isAtStartOfLineComment(false) || isAtStartOfNumber() || isAtStartOfIdentifier() || stringDelimiters.containsKey(ch.getValue())); }
@Override protected Token fetchNumber() { Token token = super.fetchNumber(); // If a number is immediately followed by % or a text like "px" - this belongs to the numeric token. if (input.current().is('%')) { token.addToContent(input.consume()); return token; } while (input.current().isLetter()) { token.addToContent(input.consume()); } return token; }