Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 4eb4c35

Browse files
JDBarndtmythz
authored andcommitted
Support StringComparison options for ContainsAny (#514)
Thx for the PR! Somehow missed the notification for this, sorry for the delay.
1 parent 4c7afb6 commit 4eb4c35

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/ServiceStack.Text/StringExtensions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,15 @@ public static bool ContainsAny(this string text, params string[] testMatches)
918918
return false;
919919
}
920920

921+
public static bool ContainsAny(this string text, StringComparison comparisonType, params string[] testMatches)
922+
{
923+
foreach (var testMatch in testMatches)
924+
{
925+
if (text.IndexOf(testMatch, comparisonType) >= 0) return true;
926+
}
927+
return false;
928+
}
929+
921930
public static bool IsValidVarName(this string name) => InvalidVarCharsRegex.IsMatch(name);
922931

923932
public static string SafeVarName(this string text) => !string.IsNullOrEmpty(text)

tests/ServiceStack.Text.Tests/StringExtensionsTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,5 +344,14 @@ public void Can_convert_ToPascalCase()
344344
Assert.That("Aa_Bb".ToPascalCase(), Is.EqualTo("AaBb"));
345345
Assert.That("AA_BB".ToPascalCase(), Is.EqualTo("AaBb"));
346346
}
347+
348+
[Test]
349+
public void Does_ContainsAny_Return_CaseInsensitive_Matches()
350+
{
351+
var testMatches = new string[] { "abc" };
352+
var input = "ABC";
353+
354+
Assert.That(input.ContainsAny(StringComparison.OrdinalIgnoreCase, testMatches));
355+
}
347356
}
348357
}

0 commit comments

Comments
 (0)