I just came across a strange bug in
NSArray.componentsSeparatedByString(). Under certain conditions, the
number of components in the array doesn't match the expected number.
I came across the problem while checking the number of columns in a
CSV file. To reproduce it, the following conditions must be met:
1. Your last two colums are empty (String ends with two times the
separator)
2a. You have a single-character separator AND your string is longer
than 255 characters
OR
2b. You have a multi character separator
Here's the output of some sample code with WO 5.3.3. The result
should always be 3.
Testing with two single character separators and empty last column
String lenght: 255, number of columns: 3
String lenght: 256, number of columns: 2
Testing with two single character separators and filled last column
String lenght: 255, number of columns: 3
String lenght: 256, number of columns: 3
Testing with two multi character separators and empty last column
String lenght: 255, number of columns: 2
String lenght: 256, number of columns: 2
Testing with two multi character separators and filled last column
String lenght: 255, number of columns: 3
String lenght: 256, number of columns: 3
Here's the reproduction code:
public static void main(String[] args) throws Exception {
System.out.println("Testing with two single character separators and
empty last column");
testWithSeparator("|", null);
System.out.println("Testing with two single character separators and
filled last column");
testWithSeparator("|", "x");
System.out.println("Testing with two multi character separators and
empty last column");
testWithSeparator("||", null);
System.out.println("Testing with two multi character separators and
filled last column");
testWithSeparator("||", "x");
}