Skip to content

Commit

Permalink
add regex IsMatch (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Feb 18, 2024
1 parent 2323d6e commit 60c41a0
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 1 deletion.
12 changes: 12 additions & 0 deletions api_list.include.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
* `Boolean TryFormat(Span<Char>, Int32&, ReadOnlySpan<Char>, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.double.tryformat)


### Guid

* `Boolean TryFormat(Span<Char>, Int32&, ReadOnlySpan<Char>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.guid.tryformat#system-guid-tryformat(system-span((system-char))-system-int32@-system-readonlyspan((system-char))))


### Int16

* `Boolean TryFormat(Span<Char>, Int32&, ReadOnlySpan<Char>, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int16.tryformat)
Expand Down Expand Up @@ -207,6 +212,12 @@
* `Boolean TryCopyTo(Span<Char>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.trycopyto)


### RegularExpressions.Regex

* `Boolean IsMatch(ReadOnlySpan<Char>, Int32)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-int32))
* `Boolean IsMatch(ReadOnlySpan<Char>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))))


### StringBuilder

* `StringBuilder Append(ReadOnlySpan<Char>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.append#system-text-stringbuilder-append(system-readonlyspan((system-char))))
Expand Down Expand Up @@ -254,6 +265,7 @@

* `Int32 Microseconds()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.timespan.microseconds)
* `Int32 Nanoseconds()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.timespan.nanoseconds)
* `Boolean TryFormat(Span<Char>, Int32&, ReadOnlySpan<Char>, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.timespan.tryformat#system-timespan-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider))


### Type
Expand Down
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,11 @@ The class `Polyfill` includes the following extension methods:
* `Boolean TryFormat(Span<Char>, Int32&, ReadOnlySpan<Char>, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.double.tryformat)


### Guid

* `Boolean TryFormat(Span<Char>, Int32&, ReadOnlySpan<Char>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.guid.tryformat#system-guid-tryformat(system-span((system-char))-system-int32@-system-readonlyspan((system-char))))


### Int16

* `Boolean TryFormat(Span<Char>, Int32&, ReadOnlySpan<Char>, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int16.tryformat)
Expand Down Expand Up @@ -610,6 +615,7 @@ The class `Polyfill` includes the following extension methods:

* `Int32 Microseconds()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.timespan.microseconds)
* `Int32 Nanoseconds()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.timespan.nanoseconds)
* `Boolean TryFormat(Span<Char>, Int32&, ReadOnlySpan<Char>, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.timespan.tryformat#system-timespan-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider))


### Type
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Version>2.3.0</Version>
<Version>2.4.0</Version>
<AssemblyVersion>1.0.0</AssemblyVersion>
<PackageTags>Polyfill</PackageTags>
<DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>
Expand Down
37 changes: 37 additions & 0 deletions src/Polyfill/Polyfill_RegeEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// <auto-generated />

#pragma warning disable

#if (MEMORYREFERENCED && !NET7_0_OR_GREATER)

using System;
using System.IO;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Link = System.ComponentModel.DescriptionAttribute;

static partial class Polyfill
{
/// <summary>
/// Indicates whether the regular expression specified in the Regex constructor finds a match in a specified input span.
/// </summary>
/// <returns>true if the regular expression finds a match; otherwise, false.</returns>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-int32)")]
public static bool IsMatch(this Regex target, ReadOnlySpan<char> input, int startat)
{
return target.IsMatch(input.ToString(), startat);
}

/// <summary>
/// Indicates whether the regular expression specified in the Regex constructor finds a match in a specified input span.
/// </summary>
/// <returns>true if the regular expression finds a match; otherwise, false.</returns>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char)))")]
public static bool IsMatch(this Regex target, ReadOnlySpan<char> input)
{
return target.IsMatch(input.ToString());
}
}
#endif
59 changes: 59 additions & 0 deletions src/Polyfill/RegexPolyfill.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// <auto-generated />

#pragma warning disable
#if MEMORYREFERENCED
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text.RegularExpressions;
using Link = System.ComponentModel.DescriptionAttribute;

[ExcludeFromCodeCoverage]
#if PolyPublic
public
#endif
static partial class RegexPolyfill
{
/// <summary>
/// Indicates whether the specified regular expression finds a match in the specified input span, using the specified matching options and time-out interval.
/// </summary>
/// <returns>true if the regular expression finds a match; otherwise, false.</returns>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-string-system-text-regularexpressions-regexoptions-system-timespan)")]
public static bool IsMatch(ReadOnlySpan<char> input, string pattern, RegexOptions options, TimeSpan matchTimeout)
{
#if NET7_0_OR_GREATER
return Regex.IsMatch(input, pattern, options, matchTimeout);
#else
return Regex.IsMatch(input.ToString(), pattern, options, matchTimeout);
#endif
}

/// <summary>
/// Indicates whether the specified regular expression finds a match in the specified input span, using the specified matching options.
/// </summary>
/// <returns>true if the regular expression finds a match; otherwise, false.</returns>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-string-system-text-regularexpressions-regexoptions)")]
public static bool IsMatch(ReadOnlySpan<char> input, string pattern, System.Text.RegularExpressions.RegexOptions options)
{
#if NET7_0_OR_GREATER
return Regex.IsMatch(input, pattern, options);
#else
return Regex.IsMatch(input.ToString(), pattern, options);
#endif
}

/// <summary>
/// Indicates whether the specified regular expression finds a match in the specified input span.
/// </summary>
/// <returns>true if the regular expression finds a match; otherwise, false.</returns>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-string)")]
public static bool IsMatch(ReadOnlySpan<char> input, string pattern)
{
#if NET7_0_OR_GREATER
return Regex.IsMatch(input, pattern);
#else
return Regex.IsMatch(input.ToString(), pattern);
#endif
}
}
#endif

0 comments on commit 60c41a0

Please sign in to comment.