Skip to content

Commit

Permalink
Fix line/col in TextWithMarkers
Browse files Browse the repository at this point in the history
  • Loading branch information
mhutch committed Sep 5, 2024
1 parent c7b108f commit e5c608d
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions Core.Tests/Utils/TextWithMarkers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,19 +446,20 @@ public static TextWithMarkers Parse (string textWithMarkers, params char[] marke
for (int i = 0; i < textWithMarkers.Length; i++) {
var c = textWithMarkers[i];

int markerId = Array.IndexOf (markerChars, c);
if (markerId > -1) {
markerIndices[markerId].Add (new (sb.Length, line, col));
continue;
}

if (c == '\n') {
line++;
col = 0;
} else {
col++;
}

int markerId = Array.IndexOf (markerChars, c);
if (markerId > -1) {
markerIndices[markerId].Add (new (sb.Length, line, col));
} else {
sb.Append (c);
}
sb.Append (c);
}

return new (sb.ToString (), markerChars, markerIndices);
Expand Down Expand Up @@ -487,18 +488,19 @@ public static TextWithMarkers Parse (string textWithMarkers, char markerChar)
for (int i = 0; i < textWithMarkers.Length; i++) {
var c = textWithMarkers[i];

if(c == '\n') {
if (c == markerChar) {
markerIndices.Add (new (sb.Length, line, col));
continue;
}

if (c == '\n') {
line++;
col = 0;
} else {
col++;
}

if (c == markerChar) {
markerIndices.Add (new (sb.Length, line, col));
} else {
sb.Append (c);
}
sb.Append (c);
}

return new (sb.ToString (), [markerChar], [markerIndices]);
Expand Down

0 comments on commit e5c608d

Please sign in to comment.