Hi Andres,
nice to have you back as a groovy commiter :)
Cheers,
Pascal
Am 19.06.2015 um 17:41 schrieb [email protected]:
Repository: incubator-groovy
Updated Branches:
refs/heads/master f953de781 -> 791e71f4d
GROOVY-7472 add uncapitalize() to SGM, applied to CharSequence
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/791e71f4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/791e71f4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/791e71f4
Branch: refs/heads/master
Commit: 791e71f4d35a85dcef2fb338a681002166b9f20a
Parents: f953de7
Author: aalmiray <[email protected]>
Authored: Fri Jun 19 17:41:00 2015 +0200
Committer: aalmiray <[email protected]>
Committed: Fri Jun 19 17:41:00 2015 +0200
----------------------------------------------------------------------
.../groovy/runtime/StringGroovyMethods.java | 23 ++++++++++++++++++++
.../groovy/GroovyCharSequenceMethodsTest.groovy | 6 +++++
2 files changed, 29 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/791e71f4/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
b/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
index bd4a76a..27031ef 100644
--- a/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
+++ b/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
@@ -98,6 +98,7 @@ import static
org.codehaus.groovy.runtime.DefaultGroovyMethods.join;
* @author Dinko Srkoc
* @author Pascal Lombard
* @author Christophe Charles
+ * @author Andres Almiray
*/
public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
@@ -240,6 +241,28 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
}
/**
+ * Convenience method to uncapitalize the first letter of a CharSequence
+ * (typically the first letter of a word). Example usage:
+ * <pre class="groovyTestCase">
+ * assert 'H'.uncapitalize() == 'h'
+ * assert 'Hello'.uncapitalize() == 'hello'
+ * assert 'Hello world'.uncapitalize() == 'hello world'
+ * assert 'Hello World'.uncapitalize() == 'hello World'
+ * assert 'Hello World' ==
+ * 'hello world'.split(' ').collect{ it.uncapitalize() }.join(' ')
+ * </pre>
+ *
+ * @param self The CharSequence to uncapitalize
+ * @return A String containing the uncapitalized toString() of the
CharSequence
+ * @since 2.5.0
+ */
+ public static String uncapitalize(CharSequence self) {
+ String s = self.toString();
+ if (s == null || s.length() == 0) return s;
+ return Character.toLowerCase(s.charAt(0)) + s.substring(1);
+ }
+
+ /**
* Convenience method to capitalize the first letter of a CharSequence
* (typically the first letter of a word). Example usage:
* <pre class="groovyTestCase">
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/791e71f4/src/test/groovy/GroovyCharSequenceMethodsTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/GroovyCharSequenceMethodsTest.groovy
b/src/test/groovy/GroovyCharSequenceMethodsTest.groovy
index 47a0247..0e40f2c 100644
--- a/src/test/groovy/GroovyCharSequenceMethodsTest.groovy
+++ b/src/test/groovy/GroovyCharSequenceMethodsTest.groovy
@@ -170,6 +170,12 @@ class GroovyCharSequenceMethodsTest extends GroovyTestCase
{
assert cs2.capitalize() == 'Foobar'
}
+ void testUncapitalize() {
+ def csfoo = [toString:{->'Foo'}] as CharSequence
+ assert csfoo.uncapitalize() == 'foo'
+ assert cs2.uncapitalize() == 'foobar'
+ }
+
void testExpand() {
def csfoobar = [toString:{->'foo\tbar'}] as CharSequence
assert csfoobar.expand() == 'foo bar'