mirror of
https://github.com/shekhargulati/strman-java.git
synced 2026-10-04 18:13:55 +00:00
Resolved#71
This commit is contained in:
@@ -1164,6 +1164,37 @@ public abstract class Strman {
|
||||
return head(input).toLowerCase() + tail(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies whether String is enclosed by encloser
|
||||
*
|
||||
* @param input The input String
|
||||
* @param encloser String which encloses input String
|
||||
* @return true if enclosed false otherwise
|
||||
*/
|
||||
public static boolean isEnclosedBetween(final String input, final String encloser) {
|
||||
return isEnclosedBetween(input, encloser, encloser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies whether String is enclosed by encloser
|
||||
*
|
||||
* @param input The input String
|
||||
* @param leftEncloser String which encloses input String
|
||||
* @return true if enclosed false otherwise
|
||||
*/
|
||||
public static boolean isEnclosedBetween(final String input, final String leftEncloser, String rightEncloser) {
|
||||
if (input == null) {
|
||||
throw new IllegalArgumentException("input can't be null");
|
||||
}
|
||||
if (leftEncloser == null) {
|
||||
throw new IllegalArgumentException("leftEncloser can't be null");
|
||||
}
|
||||
if (rightEncloser == null) {
|
||||
throw new IllegalArgumentException("rightEncloser can't be null");
|
||||
}
|
||||
return input.startsWith(leftEncloser) && input.endsWith(rightEncloser);
|
||||
}
|
||||
|
||||
private static void validate(String value, Predicate<String> predicate, final Supplier<String> supplier) {
|
||||
if (predicate.test(value)) {
|
||||
throw new IllegalArgumentException(supplier.get());
|
||||
|
||||
@@ -925,8 +925,21 @@ public class StrmanTest {
|
||||
|
||||
@Test
|
||||
public void lowerFirst_shouldLowercasedFirstCharacterOfString() throws Exception {
|
||||
assertThat(lowerFirst("FRED"),is(equalTo("fRED")));
|
||||
assertThat(lowerFirst("fred"),is(equalTo("fred")));
|
||||
assertThat(lowerFirst("Fred"),is(equalTo("fred")));
|
||||
assertThat(lowerFirst("FRED"), is(equalTo("fRED")));
|
||||
assertThat(lowerFirst("fred"), is(equalTo("fred")));
|
||||
assertThat(lowerFirst("Fred"), is(equalTo("fred")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isEnclosedBetween_shouldChekcWhetherStringIsEnclosed() throws Exception {
|
||||
assertThat(isEnclosedBetween("{{shekhar}}", "{{", "}}"), is(true));
|
||||
assertThat(isEnclosedBetween("shekhar", "{{", "}}"), is(false));
|
||||
assertThat(isEnclosedBetween("*shekhar*", "*"), is(true));
|
||||
assertThat(isEnclosedBetween("shekhar", "*"), is(false));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void isEnclosedBetween_shouldThrowIllegalArgumentExceptionWhenEncloserIsNull() throws Exception {
|
||||
assertThat(isEnclosedBetween("shekhar", null), is(false));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user