mirror of
https://github.com/octoleo/plantuml.git
synced 2024-11-20 04:00:53 +00:00
Merge pull request #737 from matthew16550/StringUtils.isEmpty
Change StringUtils.isEmpty() & isNotEmpty() to avoid creating new strings
This commit is contained in:
commit
41f464fc23
@ -119,16 +119,22 @@ public class StringUtils {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isNotEmpty(String input) {
|
||||
return input != null && trin(input).length() > 0;
|
||||
public static boolean isNotEmpty(CharSequence s) {
|
||||
return !isEmpty(s);
|
||||
}
|
||||
|
||||
public static boolean isNotEmpty(List<? extends CharSequence> input) {
|
||||
return input != null && input.size() > 0;
|
||||
}
|
||||
|
||||
public static boolean isEmpty(String input) {
|
||||
return input == null || trin(input).length() == 0;
|
||||
public static boolean isEmpty(CharSequence s) {
|
||||
if (s == null) return true;
|
||||
final int length = s.length();
|
||||
if (length == 0) return true;
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (!isSpaceOrTabOrNull(s.charAt(i))) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String manageHtml(String s) {
|
||||
|
29
test/net/sourceforge/plantuml/StringUtilsTest.java
Normal file
29
test/net/sourceforge/plantuml/StringUtilsTest.java
Normal file
@ -0,0 +1,29 @@
|
||||
package net.sourceforge.plantuml;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
class StringUtilsTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource(nullValues = "null", value = {
|
||||
" null , true ",
|
||||
" '' , true ",
|
||||
" ' ' , true ",
|
||||
" '\0' , true ",
|
||||
" '\n' , true ",
|
||||
" '\r' , true ",
|
||||
" '\t' , true ",
|
||||
" 'x' , false ",
|
||||
" ' x ' , false ",
|
||||
})
|
||||
void test_isEmpty_isNotEmpty(String s, boolean empty) {
|
||||
assertThat(StringUtils.isEmpty(s))
|
||||
.isEqualTo(empty);
|
||||
|
||||
assertThat(StringUtils.isNotEmpty(s))
|
||||
.isNotEqualTo(empty);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user