Skip to content

Commit

Permalink
[refactoring] rename "URI" to "uri"
Browse files Browse the repository at this point in the history
  • Loading branch information
asolntsev committed Dec 28, 2023
1 parent e100566 commit 8a1da8c
Showing 1 changed file with 23 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public class CSSParser {

private Token _saved;
private final Lexer _lexer;
private CSSErrorHandler _errorHandler;
private String _URI;
private final CSSErrorHandler _errorHandler;
private String _uri;

private final Map<String, String> _namespaces = new HashMap<>();
private boolean _supportCMYKColors;
Expand All @@ -70,7 +70,7 @@ public CSSParser(CSSErrorHandler errorHandler) {

public Stylesheet parseStylesheet(String uri, int origin, Reader reader)
throws IOException {
_URI = uri;
_uri = uri;
reset(reader);

Stylesheet result = new Stylesheet(uri, origin);
Expand All @@ -82,7 +82,7 @@ public Stylesheet parseStylesheet(String uri, int origin, Reader reader)
public Ruleset parseDeclaration(int origin, String text) {
try {
// XXX Set this to something more reasonable
_URI = "style attribute";
_uri = "style attribute";
reset(new StringReader(text));

skip_whitespace();
Expand All @@ -103,7 +103,7 @@ public Ruleset parseDeclaration(int origin, String text) {
}

public PropertyValue parsePropertyValue(CSSName cssName, int origin, String expr) {
_URI = cssName + " property value";
_uri = cssName + " property value";
try {
reset(new StringReader(expr));
List<PropertyValue> values = expr(
Expand Down Expand Up @@ -311,7 +311,7 @@ private void import_rule(Stylesheet stylesheet) throws IOException {
t, new Token[] { Token.TK_STRING, Token.TK_URI }, getCurrentLine());
}

if (info.getMedia().size() == 0) {
if (info.getMedia().isEmpty()) {
info.addMedium("all");
}
stylesheet.addImportRule(info);
Expand Down Expand Up @@ -475,7 +475,6 @@ private void font_face(Stylesheet stylesheet) throws IOException {
// Prevent runaway threads with a max loop/counter
int maxLoops = 1024 * 1024; // 1M is too much, 1K is probably too...
int i = 0;
LOOP:
while (true) {
if (++i >= maxLoops)
throw new CSSParseException(t, Token.TK_RBRACE, getCurrentLine());
Expand All @@ -484,7 +483,7 @@ private void font_face(Stylesheet stylesheet) throws IOException {
if (t == Token.TK_RBRACE) {
next();
skip_whitespace();
break LOOP;
break;
} else {
declaration_list(ruleset, false, true, true);
}
Expand Down Expand Up @@ -535,14 +534,13 @@ private void page(Stylesheet stylesheet) throws IOException {
skip_whitespace();
t = next();
if (t == Token.TK_LBRACE) {
LOOP:
while (true) {
skip_whitespace();
t = la();
if (t == Token.TK_RBRACE) {
next();
skip_whitespace();
break LOOP;
break;
} else if (t == Token.TK_AT_RULE) {
margin(stylesheet, pageRule);
} else {
Expand Down Expand Up @@ -775,7 +773,7 @@ private void ruleset(RulesetContainer container) throws IOException {
t, new Token[] { Token.TK_COMMA, Token.TK_LBRACE }, getCurrentLine());
}

if (ruleset.getPropertyDeclarations().size() > 0) {
if (!ruleset.getPropertyDeclarations().isEmpty()) {
container.addContent(ruleset);
}
} catch (CSSParseException e) {
Expand Down Expand Up @@ -1213,7 +1211,7 @@ private void addPseudoElement(Token t, Selector selector) {
if (SUPPORTED_PSEUDO_ELEMENTS.contains(value)) {
selector.setPseudoElement(value);
} else {
throw new CSSParseException(value + " is not a recognized psuedo-element", getCurrentLine());
throw new CSSParseException(value + " is not a recognized pseudo-element", getCurrentLine());
}
}

Expand Down Expand Up @@ -1250,15 +1248,15 @@ private void pseudo(Selector selector) throws IOException {
private boolean checkCSSName(CSSName cssName, String propertyName) {
if (cssName == null) {
_errorHandler.error(
_URI,
_uri,
propertyName + " is an unrecognized CSS property at line "
+ getCurrentLine() + ". Ignoring declaration.");
return false;
}

if (! CSSName.isImplemented(cssName)) {
_errorHandler.error(
_URI,
_uri,
propertyName + " is not implemented at line "
+ getCurrentLine() + ". Ignoring declaration.");
return false;
Expand All @@ -1267,7 +1265,7 @@ private boolean checkCSSName(CSSName cssName, String propertyName) {
PropertyBuilder builder = CSSName.getPropertyBuilder(cssName);
if (builder == null) {
_errorHandler.error(
_URI,
_uri,
"(bug) No property builder defined for " + propertyName
+ " at line " + getCurrentLine() + ". Ignoring declaration.");
return false;
Expand Down Expand Up @@ -1828,7 +1826,7 @@ private Token la() throws IOException {
private void error(CSSParseException e, String what, boolean rethrowEOF) {
if (! e.isCallerNotified()) {
String message = e.getMessage() + " Skipping " + what + ".";
_errorHandler.error(_URI, message);
_errorHandler.error(_uri, message);
}
e.setCallerNotified(true);
if (e.isEOF() && rethrowEOF) {
Expand Down Expand Up @@ -1880,14 +1878,6 @@ public void reset(Reader r) {
_lexer.setyyline(0);
}

public CSSErrorHandler getErrorHandler() {
return _errorHandler;
}

public void setErrorHandler(CSSErrorHandler errorHandler) {
_errorHandler = errorHandler;
}

private String getRawTokenValue() {
return _lexer.yytext();
}
Expand Down Expand Up @@ -1928,16 +1918,16 @@ private String getTokenValue(Token t, boolean literal) {
String uriResult = processEscapes(ch, start, end+1);

// Relative URIs are resolved relative to CSS file, not XHTML file
if (isRelativeURI(uriResult) && _URI != null) {
int lastSlash = _URI.lastIndexOf('/');
if (isRelativeURI(uriResult) && _uri != null) {
int lastSlash = _uri.lastIndexOf('/');
if (lastSlash != -1) {
uriResult = _URI.substring(0, lastSlash+1) + uriResult;
uriResult = _uri.substring(0, lastSlash+1) + uriResult;
}
} else if (isServerRelativeURI(uriResult) && _URI != null) {
int uriOffset = _URI.indexOf("://") + 3;
int firstSlashAfterProtocol = _URI.substring(uriOffset).indexOf('/');
} else if (isServerRelativeURI(uriResult) && _uri != null) {
int uriOffset = _uri.indexOf("://") + 3;
int firstSlashAfterProtocol = _uri.substring(uriOffset).indexOf('/');
if (firstSlashAfterProtocol != -1) {
uriResult = _URI.substring(0, uriOffset + firstSlashAfterProtocol) + uriResult;
uriResult = _uri.substring(0, uriOffset + firstSlashAfterProtocol) + uriResult;
}
}

Expand All @@ -1962,15 +1952,15 @@ private String getTokenValue(Token t, boolean literal) {

private boolean isRelativeURI(String uri) {
try {
return uri.length() > 0 && (uri.charAt(0) != '/' && ! new URI(uri).isAbsolute());
return !uri.isEmpty() && (uri.charAt(0) != '/' && ! new URI(uri).isAbsolute());
} catch (URISyntaxException e) {
return false;
}
}

private boolean isServerRelativeURI(String uri) {
try {
return uri.length() > 0 && uri.charAt(0) == '/' && !new URI(uri).isAbsolute();
return !uri.isEmpty() && uri.charAt(0) == '/' && !new URI(uri).isAbsolute();
} catch (URISyntaxException e) {
return false;
}
Expand Down

0 comments on commit 8a1da8c

Please sign in to comment.