mirror of
https://github.com/shekhargulati/strman-java.git
synced 2026-11-21 21:03:44 +00:00
Fixed #35. Added support for surround function
This commit is contained in:
@@ -961,6 +961,22 @@ public abstract class Strman {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Surrounds a 'value' with the given 'prefix' and 'suffix'.
|
||||||
|
*
|
||||||
|
* @param value The input String
|
||||||
|
* @param prefix prefix. If suffix is null then prefix is used
|
||||||
|
* @param suffix suffix
|
||||||
|
* @return The String with surround substrs!
|
||||||
|
*/
|
||||||
|
public static String surround(final String value, final String prefix, final String suffix) {
|
||||||
|
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
|
||||||
|
String _prefix = Optional.ofNullable(prefix).orElse("");
|
||||||
|
return append(_prefix, value, Optional.ofNullable(suffix).orElse(_prefix));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String decode(final String value, final int digits, final int radix) {
|
public static String decode(final String value, final int digits, final int radix) {
|
||||||
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
|
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
|
||||||
return Arrays
|
return Arrays
|
||||||
|
|||||||
@@ -711,6 +711,15 @@ public class StrmanTest {
|
|||||||
@Test
|
@Test
|
||||||
public void transliterate_shouldTransliterateTheText() throws Exception {
|
public void transliterate_shouldTransliterateTheText() throws Exception {
|
||||||
assertThat(transliterate("fóõ bár"), equalTo("foo bar"));
|
assertThat(transliterate("fóõ bár"), equalTo("foo bar"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void surround_shouldSurrondStringWithPrefixAndSuffix() throws Exception {
|
||||||
|
assertThat(surround("foo", "bar", null), equalTo("barfoobar"));
|
||||||
|
assertThat(surround("shekhar", "***", null), equalTo("***shekhar***"));
|
||||||
|
assertThat(surround("", ">", null), equalTo(">>"));
|
||||||
|
assertThat(surround("bar", "", null), equalTo("bar"));
|
||||||
|
assertThat(surround("f", null, null), equalTo("f"));
|
||||||
|
assertThat(surround("div", "<", ">"), equalTo("<div>"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user