Skip to content

Commit

Permalink
polyfill EndsWith char
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Aug 9, 2022
1 parent 04af432 commit fdd6272
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/Verify/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ public static bool StartsWith(this string value, char ch)

return value[0] == ch;
}

public static bool EndsWith(this string value, char ch)
{
var lastPos = value.Length - 1;
if (lastPos >= value.Length)
{
return false;
}

return value[lastPos] == ch;
}
#endif

public static FrameworkName? FrameworkName(this Assembly assembly)
Expand Down
4 changes: 2 additions & 2 deletions src/Verify/Serialization/Scrubbers/LinesScrubber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void ReplaceLines(this StringBuilder input, Func<string, string?>
}

if (theString.Length > 0 &&
!theString.EndsWith("\n"))
!theString.EndsWith('\n'))
{
input.Length -= 1;
}
Expand All @@ -46,7 +46,7 @@ public static void FilterLines(this StringBuilder input, Func<string, bool> remo
}

if (input.Length > 0 &&
!theString.EndsWith("\n"))
!theString.EndsWith('\n'))
{
input.Length -= 1;
}
Expand Down

0 comments on commit fdd6272

Please sign in to comment.