Re: Small survey about JDK-8280101: in String.split grouped regex should keep the delimiter

2023-03-31 Thread Raffaello Giulietti
Hi Roger, I agree that Pattern.splitStream() would be hard use without contextual information, so let's drop it from the (still to be written) CSR. As for the guarantee that the array contains an alternation of n substrings and n-1 delimiters, this is what the overload String[] split(St

Re: Small survey about JDK-8280101: in String.split grouped regex should keep the delimiter

2023-03-31 Thread Roger Riggs
Hi Raffaello, It sounds useful to return the delimiters in a new API. It might be interesting to guarantee the array returns n strings and n-1 delimiters; filling with an empty string at the beginning and end if the input starts with or ends with a delimiter. Similar to the construction of Temp

Re: Small survey about JDK-8280101: in String.split grouped regex should keep the delimiter

2023-03-31 Thread Jim Laskey
D’oh - I did not know that. Good idiom to have in your pocket. > On Mar 31, 2023, at 10:20 AM, Raffaello Giulietti > wrote: > > IIUC, Case 1 could be covered already today with split("\\n", -1). That > returns N+1 substrings when the delimiter occurs N times. > > The proposed overload in Stri

Re: Small survey about JDK-8280101: in String.split grouped regex should keep the delimiter

2023-03-31 Thread Raffaello Giulietti
IIUC, Case 1 could be covered already today with split("\\n", -1). That returns N+1 substrings when the delimiter occurs N times. The proposed overload in String would be String[] split(String regex, int limit, boolean withDelimiters) with the existing split(regex, limit) simply invoking spl

Re: Small survey about JDK-8280101: in String.split grouped regex should keep the delimiter

2023-03-31 Thread Jim Laskey
[IMHO] I think you’ll find that split isn’t everyone’s favourite method for lots of reasons. For example, more often than not I would like to have split guarantee N + 1 elements in the result, where N is the number delimiters found. Case 1: text blocks split on newlines. Case 2: string templates

Small survey about JDK-8280101: in String.split grouped regex should keep the delimiter

2023-03-31 Thread Raffaello Giulietti
HI, JBS issue JDK-8280101 [0] proposes to add functionality to String.split() to behave more like the perl equivalent. Rather than returning only the substrings resulting from the split, the perl implementation can return an alternation of the substrings and the matched delimiters when the de