diff options
author | Caleb Cushing <xenoterracide@gmail.com> | 2015-06-27 13:52:41 -0500 |
---|---|---|
committer | pascalschumacher <pascalschumacher@gmx.net> | 2016-05-29 09:39:09 +0200 |
commit | 1a002c67f2d3c198411a62165e53b31d6b414aa3 (patch) | |
tree | 9a1ebc1cef78ce53eddf2451238caa9e8fb69e19 /src/main/java/org/apache/commons/lang3/RandomStringUtils.java | |
parent | 9625891a7bbc0a8b11f7cf9c2b4650775ec8ac53 (diff) | |
download | apache-commons-lang-1a002c67f2d3c198411a62165e53b31d6b414aa3.tar.gz |
LANG-1225: Add RandomStringUtils#randomGraph and #randomPrint which match corresponding regular expression class
These are useful over randomAscii because they do not contain the DEL character but otherwise contain the full range of ASCII printing characters, and optionally include whitespace. This is useful for testing user defined inputs where characters like spaces, angle brakets, semicolons, dashes, etc. can cause issues.
Diffstat (limited to 'src/main/java/org/apache/commons/lang3/RandomStringUtils.java')
-rw-r--r-- | src/main/java/org/apache/commons/lang3/RandomStringUtils.java | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/main/java/org/apache/commons/lang3/RandomStringUtils.java b/src/main/java/org/apache/commons/lang3/RandomStringUtils.java index cc8d70bc4..662249f2b 100644 --- a/src/main/java/org/apache/commons/lang3/RandomStringUtils.java +++ b/src/main/java/org/apache/commons/lang3/RandomStringUtils.java @@ -111,6 +111,18 @@ public class RandomStringUtils { } /** + * <p>Creates a random string whose length is the number of characters specified.</p> + * + * <p>Characters will be chosen from the set of characters which match the POSIX [:graph:] regular expression.</p> + * + * @param count the length of random string to create + * @return the random string + */ + public static String randomGraph(final int count) { + return random(count, 33, 126, false, false); + } + + /** * <p>Creates a random string whose length is the number of characters * specified.</p> * @@ -125,6 +137,18 @@ public class RandomStringUtils { } /** + * <p>Creates a random string whose length is the number of characters specified.</p> + * + * <p>Characters will be chosen from the set of characters which match the POSIX [:print:] regular expression.</p> + * + * @param count the length of random string to create + * @return the random string + */ + public static String randomPrint(final int count) { + return random(count, 32, 126, false, false); + } + + /** * <p>Creates a random string whose length is the number of characters * specified.</p> * |