EvalHelper { public static String normalizeVariableName(String name) { if (name == null || name.isEmpty()) { return name; } int firstValid = 0, size = name.length(); for (; firstValid < size; firstValid++) { if (isValidChar(name.charAt(firstValid))) { break; } } if (firstValid == size) { return ""; } int lastValid = 0, trailing = 0; boolean inWhitespace = false; for (int i = firstValid; i < size; i++) { if (isValidChar(name.charAt(i))) { lastValid = i + 1; inWhitespace = false; } else { if (inWhitespace) { break; } inWhitespace = true; if (name.charAt(i) != ' ') { break; } } } for (int i = lastValid; i < size && !isValidChar(name.charAt(i)); i++) { trailing++; } if (lastValid + trailing == size) { return firstValid != 0 || trailing != 0 ? name.substring(firstValid, lastValid) : name; } int pos = 0; char[] target = new char[size-firstValid]; for (int i = firstValid; i < lastValid; i++) { target[pos++] = name.charAt(i); } for (int i = lastValid + 1; i < size; i++) { char c = name.charAt(i); if (isValidChar(c)) { if (inWhitespace) { target[pos++] = ' '; } target[pos++] = c; inWhitespace = false; } else { inWhitespace = true; } } return new String(target, 0, pos); }  static String normalizeVariableName(String name); static BigDecimal getBigDecimalOrNull(Object value); static Object coerceNumber(Object value); static Boolean getBooleanOrNull(Object value); static String unescapeString(String text); static PropertyValueResult getDefinedValue(final Object current, final String property); static Object getValue(final Object current, final String property); static Method getGenericAccessor(Class<?> clazz, String field); static void clearGenericAccessorCache(); static Method getAccessor(Class<?> clazz, String field); static Optional<String> propertyFromAccessor(Method accessor); static String ucFirst(final String name); static String lcFirst(final String name); static Boolean compare(Object left, Object right, EvaluationContext ctx, BiPredicate<Comparable, Comparable> op); static Boolean isEqual(Object left, Object right, EvaluationContext ctx ); static Boolean isEqualDateTimeInSemanticD(TemporalAccessor left, TemporalAccessor right); static Boolean isEqualTimeInSemanticD(TemporalAccessor left, TemporalAccessor right); static final Logger LOG; }
@Test public void testNormalizeSpace() { assertNull(normalizeVariableName(null)); assertEquals("", normalizeVariableName("")); assertEquals("", normalizeVariableName(" ")); assertEquals("", normalizeVariableName("\t")); assertEquals("", normalizeVariableName("\n")); assertEquals("", normalizeVariableName("\u0009")); assertEquals("", normalizeVariableName("\u000B")); assertEquals("", normalizeVariableName("\u000C")); assertEquals("", normalizeVariableName("\u001C")); assertEquals("", normalizeVariableName("\u001D")); assertEquals("", normalizeVariableName("\u001E")); assertEquals("", normalizeVariableName("\u001F")); assertEquals("", normalizeVariableName("\f")); assertEquals("", normalizeVariableName("\r")); assertEquals("a", normalizeVariableName(" a ")); assertEquals("a b c", normalizeVariableName(" a b c ")); assertEquals("a b c", normalizeVariableName("a\t\f\r b\u000B c\n")); assertEquals("a b c", normalizeVariableName("a\t\f\r \u00A0\u00A0b\u000B c\n")); assertEquals("b", normalizeVariableName(" b")); assertEquals("b", normalizeVariableName("b ")); assertEquals("ab c", normalizeVariableName("ab c ")); assertEquals("a b", normalizeVariableName("a\u00A0b")); }