Skip to content

Commit

Permalink
Update Extensions.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jul 6, 2024
1 parent a7f20be commit c6580fe
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/MarkdownSnippets/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,24 @@ public static int LineCount(this string input)
{
var count = 1;
var len = input.Length;
for(var i = 0; i != len; ++i)
for (var i = 0; i != len; ++i)
{
switch(input[i])
switch (input[i])
{
case '\r':
++count;
if (i + 1 != len && input[i + 1] == '\n')
{
++i;
}

break;
case '\n':
++count;
break;
}
}

return count;
}

Expand All @@ -92,15 +94,18 @@ public static int LastIndexOfSequence(this string value, char c, int max)
{
return index;
}

if (index == value.Length)
{
return index;
}

var ch = value[index];
if (c != ch)
{
return index;
}

index++;
}
}
Expand All @@ -112,9 +117,10 @@ public static string TrimBackCommentChars(this string input, int startIndex)
var ch = input[index];
if (char.IsLetterOrDigit(ch) || ch is ']' or ' ' or ')')
{
return input.Substring(startIndex, index + 1 - startIndex);
return input[startIndex..(index + 1)];
}
}

return string.Empty;
}

Expand Down

0 comments on commit c6580fe

Please sign in to comment.