Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/ServiceStack.Text/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,15 @@ public static bool ContainsAny(this string text, params string[] testMatches)
return false;
}

public static bool ContainsAny(this string text, StringComparison comparisonType, params string[] testMatches)
{
foreach (var testMatch in testMatches)
{
if (text.IndexOf(testMatch, comparisonType) >= 0) return true;
}
return false;
}

public static bool IsValidVarName(this string name) => InvalidVarCharsRegex.IsMatch(name);

public static string SafeVarName(this string text) => !string.IsNullOrEmpty(text)
Expand Down
9 changes: 9 additions & 0 deletions tests/ServiceStack.Text.Tests/StringExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,5 +344,14 @@ public void Can_convert_ToPascalCase()
Assert.That("Aa_Bb".ToPascalCase(), Is.EqualTo("AaBb"));
Assert.That("AA_BB".ToPascalCase(), Is.EqualTo("AaBb"));
}

[Test]
public void Does_ContainsAny_Return_CaseInsensitive_Matches()
{
var testMatches = new string[] { "abc" };
var input = "ABC";

Assert.That(input.ContainsAny(StringComparison.OrdinalIgnoreCase, testMatches));
}
}
}