Skip to content

Commit

Permalink
Add implementation of String.lines() (jdk11 only)
Browse files Browse the repository at this point in the history
This change adds an implementation of String.lines(), which returns
a lazily supplied Stream of Strings broken up by line terminators.

Signed-off-by: Mohammad Ali Nikseresht <anikser@ibm.com>
  • Loading branch information
Mohammad Ali Nikseresht committed Jul 24, 2018
1 parent ba7262b commit d6d3224
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions jcl/src/java.base/share/classes/java/lang/String.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
import sun.misc.Unsafe;
/*[ENDIF] Sidecar19-SE*/

/*[IF Java11]*/
import java.util.stream.Stream;
/*[ENDIF] Java11*/

/**
* Strings are objects which represent immutable arrays of characters.
*
Expand Down Expand Up @@ -2583,8 +2587,26 @@ public boolean isBlank() {

return index >= lengthInternal();
}
/*[ENDIF]*/


/**
* Returns a stream of substrings extracted from this string partitioned by line terminators.
*
* Line terminators recognized are line feed "\n", carriage return "\r", and carriage return
* followed by line feed "\r\n".
*
* @return the stream of this string's substrings partitioned by line terminators
*
* @since 11
*/
public Stream<String> lines() {
if (enableCompression && (null == compressionFlag || coder == LATIN1)) {
return StringLatin1.lines(value);
} else {
return StringUTF16.lines(value);
}
}
/*[ENDIF] Java11*/

/**
* Copies a range of characters into a new String.
*
Expand Down

0 comments on commit d6d3224

Please sign in to comment.