[ https://issues.apache.org/jira/browse/TEXT-231?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17763443#comment-17763443 ]
Michael Karnerfors commented on TEXT-231: ----------------------------------------- [~ggregory] Yes, it is true that I have reorganised the tests, and that makes for a difficult-to-read patch. I will gladly make a branch on GitHub. I do have a couple of questions: * Apart from the code change, do I need to add/edit anything else, to the pom.xml or similar, to show which Jira issue the change belongs to? * What is a good style for the branch name? Will TEXT-231 suffice or should I add a short description? > WordUtils.wrap should react to prexisting "new line string" as a wrap > --------------------------------------------------------------------- > > Key: TEXT-231 > URL: https://issues.apache.org/jira/browse/TEXT-231 > Project: Commons Text > Issue Type: Improvement > Affects Versions: 1.10.0 > Reporter: Michael Karnerfors > Priority: Minor > Attachments: TEXT-231-wrap-on-newline-string.patch > > > WordUtils.wrap ignores pre-existing occurrences of the "new line string" and > counts them as part of a line, instead of as a wrap. > Example: > {code:java} > public static final String LINE_SEPARATOR = "\n"; > void wrap() { > String line = "Alpha"+ LINE_SEPARATOR + "Bravo Charlie Delta Echo > Foxtrot"; > System.out.println(WordUtils.wrap(line, 13)); > } {code} > The default new line string is just newline ("\n"). So in this case I would > expect this to output... > {noformat} > Alpha > Bravo Charlie > Delta Echo > Foxtrot > {noformat} > However, since WordUtils.wrap does not consider the pre-existing newline > after "Alpha" as one of its own wraps, I instead get... > {noformat} > Alpha > Bravo > Charlie Delta > Echo Foxtrot > {noformat} > There is a work-around, but it is not as elegant... > {code:java} > String wrappedLine = > Arrays > .stream( > line.split(LINE_SEPARATOR) > ) > .map( > subLine -> WordUtils.wrap(subLine, 13) > ) > .collect( > Collectors.joining(LINE_SEPARATOR) > ); > System.out.println(wrappedLine); > {code} > Hence, I suggest that WordUtils.wrap should consider matches of "newLineStr" > as a wrap, and any directly following text as the beginning of the next line. -- This message was sent by Atlassian Jira (v8.20.10#820010)