You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2025/04/24 05:29:00 UTC
[jira] [Commented] (GROOVY-11636) Create a SGM#next which also takes an integer increment value
[ https://issues.apache.org/jira/browse/GROOVY-11636?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17946936#comment-17946936 ]
ASF GitHub Bot commented on GROOVY-11636:
-----------------------------------------
paulk-asert opened a new pull request, #2204:
URL: https://github.com/apache/groovy/pull/2204
…crement value
> Create a SGM#next which also takes an integer increment value
> -------------------------------------------------------------
>
> Key: GROOVY-11636
> URL: https://issues.apache.org/jira/browse/GROOVY-11636
> Project: Groovy
> Issue Type: New Feature
> Reporter: Paul King
> Assignee: Paul King
> Priority: Major
>
> Trying to get from String 'a' to 'e' by "adding 4" can be cumbersome, either calling next() multiple times, or converting to a char, doing the arithmetic, then converting back.
> The idea would be to support:
> {code:groovy}
> assert 'a'.next(0) == 'a'
> assert 'a'.next(4) == 'e'
> assert 'a'.next(0) == 'a'
> assert 'a'.next(25) == 'z'
> assert 'A'.next(32) == 'a'
> assert (0..4).collect('a'::next) == 'a'..'e'
> assert 'car'.next(2) == 'cat'
> {code}
> Although hopefully never used, this piggybacks on the normal next() wrapping behavior if Character.MAX_VALUE is reached. And also, like next(), applies the the last character in a longer String as per last test above.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)