Skip to content

Commit c346337

Browse files
author
Open Lowcode SAS
committed
Close #72 Close #74
1 parent 6bfe7de commit c346337

File tree

4 files changed

+294
-51
lines changed

4 files changed

+294
-51
lines changed

src/org/openlowcode/tools/misc/SplitString.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,15 @@ public boolean getTransitionAt(int index) {
5454
}
5555

5656
/**
57-
* create a Split chain, parsing the string for carriage return and new lines
57+
* create a Split chain, parsing the string for new lines only (\n or \r\n)
58+
* (carriage returns are kept in sections), or for all
5859
*
5960
* @param chaintosplit the string to split
61+
* @param onlymajor if true, only new lines are considered, if false, new
62+
* lines and carriage returns are considered
63+
* @since 1.5
6064
*/
61-
public SplitString(String chaintosplit) {
62-
65+
public SplitString(String chaintosplit, boolean onlymajor) {
6366
stringsplit = new ArrayList<String>();
6467
transitions = new ArrayList<Boolean>();
6568

@@ -70,10 +73,10 @@ public SplitString(String chaintosplit) {
7073
while (parseindex < chaintosplit.length()) {
7174
int currentchar = chaintosplit.charAt(parseindex);
7275
boolean specialcharacter = false;
73-
if (currentchar == 13) {
76+
if (currentchar == 13) { // \r
7477
specialcharacter = true;
7578
}
76-
if (currentchar == 10) {
79+
if (currentchar == 10) { // \n
7780
specialcharacter = true;
7881
stringsplit.add(currentstring.toString());
7982
transitions.add(new Boolean(lastsplitismajor));
@@ -83,10 +86,14 @@ public SplitString(String chaintosplit) {
8386
}
8487
if (!specialcharacter) {
8588
if (lastisbackslashr) {
86-
stringsplit.add(currentstring.toString());
87-
transitions.add(new Boolean(lastsplitismajor));
88-
lastsplitismajor = false;
89-
currentstring = new StringBuffer();
89+
if (!onlymajor) {
90+
stringsplit.add(currentstring.toString());
91+
transitions.add(new Boolean(lastsplitismajor));
92+
lastsplitismajor = false;
93+
currentstring = new StringBuffer();
94+
} else {
95+
currentstring.append((char) '\r');
96+
}
9097
}
9198
lastisbackslashr = false;
9299
currentstring.append((char) currentchar);
@@ -99,4 +106,14 @@ public SplitString(String chaintosplit) {
99106
stringsplit.add(currentstring.toString());
100107
transitions.add(new Boolean(lastsplitismajor));
101108
}
109+
110+
/**
111+
* create a Split chain, parsing the string for carriage return and new lines
112+
*
113+
* @param chaintosplit the string to split
114+
*/
115+
public SplitString(String chaintosplit) {
116+
this(chaintosplit, false);
117+
118+
}
102119
}

0 commit comments

Comments
 (0)