1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2025-06-13 12:54:14 +00:00

Css: Change java.lang.String.charAt to JsString_.charAt [#741]

This commit is contained in:
gnosygnu 2020-06-08 08:58:32 -04:00
parent 27756f8056
commit 1103674d88
2 changed files with 15 additions and 5 deletions

View File

@ -107,7 +107,7 @@ public class XoCssMin {
// ! in the first position of the comment means preserve // ! in the first position of the comment means preserve
// so push to the preserved tokens keeping the ! // so push to the preserved tokens keeping the !
if (token.charAt(0) == '!') { if (JsString_.charAtEq(token, 0, '!')) {
preservedTokens.add(token); preservedTokens.add(token);
css = css.replace(placeholder, "___YUICSSMIN_PRESERVED_TOKEN_" + (preservedTokens.size() - 1) + "___"); css = css.replace(placeholder, "___YUICSSMIN_PRESERVED_TOKEN_" + (preservedTokens.size() - 1) + "___");
continue; continue;
@ -115,7 +115,7 @@ public class XoCssMin {
// \ in the last position looks like hack for Mac/IE5 // \ in the last position looks like hack for Mac/IE5
// shorten that to /*\*/ and the next one to /**/ // shorten that to /*\*/ and the next one to /**/
if (token.charAt(token.length() - 1) == '\\') { if (JsString_.charAtEq(token, token.length() - 1, '\\')) {
preservedTokens.add("\\"); preservedTokens.add("\\");
css = css.replace(placeholder, "___YUICSSMIN_PRESERVED_TOKEN_" + (preservedTokens.size() - 1) + "___"); css = css.replace(placeholder, "___YUICSSMIN_PRESERVED_TOKEN_" + (preservedTokens.size() - 1) + "___");
i = i + 1; // attn: advancing the loop i = i + 1; // attn: advancing the loop
@ -129,7 +129,7 @@ public class XoCssMin {
if (token.length() == 0) { if (token.length() == 0) {
startIndex = css.indexOf(placeholder); startIndex = css.indexOf(placeholder);
if (startIndex > 2) { if (startIndex > 2) {
if (css.charAt(startIndex - 3) == '>') { if (JsString_.charAtEq(css, startIndex - 3, '>')) {
preservedTokens.add(""); preservedTokens.add("");
css = css.replace(placeholder, "___YUICSSMIN_PRESERVED_TOKEN_" + (preservedTokens.size() - 1) + "___"); css = css.replace(placeholder, "___YUICSSMIN_PRESERVED_TOKEN_" + (preservedTokens.size() - 1) + "___");
} }
@ -267,7 +267,7 @@ public class XoCssMin {
// XO: desb42 comments this // XO: desb42 comments this
while (i < css.length()) { while (i < css.length()) {
i = i + 1; i = i + 1;
if (css.charAt(i - 1) == '}' && i - startIndex > linebreakpos) { if (JsString_.charAtEq(css, i - 1, '}') && i - startIndex > linebreakpos) {
css = JsString_.slice(css, 0, i) + '\n' + JsString_.slice(css, i); css = JsString_.slice(css, 0, i) + '\n' + JsString_.slice(css, i);
startIndex = i; startIndex = i;
} }
@ -326,7 +326,7 @@ public class XoCssMin {
endIndex = css.indexOf(terminator, endIndex + 1); endIndex = css.indexOf(terminator, endIndex + 1);
// endIndex == 0 doesn't really apply here // endIndex == 0 doesn't really apply here
if ((endIndex > 0) && (css.charAt(endIndex - 1) != '\\')) {// XO:found terminator; check it isn't escaped; EX: `\'` if ((endIndex > 0) && JsString_.charAtEqNot(css, endIndex - 1, '\\')) {// XO:found terminator; check it isn't escaped; EX: `\'`
foundTerminator = true; foundTerminator = true;
if (!(")".equals(terminator))) {// XO:cur terminator is either `'` or `"`; grab next `)` if (!(")".equals(terminator))) {// XO:cur terminator is either `'` or `"`; grab next `)`
endIndex = css.indexOf(")", endIndex); endIndex = css.indexOf(")", endIndex);

View File

@ -61,6 +61,16 @@ public class XoCssMinTest {
) )
); );
} }
@Test public void commentsEmpty() {// PURPOSE:handle empty comments; ISSUE#:741 DATE:2020-06-08
tstr.Test("collectComments.empty"
, "a /**/ b"
, "a b" // NOTE: `\s` instead of `\s\s` b/c of "Normalize all whitespace strings to single spaces"
, new TestAssert.Grp("collectComments"
, new TestAssert.ListEq("comments", "")
, new TestAssert.StringEq("css", "a /*___YUICSSMIN_PRESERVE_CANDIDATE_COMMENT_0___*/ b")
)
);
}
@Test public void rgb() { @Test public void rgb() {
tstr.Test("rgb.basic" ,"rgb (128,128,128)", "#808080"); tstr.Test("rgb.basic" ,"rgb (128,128,128)", "#808080");
tstr.Test("rgb.casing" ,"RgB (128,128,128)", "#808080"); tstr.Test("rgb.casing" ,"RgB (128,128,128)", "#808080");