Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2025 Jannis Weis
* Copyright (c) 2025-2026 Jannis Weis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
Expand Down Expand Up @@ -101,25 +101,31 @@ public static float parseFloat(@Nullable String value, float fallback) {
if (value == null || value.isEmpty()) return fallback;
List<String> list = new ArrayList<>();
int max = value.length();
boolean splitOnWhitespace = splitter.splitOnWhitespace();
int start = 0;
int i = 0;
boolean inWhiteSpace = false;
boolean lastSplitWasWhiteSpace = false;
for (; i < max; i++) {
char c = value.charAt(i);
if (Character.isWhitespace(c)) {
if (!inWhiteSpace && splitter.splitOnWhitespace() && i - start > 0) {
if (!inWhiteSpace && splitOnWhitespace && i - start > 0) {
list.add(value.substring(start, i));
start = i + 1;
lastSplitWasWhiteSpace = true;
}
inWhiteSpace = true;
continue;
}
inWhiteSpace = false;
ListSplitter.SplitResult result = splitter.testChar(c, i - start);
if (result.shouldSplit()) {
list.add(value.substring(start, i));
if (!(lastSplitWasWhiteSpace && i == start)) list.add(value.substring(start, i));
start = result.shouldIncludeChar() ? i : i + 1;
lastSplitWasWhiteSpace = false;
continue;
}
lastSplitWasWhiteSpace = false;
}
if (i - start > 0) list.add(value.substring(start, i));
return list.toArray(new String[0]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2021-2025 Jannis Weis
* Copyright (c) 2021-2026 Jannis Weis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
Expand All @@ -27,6 +27,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.github.weisj.jsvg.attributes.transform.TransformPart;
import com.github.weisj.jsvg.paint.impl.DefaultPaintParser;
import com.github.weisj.jsvg.parser.impl.AttributeParser;
import com.github.weisj.jsvg.parser.impl.SeparatorMode;
Expand Down Expand Up @@ -91,4 +92,22 @@ private <T> String appendToList(T[] arr, Random r, boolean requireComma) {
}
return builder.toString();
}

@Test
void testTransformScaleAllowsCommaAndWhitespace() {
TransformPart part = parser.parseTransformPart(TransformPart.TransformType.SCALE, "-1, 1");
Assertions.assertNotNull(part);
}

@Test
void testTransformScaleAllowsMixedCommaAndWhitespace() {
TransformPart part = parser.parseTransformPart(TransformPart.TransformType.SCALE, "-1 , 1");
Assertions.assertNotNull(part);
}

@Test
void testTransformCommaOnlyKeepsEmptyEntryBetweenCommas() {
String[] values = parser.parseStringList("1,,1", SeparatorMode.COMMA_ONLY);
Assertions.assertArrayEquals(new String[] {"1", "", "1"}, values);
}
}