Skip to content

Commit

Permalink
Replace StartWithIgnoreCase with build-in StartsWith
Browse files Browse the repository at this point in the history
  • Loading branch information
FrediKats committed Aug 17, 2023
1 parent 0a65182 commit bf5f93e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
7 changes: 1 addition & 6 deletions Sources/Kysect.Configuin.Common/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ namespace Kysect.Configuin.Common;

public static class StringExtensions
{
public static bool StartWithIgnoreCase(this string value, string otherValue)
{
return value.Substring(0, otherValue.Length).Equals(otherValue, StringComparison.InvariantCultureIgnoreCase);
}

public static string RemovePrefix(this string value, string prefix)
{
if (!value.StartWithIgnoreCase(prefix))
if (!value.StartsWith(prefix, StringComparison.InvariantCultureIgnoreCase))
throw new ArgumentException($"String {value} does not start with {prefix}");

return value.Substring(prefix.Length, value.Length - prefix.Length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public static RoslynRuleId Parse(string value)
{
// CA1234
string qualityRulePrefix = "CA";
if (value.StartWithIgnoreCase(qualityRulePrefix))
if (value.StartsWith(qualityRulePrefix, StringComparison.InvariantCultureIgnoreCase))
{
string id = value.RemovePrefix(qualityRulePrefix);
return new RoslynRuleId(RoslynRuleType.QualityRule, int.Parse(id));
}

// IDE1234
string styleRulePrefix = "IDE";
if (value.StartWithIgnoreCase(styleRulePrefix))
if (value.StartsWith(styleRulePrefix, StringComparison.InvariantCultureIgnoreCase))
{
string id = value.RemovePrefix(styleRulePrefix);
return new RoslynRuleId(RoslynRuleType.QualityRule, int.Parse(id));
Expand Down

0 comments on commit bf5f93e

Please sign in to comment.