[ https://issues.apache.org/jira/browse/GROOVY-11636?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17947168#comment-17947168 ]
Paul King edited comment on GROOVY-11636 at 4/25/25 12:09 AM: -------------------------------------------------------------- The intention is for something which doesn't try to do anything smart with codepoints, like the existing {{{}next()/++{}}}: {code:groovy} assert ++'🍑' == '🍒' // existing assert '🍑'.next() == '🍒' // existing assert '🍌'.next(5) == '🍑' assert '🍌'.next(6) == '🍒' assert ++'🙋🏻' == '🙋🏼' // existing assert (0..9).collect('🍌'::next).join() == '🍌🍍🍎🍏🍐🍑🍒🍓🍔🍕' assert '👩🍳'.next(9) == '👩🍼' assert '👩🍳'.next(32) == '👩🎓' assert '👩🍳'.next(10) == '👩🍽' {code} So, if you give a unicode sequence where it doesn't make sense to increment the last character, you might get something you don't expect. E.g. the last example above with next(10) ends up being "woman" + ZWJ + "dinnerplate" which isn't a recognised combination like the earlier examples. Increment on the ZWJ or the wrapping past Character.MAX_VALUE would also cause weirds combinations - but that is what was asked for! was (Author: paulk): The intention is for something which doesn't try to do anything smart with codepoints, like the existing {{{}next()/++{}}}: {code:groovy} assert ++'🍑' == '🍒' // existing assert '🍑'.next() == '🍒' // existing assert '🍌'.next(5) == '🍑' assert '🍌'.next(6) == '🍒' assert ++'🙋🏻' == '🙋🏼' // existing assert (0..8).collect('🍏'::next).join() == '🍏🍐🍑🍒🍓🍔🍕🍖🍗' assert '👩🍳'.next(9) == '👩🍼' assert '👩🍳'.next(32) == '👩🎓' assert '👩🍳'.next(10) == '👩🍽' {code} So, if you give a unicode sequence where it doesn't make sense to increment the last character, you might get something you don't expect. E.g. the last example above with next(10) ends up being "woman" + ZWJ + "dinnerplate" which isn't a recognised combination like the earlier examples. Increment on the ZWJ or the wrapping past Character.MAX_VALUE would also cause weirds combinations - but that is what was asked for! > 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)