Fixed #2. Added support for htmlDecode function

This commit is contained in:
Shekhar Gulati
2016-05-22 16:04:27 +05:30
parent 8fbdbd4e9e
commit 5158ca6b17
3 changed files with 2264 additions and 0 deletions
File diff suppressed because it is too large Load Diff
+12
View File
@@ -885,6 +885,18 @@ public abstract class Strman {
return append(value.substring(0, length - filler.length()), filler);
}
/**
* Converts all HTML entities to applicable characters.
*
* @param encodedHtml The encoded HTML
* @return The decoded HTML
*/
public static String htmlDecode(final String encodedHtml) {
validate(encodedHtml, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
String[] entities = encodedHtml.split("&\\W+;");
return Arrays.stream(entities).map(e -> HtmlEntities.decodedEntities.get(e)).collect(joining());
}
public static String decode(final String value, final int digits, final int radix) {
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
return Arrays
+8
View File
@@ -646,4 +646,12 @@ public class StrmanTest {
assertThat(truncate("A Javascript string manipulation library.", 15, "..."), equalTo("A Javascript..."));
assertThat(truncate("A Javascript string manipulation library.", 14, "..."), equalTo("A Javascrip..."));
}
@Test
public void htmlDecode_shouldDecodeToHtml() throws Exception {
assertThat(htmlDecode("á"), equalTo("\u00E1"));
assertThat(htmlDecode("Ш"), equalTo("Ш"));
assertThat(htmlDecode("Ж"), equalTo("Ж"));
assertThat(htmlDecode("┐"), equalTo("┐"));
}
}