GitHub user thiagoh opened a pull request:
https://github.com/apache/commons-lang/pull/25
Adding unwrap and unwrapFull methods to StringUtils
Adding the following methods from `StringUtils`:
* `public static String unwrap(String str, char unwrapChar)`
* `public static String unwrapFull(String str, char unwrapChar)`
* `public static String unwrap(String str, String unwrapStr)`
* `public static String unwrapFull(String str, String unwrapStr)`
* `public static String unwrap(String str, String unwrapLeft, String
unwrapRight)`
* `public static String unwrapFull(String str, String unwrapLeft, String
unwrapRight)`
These methods unwraps (fully or not) the string parameter
Usage:
```
// public static String unwrap(String str, char unwrapChar)
StringUtils.unwrap("", '\0') = ""
StringUtils.unwrap("xabx", 'x') = "ab"
StringUtils.unwrap("\"ab\"", '\"') = "ab"
StringUtils.unwrap("\"\"ab\"\"", '\"') = "\"ab\""
StringUtils.unwrap("'ab'", '\'') = "ab"
StringUtils.unwrap("''ab''", '\'') = "'ab'"
StringUtils.unwrap("'''ab'''", '\'') = "''ab''"
StringUtils.unwrap("'\"abcd\"'", '\'') = "\"abcd\""
StringUtils.unwrap("'\"abcd\"'", '\"') = "'\"abcd\"'"
// public static String unwrapFull(String str, char unwrapChar)
StringUtils.unwrapFull("", '\0') = ""
StringUtils.unwrapFull("xabx", 'x') = "ab"
StringUtils.unwrapFull("xxxxxxabxxxxxx", 'x') = "ab"
StringUtils.unwrapFull("\"ab\"", '\"') = "ab"
StringUtils.unwrapFull("\"\"ab\"\"", '\"') = "ab"
StringUtils.unwrapFull("'ab'", '\'') = "ab"
StringUtils.unwrapFull("'x'ab'x'", '\'') = "x'ab'x"
StringUtils.unwrapFull("''ab''", '\'') = "ab"
StringUtils.unwrapFull("'''''ab'''''", '\'') = "ab"
StringUtils.unwrapFull("''''x'ab'''''", '\'') = "x'ab'"
StringUtils.unwrapFull("'ab''''", '\'') = "ab'''"
// public static String unwrap(String str, String unwrapStr)
StringUtils.unwrap("xxabxx", "xx") = "ab"
StringUtils.unwrap("xxxxabxxxx", "xx") = "xxabxx"
StringUtils.unwrap("xx xxabxx xx", "xx") = " xxabxx "
StringUtils.unwrap("xxZxx", "xx") = "Z"
StringUtils.unwrap("xxZxx", "x") = "xZx"
StringUtils.unwrap("xzx xzx", "xzx") = " "
StringUtils.unwrap("xxxx xxxx", "xx") = "xx xx"
StringUtils.unwrap("'name'", "'") = "name"
StringUtils.unwrap("''name''", "'") = "'name'"
StringUtils.unwrap("'''name'''", "'") = "''name''"
// public static String unwrapFull(String str, String unwrapStr)
StringUtils.unwrapFull("xxabxx", "x") = "ab"
StringUtils.unwrapFull("xx xxabxx xx", "xx") = " ab "
StringUtils.unwrapFull("xxZxx", "xx") = "Z"
StringUtils.unwrapFull("xzx xzx", "xzx") = " "
StringUtils.unwrapFull("xxxx xxxx", "xx") = " "
StringUtils.unwrapFull("'name'", "'") = "name"
StringUtils.unwrapFull("''name''", "'") = "name"
StringUtils.unwrapFull("'''name'''", "'") = "name"
// public static String unwrap(String str, String unwrapLeft, String
unwrapRight)
StringUtils.unwrap("xxabxx", "x", "x") = "ab"
StringUtils.unwrap("xx xxabxx xx", "xx", "xx") = " ab "
StringUtils.unwrap("xxZxx", "xx", "xx") = "Z"
StringUtils.unwrap("xxZxx", "xx", "yy") = "xxZxx" // no unwrap
StringUtils.unwrap("xzx xzx", "xzx", "xzx") = " "
StringUtils.unwrap("xxxx xxxx", "xx", "xx") = " "
StringUtils.unwrap("xxxx xxxx", "xx", "yy") = "xxxx xxxx" // no unwrap
StringUtils.unwrap("xxxxxxxxxxoutputxxxxxxxxxx", "xxxxx", "xxxxx") =
"output"
StringUtils.unwrap("%{name}", "%{", "}") = "name"
StringUtils.unwrap("%{ name}", "%{", "}") = " name"
StringUtils.unwrap("%{ name }", "%{", "}") = " name "
StringUtils.unwrap(" %{ name }", "%{", "}") = " name "
StringUtils.unwrap("%{'name'}", "%{'", "'}") = "name"
StringUtils.unwrap("%{' name'}", "%{'", "'}") = " name"
StringUtils.unwrap("%{' name '}", "%{'", "'}") = " name "
StringUtils.unwrap(" %{' name '}", "%{'", "'}") = " name "
StringUtils.unwrap("%{ 'name'}", "%{'", "'}") = "%{ 'name'}" // no unwrap
StringUtils.unwrap("% {'name'}", "%{'", "'}") = "% {'name'}" // no unwrap
StringUtils.unwrap("% { 'name'}", "%{'", "'}") = "% { 'name'}" // no unwrap
// public static String unwrapFull(String str, String unwrapLeft, String
unwrapRight)
StringUtils.unwrapFull("xxabxx", "x", "x") = "ab"
StringUtils.unwrapFull("xx xxabxx xx", "xx", "xx") = " ab "
StringUtils.unwrapFull("xxZxx", "xx", "xx") = "Z"
StringUtils.unwrapFull("xxZxx", "xx", "yy") = "xxZxx" // no unwrap
StringUtils.unwrapFull("xzx xzx", "xzx", "xzx") = " "
StringUtils.unwrapFull("xxxx xxxx", "xx", "xx") = " "
StringUtils.unwrapFull("xxxx xxxx", "xx", "yy") = "xxxx xxxx" // no unwrap
StringUtils.unwrapFull("xxxxxxxxxxoutputxxxxxxxxxx", "xxxxx", "xxxxx") =
"output"
StringUtils.unwrapFull("%{name}", "%{", "}") = "name"
StringUtils.unwrapFull("%{ name}", "%{", "}") = " name"
StringUtils.unwrapFull("%{ name }", "%{", "}") = " name "
StringUtils.unwrapFull(" %{ name }", "%{", "}") = " name "
StringUtils.unwrapFull("%{'name'}", "%{'", "'}") = "name"
StringUtils.unwrapFull("%{' name'}", "%{'", "'}") = " name"
StringUtils.unwrapFull("%{' name '}", "%{'", "'}") = " name "
StringUtils.unwrapFull(" %{' name '}", "%{'", "'}") = " name "
StringUtils.unwrapFull("%{ 'name'}", "%{'", "'}") = "%{ 'name'}" // no
unwrap
StringUtils.unwrapFull("% {'name'}", "%{'", "'}") = "% {'name'}" // no
unwrap
StringUtils.unwrapFull("% { 'name'}", "%{'", "'}") = "% { 'name'}" // no
unwrap
```
Jira ticket
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/thiagoh/commons-lang branch-2-unwrap
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/commons-lang/pull/25.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #25
----
commit 97261aa164cb0d924188dbcb5634afc2935305b3
Author: thiagoh <[email protected]>
Date: 2014-05-14T20:55:52Z
Adding unwrap and unwrapFull methods to StringUtils
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]