Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TextIO.read() split with non-default delimiter #32298

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,11 @@ private boolean readCustomLine() throws IOException {
// Add to str any previous partial delimiter since we didn't match the whole
// delimiter
str.write(delimiter, 0, prevDelPosn);
delPosn = 0;
if (buffer[bufferPosn] == delimiter[0]) {
delPosn = 1;
} else {
delPosn = 0;
}
break; // Leave this loop and use the fast-path delimiter matching
}
}
Expand All @@ -452,6 +456,8 @@ private boolean readCustomLine() throws IOException {
bufferPosn++;
break;
}
} else if (buffer[bufferPosn] == delimiter[0]) {
delPosn = 1;
} else {
delPosn = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,10 @@ public void testReadStringsWithCustomDelimiter() throws Exception {
"To be, or not to be: that *is the question: ",
// complete delimiter
"Whether 'tis nobler in the mind to suffer |*",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we preserve this existing line case. just add one more line to test *||**|, like

// complete delimiter
"Whether 'tis nobler in the mind to suffer |*",
// edge case: partial delimiter then complete delimiter
"The slings and arrows of outrageous fortune,*||**|"
// truncated delimiter
"Or to take arms against a sea of troubles,|"

// edge case: partial delimiter then complete delimiter
"The slings and arrows of outrageous fortune,*||**|",
// truncated delimiter
"The slings and arrows of outrageous fortune,|"
"Or to take arms against a sea of troubles,|"
};

File tmpFile = tempFolder.newFile("tmpfile.txt");
Expand All @@ -689,7 +691,8 @@ public void testReadStringsWithCustomDelimiter() throws Exception {
.containsInAnyOrder(
"To be, or not to be: that |is the question: To be, or not to be: "
+ "that *is the question: Whether 'tis nobler in the mind to suffer ",
"The slings and arrows of outrageous fortune,|");
"The slings and arrows of outrageous fortune,*|",
"*|Or to take arms against a sea of troubles,|");
p.run();
}

Expand Down
Loading