From afaf9faff3781744d05e40b02ffb406c319b9172 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 3 Jul 2017 22:19:42 +0200 Subject: [PATCH] Fixed color define parsing on ubuntu (color defines were scattered throughout the CSS) --- src/dorkbox/systemTray/util/CssParser.java | 71 ++++++++++++---------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/src/dorkbox/systemTray/util/CssParser.java b/src/dorkbox/systemTray/util/CssParser.java index 3f625a2..1fc8c06 100644 --- a/src/dorkbox/systemTray/util/CssParser.java +++ b/src/dorkbox/systemTray/util/CssParser.java @@ -599,43 +599,45 @@ class CssParser { */ private static List getColorDefinition(final String css) { - // have to setup the "define color" section - String colorDefine = "@define-color"; - int start = css.indexOf(colorDefine); - int end = css.lastIndexOf(colorDefine); - end = css.lastIndexOf(";", end) + 1; // include the ; - String colorDefines = css.substring(start, end); - - if (DEBUG_VERBOSE) { - System.err.println("+++++++++++++++++++++++"); - System.err.println(colorDefines); - System.err.println("+++++++++++++++++++++++"); - } - - // since it's a color definition, it will start a very specific way. This will recursively get the defined colors. - String[] split = colorDefines.split(colorDefine); - List defines = new ArrayList(split.length); + List defines = new ArrayList(); + { + // have to setup the "define color" section + String colorDefine = "@define-color"; + int length = colorDefine.length() + 1; - for (String s : split) { - s = s.trim(); - int endDefine = s.indexOf(" "); - if (endDefine > -1) { - String label = s.substring(0, endDefine); - String value = s.substring(endDefine + 1); + int start = 0; + int mid = 0; + int end = 0; - // remove the trailing ; - int endOfValue = value.length() - 1; - if (value.charAt(endOfValue) == ';') { - value = value.substring(0, endOfValue); + while (start < css.length()) { + start = css.indexOf(colorDefine, start); + if (start == -1) { + break; } - Entry attribute = new Entry(label, value); - defines.add(attribute); + start += length; + end = css.indexOf(';', start) + 1; // include the ; + mid = css.indexOf(' ', start); + + if (mid > -1) { + String label = css.substring(start, mid); + String value = css.substring(mid + 1, end); + + // remove the trailing ; + int endOfValue = value.length() - 1; + if (value.charAt(endOfValue) == ';') { + value = value.substring(0, endOfValue); + } + + Entry attribute = new Entry(label, value); + defines.add(attribute); + } + + start = end + 1; } } - // now to recursively figure out the color definitions boolean allClean = false; while (!allClean) { @@ -655,12 +657,19 @@ class CssParser { } } - String replacement = d.value.substring(i+1, lastLetter); + String replacement = value.substring(i+1, lastLetter); // the target value for replacement will ALWAYS be earlier in the list. for (Entry d2 : defines) { if (d2.key.equals(replacement)) { - d.value = value.replace("@" + replacement, d2.value); + int length = d2.value.length(); + + // string.replace() goes bonkers on the heap... This keeps it under control + StringBuilder builder = new StringBuilder(value); + builder.insert(i, d2.value); + builder.delete(i + length, lastLetter + length); + + d.value = builder.toString(); break; } }