CssUtils { public static List<String> splitStringWithComma(final String value) { if (value == null) { return new ArrayList<>(); } final List<String> resultList = new ArrayList<>(); int lastComma = 0; int notClosedBrackets = 0; for (int i = 0; i < value.length(); ++i) { if (value.charAt(i) == ',' && notClosedBrackets == 0) { resultList.add(value.substring(lastComma, i)); lastComma = i + 1; } if (value.charAt(i) == '(') { ++notClosedBrackets; } if (value.charAt(i) == ')') { --notClosedBrackets; notClosedBrackets = Math.max(notClosedBrackets, 0); } } final String lastToken = value.substring(lastComma); if (!lastToken.isEmpty()) { resultList.add(lastToken); } return resultList; } private  CssUtils(); static List<String> splitStringWithComma(final String value); static BlendMode parseBlendMode(String cssValue); static List<List<String>> extractShorthandProperties(String str); static String normalizeCssProperty(String str); static String removeDoubleSpacesAndTrim(String str); static Integer parseInteger(String str); static Float parseFloat(String str); static Double parseDouble(String str); static float parseAngle(String angle, String defaultMetric); static float parseAngle(String angle); static int[] parseAspectRatio(String str); static float parseAbsoluteLength(String length, String defaultMetric); static float parseAbsoluteLength(String length); static float parseRelativeValue(final String relativeValue, final float baseValue); static UnitValue parseLengthValueToPt(final String value, final float emValue, final float remValue); static boolean isValidNumericValue(final String value); static float parseAbsoluteFontSize(String fontSizeValue, String defaultMetric); static float parseAbsoluteFontSize(String fontSizeValue); static float parseRelativeFontSize(final String relativeFontSizeValue, final float baseValue); static UnitValue[] parseSpecificCornerBorderRadius(String specificBorderRadius, final float emValue, final float remValue); static float parseResolution(String resolutionStr); static int determinePositionBetweenValueAndUnit(String string); static boolean isMetricValue(final String value); static boolean isAngleValue(final String value); static boolean isRelativeValue(final String value); static boolean isFontRelativeValue(final String value); static boolean isPercentageValue(final String value); static boolean isRemValue(final String value); static boolean isEmValue(final String value); static boolean isExValue(final String value); static boolean isNumericValue(final String value); static String extractUrl(final String url); static boolean isBase64Data(String data); static int findNextUnescapedChar(String source, char ch, int startIndex); static boolean isColorProperty(String value); static boolean compareFloats(double d1, double d2); static boolean compareFloats(float f1, float f2); static float[] parseRgbaColor(String colorValue); static Range parseUnicodeRange(String unicodeRange); static float convertPtsToPx(float pts); static double convertPtsToPx(double pts); static float convertPxToPts(float px); static double convertPxToPts(double px); static boolean isStyleSheetLink(IElementNode headChildElement); static boolean isInitialOrInheritOrUnset(String value);  }
@Test public void splitStringWithCommaTest() { Assert.assertEquals(new ArrayList<String>(), CssUtils.splitStringWithComma(null)); Assert.assertEquals(Arrays.asList("value1", "value2", "value3"), CssUtils.splitStringWithComma("value1,value2,value3")); Assert.assertEquals(Arrays.asList("value1", " value2", " value3"), CssUtils.splitStringWithComma("value1, value2, value3")); Assert.assertEquals(Arrays.asList("value1", "(value,with,comma)", "value3"), CssUtils.splitStringWithComma("value1,(value,with,comma),value3")); Assert.assertEquals(Arrays.asList("value1", "(val(ue,with,comma),value3"), CssUtils.splitStringWithComma("value1,(val(ue,with,comma),value3")); Assert.assertEquals(Arrays.asList("value1", "(value,with)", "comma)", "value3"), CssUtils.splitStringWithComma("value1,(value,with),comma),value3")); Assert.assertEquals(Arrays.asList("value1", "( v2,v3)", "(v4, v5)", "value3"), CssUtils.splitStringWithComma("value1,( v2,v3),(v4, v5),value3")); Assert.assertEquals(Arrays.asList("v.al*ue1\"", "( v2,v3)", "\"(v4,v5;);", "value3"), CssUtils.splitStringWithComma("v.al*ue1\",( v2,v3),\"(v4,v5;);,value3")); }