@Override public String getText() { if (currentNode == null) { return ""; } return StringResources.processStringResources(currentNode.getTextContent()); }
@Override public void onEnd(XMLStreamReader xml, XmlContext xmlContext) throws XMLStreamException { String s = buf.toString(); if (resType == ResType.CHAR_SEQUENCE) { s = StringResources.processStringResources(s); } else { s = s.trim(); } resourceTable.addResource(attrType, name, new TypedResource<>(s, resType, xmlContext)); } }
public String qualify(String value) { if (value == null) return null; if (AttributeResource.isResourceReference(value)) { return "@" + ResName.qualifyResourceName(value.trim().substring(1).replace("+", ""), packageName, "attr"); } else if (AttributeResource.isStyleReference(value)) { return "?" + ResName.qualifyResourceName(value.trim().substring(1), packageName, "attr"); } else { return StringResources.processStringResources(value); } }
@Test public void escape_shouldRemoveUnescapedDoubleQuotes() { Map<String, String> tests = new HashMap<>(); tests.put("a\\\"b", "a\"b"); tests.put("a\\\\\"b", "a\\b"); tests.put("a\\\\\\\"b", "a\\\"b"); tests.put("a\\\\\\\\\"b", "a\\\\b"); for (Map.Entry<String, String> t : tests.entrySet()) { assertThat(StringResources.processStringResources(t.getKey())).isEqualTo(t.getValue()); } }
@Test public void escape_shouldEscapeCodePoints() { Map<String, String> tests = new HashMap<>(); tests.put("\\u0031", "1"); tests.put("1\\u0032", "12"); tests.put("\\u00312", "12"); tests.put("1\\u00323", "123"); tests.put("\\u005A", "Z"); tests.put("\\u005a", "Z"); for (Map.Entry<String, String> t : tests.entrySet()) { assertThat(StringResources.processStringResources(t.getKey())).isEqualTo(t.getValue()); } }
@Test public void shouldCollapseInternalWhiteSpaces() { assertThat(StringResources.processStringResources("Whitespace in the middle")).isEqualTo("Whitespace in the middle"); assertThat(StringResources.processStringResources("Some\n\n\n\nNewlines")).isEqualTo("Some Newlines"); }
@Test public void shouldTrimWhitespace() { assertThat(StringResources.processStringResources(" ")).isEmpty(); assertThat(StringResources.processStringResources("Trailingwhitespace ")).isEqualTo("Trailingwhitespace"); assertThat(StringResources.processStringResources("Leadingwhitespace ")).isEqualTo("Leadingwhitespace"); }
@Test public void escape_shouldSupport() { Map<String, String> tests = new HashMap<>(); tests.put("\\\\", "\\"); tests.put("domain\\\\username", "domain\\username"); for (Map.Entry<String, String> t : tests.entrySet()) { assertThat(StringResources.processStringResources(t.getKey())).isEqualTo(t.getValue()); } }
@Test public void testInvalidCodePoints() { List<String> tests = new ArrayList<>(); tests.add("\\u"); tests.add("\\u0"); tests.add("\\u00"); tests.add("\\u004"); tests.add("\\uzzzz"); tests.add("\\u0zzz"); tests.add("\\u00zz"); tests.add("\\u000z"); for (String t : tests) { try { StringResources.processStringResources(t); fail("expected IllegalArgumentException with test '" + t + "'"); } catch (IllegalArgumentException expected) { // cool } } } }
@Test public void escape_shouldIgnoreUnsupportedEscapeCodes() { assertThat(StringResources.processStringResources("\\ \\a\\b\\c\\d\\e\\ ")).isEqualTo(""); }
@Override public String getText() { if (currentNode == null) { return ""; } return StringResources.processStringResources(currentNode.getTextContent()); }
@Override public void onEnd(XMLStreamReader xml, XmlContext xmlContext) throws XMLStreamException { String s = buf.toString(); if (resType == ResType.CHAR_SEQUENCE) { s = StringResources.processStringResources(s); } else { s = s.trim(); } resourceTable.addResource(attrType, name, new TypedResource<>(s, resType, xmlContext)); } }
public String qualify(String value) { if (value == null) return null; if (AttributeResource.isResourceReference(value)) { return "@" + ResName.qualifyResourceName(value.trim().substring(1).replace("+", ""), packageName, "attr"); } else if (AttributeResource.isStyleReference(value)) { return "?" + ResName.qualifyResourceName(value.trim().substring(1), packageName, "attr"); } else { return StringResources.processStringResources(value); } }
@Override public void onEnd(XMLStreamReader xml, XmlContext xmlContext) throws XMLStreamException { String s = buf.toString(); if (resType == ResType.CHAR_SEQUENCE) { s = StringResources.processStringResources(s); } resourceTable.addResource(attrType, name, new TypedResource<>(s, resType, xmlContext)); } }