Skip to content

Commit

Permalink
fixed issue in connectors
Browse files Browse the repository at this point in the history
  • Loading branch information
dhuson committed Feb 16, 2021
1 parent fe1b550 commit a2994e6
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions src/jloda/util/Basic.java
Original file line number Diff line number Diff line change
Expand Up @@ -2951,7 +2951,7 @@ public static String getAnExistingFileWithGivenExtension(String path, final List
* @return split string, trimmed
*/
public static String[] split(String aLine, char splitChar) {
return split(aLine, splitChar, Integer.MAX_VALUE);
return split(aLine, splitChar, Integer.MAX_VALUE,false);
}

/**
Expand All @@ -2962,6 +2962,18 @@ public static String[] split(String aLine, char splitChar) {
* @return split string, trimmed
*/
public static String[] split(String aLine, char splitChar, int maxTokens) {
return split(aLine,splitChar,maxTokens,false);
}


/**
* split string on given character. Note that results are subsequently trimmed
*
* @param aLine
* @param splitChar
* @return split string, trimmed
*/
public static String[] split(String aLine, char splitChar, int maxTokens,boolean skipEmptyTokens) {
aLine = aLine.trim();
if (aLine.length() == 0 || maxTokens <= 0)
return new String[0];
Expand All @@ -2971,13 +2983,19 @@ public static String[] split(String aLine, char splitChar, int maxTokens) {

// count the number of tokens
int count = 1;
if (maxTokens > 1) {
for (int i = 0; i < length; i++) {
if (aLine.charAt(i) == splitChar) {
if (count < maxTokens)
count++;
else
break;
{
int prev = -1;
if (maxTokens > 1) {
for (int i = 0; i < length; i++) {
if (aLine.charAt(i) == splitChar) {
if (!skipEmptyTokens || i > prev + 1) {
if (count < maxTokens)
count++;
else
break;
}
prev = i;
}
}
}
}
Expand All @@ -2988,10 +3006,12 @@ public static String[] split(String aLine, char splitChar, int maxTokens) {
int pos = 0;
for (; pos < length; pos++) {
if (aLine.charAt(pos) == splitChar) {
result[which++] = aLine.substring(prev, pos).trim();
prev = pos + 1;
if (which == count)
return result;
if(!skipEmptyTokens || pos>prev+1) {
result[which++] = aLine.substring(prev, pos).trim();
prev = pos + 1;
if (which == count)
return result;
}
}
}
if (pos > prev) {
Expand Down

0 comments on commit a2994e6

Please sign in to comment.