/**
// Split slices s into all subslices separated by sep and returns a slice of
// the subslices between those separators.
// If sep is empty, Split splits after each UTF-8 sequence.
// It is equivalent to SplitN with a count of -1.
*
* @param s
* @param sep
* @return
*/
public static List
return genSplit(s, sep, 0, -1);
}
/**
// SplitN slices s into subslices separated by sep and returns a slice of
// the subslices between those separators.
// If sep is empty, SplitN splits after each UTF-8 sequence.
// The count determines the number of subslices to return:
// n > 0: at most n subslices; the last subslice will be the unsplit remainder.
// n == 0: the result is nil (zero subslices)
// n < 0: all subslices
*
* @param s
* @param sep
* @param n
* @return
*/
public static List
return genSplit(s, sep, 0, n);
}
/**
// Generic split: splits after each instance of sep,
// including sepSave bytes of sep in the subslices.
* @param s
* @param sep
* @param sepSave
* @param n
* @return
*/
private static List
if( n == 0 ){
return null;
}
if(null==sep || sep.length == 0 ){
return split(s, n);
}
List
int i = 0;
while(i
for(int j =0;j
for(int k = 0;k
isFound = false;
break;
}
}
if(isFound){
m = j;
break;
}
}
if( m < 0 ){
break;
}
a.add(subArray(s,0,m+sepSave));
s = subArray(s,m+sep.length);
i++;
}
a.add( s );
return a;
}
/**
* Generate a subarray of a given byte array.
*
* @param input the input byte array
* @param start the start index
* @param end the end index
* @return a subarray of input, ranging from start
* (inclusively) to end (exclusively)
*/
public static byte[] subArray(byte[] input, int start, int end)
{
byte[] result = new byte[end - start];
System.arraycopy(input, start, result, 0, end - start);
return result;
}
/**
* Generate a subarray of a given byte array.
*
* @param input the input byte array
* @param start the start index
* @return a subarray of input, ranging from start to
* the end of the array
*/
public static byte[] subArray(byte[] input, int start)
{
return subArray(input, start, input.length);
}