Fixed color define parsing on ubuntu (color defines were scattered

throughout the CSS)
This commit is contained in:
nathan 2017-07-03 22:19:42 +02:00
parent 6be7445a77
commit afaf9faff3

View File

@ -599,30 +599,30 @@ class CssParser {
*/ */
private static private static
List<Entry> getColorDefinition(final String css) { List<Entry> getColorDefinition(final String css) {
// since it's a color definition, it will start a very specific way. This will recursively get the defined colors.
List<Entry> defines = new ArrayList<Entry>();
{
// have to setup the "define color" section // have to setup the "define color" section
String colorDefine = "@define-color"; String colorDefine = "@define-color";
int start = css.indexOf(colorDefine); int length = colorDefine.length() + 1;
int end = css.lastIndexOf(colorDefine);
end = css.lastIndexOf(";", end) + 1; // include the ;
String colorDefines = css.substring(start, end);
if (DEBUG_VERBOSE) { int start = 0;
System.err.println("+++++++++++++++++++++++"); int mid = 0;
System.err.println(colorDefines); int end = 0;
System.err.println("+++++++++++++++++++++++");
while (start < css.length()) {
start = css.indexOf(colorDefine, start);
if (start == -1) {
break;
} }
start += length;
end = css.indexOf(';', start) + 1; // include the ;
mid = css.indexOf(' ', start);
// since it's a color definition, it will start a very specific way. This will recursively get the defined colors. if (mid > -1) {
String[] split = colorDefines.split(colorDefine); String label = css.substring(start, mid);
List<Entry> defines = new ArrayList<Entry>(split.length); String value = css.substring(mid + 1, end);
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);
// remove the trailing ; // remove the trailing ;
int endOfValue = value.length() - 1; int endOfValue = value.length() - 1;
@ -633,8 +633,10 @@ class CssParser {
Entry attribute = new Entry(label, value); Entry attribute = new Entry(label, value);
defines.add(attribute); defines.add(attribute);
} }
}
start = end + 1;
}
}
// now to recursively figure out the color definitions // now to recursively figure out the color definitions
boolean allClean = false; boolean allClean = false;
@ -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. // the target value for replacement will ALWAYS be earlier in the list.
for (Entry d2 : defines) { for (Entry d2 : defines) {
if (d2.key.equals(replacement)) { 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; break;
} }
} }