String: "paragraph 1\nparagraph 2"
Array: {paragraph 1,paragraph 2}
public interface String_To_ConditionalBreak extends IsTransformer<String,String[]>
Converts a String to a String array processing conditional line breaks. Conditional line breaks are CR LF, CR, LF, <br>, and <br/>.
| Modifier and Type | Method and Description |
|---|---|
static String[] |
convert(String s)
Returns a string array with conditional line breaks processed.
|
static String_To_ConditionalBreak |
create()
Creates a transformer that takes a String and returns a String[] with conditional line breaks being processed.
|
default String[] |
transform(String s)
Transforms a String to a String[] processing conditional line breaks.
|
apply, transformdefault String[] transform(String s)
Transforms a String to a String[] processing conditional line breaks. Conditional line breaks are CR LF, CR, LF, <br>, and <br/>.
The method proceeds as follows:
replace all line breaks (CR LF, CR, LF) into HTML4 line break entity <br>
replace all HTML4 line break entities to HTML5 entities (as in self-closing <br/> entity).
use a tokenizer to process the resulting string (not ignoring empty tokens, since they mark required line breaks).
return the array of the tokenizer
As a result, a string containing 1 line break will be converted into an array length 2:
String: "paragraph 1\nparagraph 2"
Array: {paragraph 1,paragraph 2}
A string containing 2 line breaks will be converted into a string array with 3 entries (first paragraph, additional line break, second paragraph):
String: "paragraph 1\n\nparagraph 2"
Array: {paragraph 1,,paragraph 2}
transform in interface Transformer<String,String[]>s - input stringnull if s was nullstatic String_To_ConditionalBreak create()
Creates a transformer that takes a String and returns a String[] with conditional line breaks being processed. Conditional line breaks are CR LF, CR, LF, <br>, and <br/>.
Copyright © 2016–2017. All rights reserved.