X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=svjatoslav_commons.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fcommons%2Fstring%2FString2.java;h=4c1627f6aee3bd63cfe37f52639f3dc38bfcfb85;hp=504c41d876a2ff24c52e18e17a27d4a63a2195ce;hb=96b417fd35bb6aae9e5e57af94cecb44aeeb9c22;hpb=1195d9ce07d2e4f2d4c2a7d67dc0bd657556e2c7 diff --git a/src/main/java/eu/svjatoslav/commons/string/String2.java b/src/main/java/eu/svjatoslav/commons/string/String2.java index 504c41d..4c1627f 100755 --- a/src/main/java/eu/svjatoslav/commons/string/String2.java +++ b/src/main/java/eu/svjatoslav/commons/string/String2.java @@ -16,13 +16,19 @@ public class String2 { private final List chars; - public String2(final String value) { + public String2(String value) { + if (value == null) + value = ""; + chars = new ArrayList<>(value.length()); for (final Character c : value.toCharArray()) chars.add(c); } public String2 addPrefix(final String prefix) { + if (prefix == null) + return this; + int i = 0; for (final char c : prefix.toCharArray()) chars.add(i++, c); @@ -31,6 +37,9 @@ public class String2 { } public String2 addSuffix(final String suffix) { + if (suffix == null) + return this; + for (final char c : suffix.toCharArray()) chars.add(c); @@ -56,6 +65,9 @@ public class String2 { } public String2 trimPrefixIfExists(String prefix){ + if (prefix == null) + return this; + if (hasPrefix(prefix)) trimPrefix(prefix.length());