mirror of
https://github.com/shekhargulati/strman-java.git
synced 2026-10-20 06:24:05 +00:00
Added support for decEncode
This commit is contained in:
@@ -346,7 +346,7 @@ public abstract class Strman {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert decimal unicode (16 digits) string to string chars
|
||||
* Convert decimal unicode (5 digits) string to string chars
|
||||
*
|
||||
* @param value The value to decode
|
||||
* @return decoded String
|
||||
@@ -359,6 +359,17 @@ public abstract class Strman {
|
||||
.collect(joining());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert string chars to decimal unicode (5 digits)
|
||||
*
|
||||
* @param value The value to encode
|
||||
* @return Encoded value
|
||||
*/
|
||||
public static String decEncode(final String value) {
|
||||
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
|
||||
return value.chars().mapToObj(ch -> leftPad(Integer.toString(ch), "0", 5)).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) {
|
||||
|
||||
@@ -286,9 +286,18 @@ public class StrmanTest {
|
||||
|
||||
@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"));
|
||||
assertThat(decDecode("28450"), equalTo("漢"));
|
||||
assertThat(decDecode("00065"), equalTo("A"));
|
||||
assertThat(decDecode("00193"), equalTo("Á"));
|
||||
assertThat(decDecode("0006500065"), equalTo("AA"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decEncode_shouldEncodeStringToDecimal() throws Exception {
|
||||
assertThat(decEncode("漢"), equalTo("28450"));
|
||||
assertThat(decEncode("A"), equalTo("00065"));
|
||||
assertThat(decEncode("Á"), equalTo("00193"));
|
||||
assertThat(decEncode("AA"), equalTo("0006500065"));
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user