mirror of
https://github.com/shekhargulati/strman-java.git
synced 2026-10-20 14:34:04 +00:00
Added support for decDecode
This commit is contained in:
@@ -345,7 +345,21 @@ public abstract class Strman {
|
||||
return value.chars().mapToObj(ch -> leftPad(Integer.toBinaryString(ch), "0", 16)).collect(joining());
|
||||
}
|
||||
|
||||
public static String leftPad(String value, String pad, int length) {
|
||||
/**
|
||||
* Convert decimal unicode (16 digits) string to string chars
|
||||
*
|
||||
* @param value The value to decode
|
||||
* @return decoded String
|
||||
*/
|
||||
public static String decDecode(final String value) {
|
||||
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
|
||||
return Arrays
|
||||
.stream(value.split("(?<=\\G.{5})"))
|
||||
.map(data -> String.valueOf(Character.toChars(Integer.parseInt(data))))
|
||||
.collect(joining());
|
||||
}
|
||||
|
||||
public static String leftPad(final String value, final String pad, final int length) {
|
||||
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
|
||||
if (value.length() >= length) {
|
||||
return value;
|
||||
|
||||
@@ -283,4 +283,12 @@ public class StrmanTest {
|
||||
assertThat(binEncode("Á"), equalTo("0000000011000001"));
|
||||
assertThat(binEncode("AA"), equalTo("00000000010000010000000001000001"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decDecode_shouldDecodeDecimalStringToString() throws Exception {
|
||||
assertThat(decDecode("28450"),equalTo("漢"));
|
||||
assertThat(decDecode("00065"),equalTo("A"));
|
||||
assertThat(decDecode("00193"),equalTo("Á"));
|
||||
assertThat(decDecode("0006500065"),equalTo("AA"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user