You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Adithyan K (JIRA)" <ji...@apache.org> on 2018/05/10 19:22:00 UTC

[jira] [Commented] (GROOVY-7154) Adding new useful String extension methods

    [ https://issues.apache.org/jira/browse/GROOVY-7154?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16470984#comment-16470984 ] 

Adithyan K commented on GROOVY-7154:
------------------------------------

For one of my projects, I have already implemented the below methods in my own `*StringExtension*` class

Can I send a PR for this?

Pls advice !

 

static String after(String self, String after)

/**
 * Splits the given String with the given separator String and returns the value at the given column Index. By
 * default, successive occurrence of the separator String is taken are one unit and the split is performed
 * 
 * @param self
 * @param separator
 * @param colIndex
 * @return
 */
 static String column(String self, String separator, int colIndex)

/**
 * Splits the given String with Space characters and returns the value at the given column Index.
 * 
 * @param self
 * @param colIndex
 * @return
 */
 static String column(String self, int colIndex)
 
 static String left(String self, int chars)

static String right(String self, int chars)

static String before(String self, String searchString)

/**
 * Returns string before '=' char
 *
 */
 static String getBeforeeq(String self)

static String bwDoubleQuotes(String line)

static String bwSingleQuotes(String line)

static String bw(String line, String enclosure)

static String bw(String line, String from, String to)

static String bwDoubleQuotes(String line, int item)

static String bwSingleQuotes(String line, int item)

static String bw(String line, String enclosure, int item)
 
 static void split(String self, String regex, Closure closure)
 
 static long getHexToLong(String hexString)

 

> Adding new useful String extension methods 
> -------------------------------------------
>
>                 Key: GROOVY-7154
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7154
>             Project: Groovy
>          Issue Type: New Feature
>          Components: groovy-jdk
>            Reporter: Maciej Ziarko
>            Priority: Minor
>
> There are several methods in commons lang StringUtils that are used very often.
> It would be pretty nice to see them in Groovy in order to eliminate nasty static non-object-oriented invocations StringUtils.methodName
> Suggested methods:
> String substringAfter(String separator)
> Gets the substring after the first occurrence of a separator.
> String substringAfterLast(String separator)
> Gets the substring after the last occurrence of a separator
> String substringBefore(String separator)
> Gets the substring before the first occurrence of a separator.
> String substringBeforeLast(String separator)
> Gets the substring before the last occurrence of a separator.
> String substringBetween(String tag)
> Gets the String that is nested in between two instances of the same String.
> String substringBetween(String open, String close)
> Gets the String that is nested in between two Strings.
> static String[] substringsBetween(String open, String close)
> Searches a String for substrings delimited by a start and end tag, returning all matching substrings in an array.
> String prependIfMissing(CharSequence prefix, CharSequence... prefixes)
> Prepends the prefix to the start of the string if the string does not already start with any of the prefixes.
> String appendIfMissing(CharSequence suffix, CharSequence... suffixes)
> Appends the suffix to the end of the string if the string does not already end with any the suffixes.
> Any other suggestions are welcome.
> I'd like to implement it (possibly migrate from Commons Utils) if it gets green light.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)