Skip to content

Commit 93d30a6

Browse files
author
jantje
committed
fix problem with workaround on first and last line of txt file
Basically the code assumed there was a \n before and after the "interesting stuff" in regards to line replacements
1 parent 54deb2a commit 93d30a6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

io.sloeber.core/src/io/sloeber/core/txt/WorkAround.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,13 @@ private static String findLineContaining(String text, String searchString) {
396396
int SearchStringIndex = text.indexOf(searchString) + 1;
397397
if (SearchStringIndex > 0) {
398398
int lineStartIndex = text.lastIndexOf("\n", SearchStringIndex) + 1;
399-
if (lineStartIndex > 0) {
399+
if (lineStartIndex >= 0) {
400400
int lineEndIndex = text.indexOf("\n", lineStartIndex);
401-
if (lineEndIndex > 0) {
401+
if (lineEndIndex == -1) {
402+
// We are at the last line and it does not end with \n
403+
lineEndIndex = text.length();
404+
}
405+
if (lineEndIndex > lineStartIndex) {
402406
return text.substring(lineStartIndex, lineEndIndex);
403407
}
404408
}

0 commit comments

Comments
 (0)