mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-29 15:32:06 +01:00
Add StringUtils.deleteXmlWhitespace(String)
This commit is contained in:
parent
3a0356488d
commit
1bc8a22b28
2 changed files with 19 additions and 0 deletions
|
@ -23,6 +23,7 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A collection of utility methods for String objects.
|
* A collection of utility methods for String objects.
|
||||||
|
@ -541,4 +542,10 @@ public class StringUtils {
|
||||||
}
|
}
|
||||||
return cs.toString();
|
return cs.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final Pattern XMLWHITESPACE = Pattern.compile("[\t\n\r ]");
|
||||||
|
|
||||||
|
public static String deleteXmlWhitespace(String string) {
|
||||||
|
return XMLWHITESPACE.matcher(string).replaceAll("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,4 +109,16 @@ public class StringUtilsTest {
|
||||||
String result = StringUtils.randomString(0);
|
String result = StringUtils.randomString(0);
|
||||||
assertEquals("", result);
|
assertEquals("", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testeDeleteXmlWhitespace() {
|
||||||
|
String noWhitespace = StringUtils.deleteXmlWhitespace(" foo\nbar ");
|
||||||
|
assertEquals("foobar", noWhitespace);
|
||||||
|
|
||||||
|
noWhitespace = StringUtils.deleteXmlWhitespace(" \tbaz\rbarz\t ");
|
||||||
|
assertEquals("bazbarz", noWhitespace);
|
||||||
|
|
||||||
|
noWhitespace = StringUtils.deleteXmlWhitespace("SNAFU");
|
||||||
|
assertEquals("SNAFU", noWhitespace);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue