Skip to content
This repository was archived by the owner on Jan 23, 2023. 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<ProjectReference Include="..\ref\System.Text.RegularExpressions.csproj">
<ProjectReference Include="..\ref\System.Text.RegularExpressions.builds">
<SupportedFramework>net463;netcoreapp1.1;$(AllXamarinFrameworks)</SupportedFramework>
</ProjectReference>
<ProjectReference Include="..\src\System.Text.RegularExpressions.builds" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<Project Include="System.Text.RegularExpressions.csproj" />
<Project Include="System.Text.RegularExpressions.csproj">
<TargetGroup>netcoreapp1.1</TargetGroup>
</Project>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.traversal.targets))\dir.traversal.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<ItemGroup>
<Compile Include="System.Text.RegularExpressions.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'netcoreapp1.1'">
<Compile Include="System.Text.RegularExpressions.netcoreapp1.1.cs" />
</ItemGroup>
<ItemGroup>
<None Include="project.json" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// ------------------------------------------------------------------------------
// Changes to this file must follow the http://aka.ms/api-review process.
// ------------------------------------------------------------------------------


namespace System.Text.RegularExpressions
{
public partial class CaptureCollection : System.Collections.Generic.ICollection<System.Text.RegularExpressions.Capture>, System.Collections.Generic.IEnumerable<System.Text.RegularExpressions.Capture>, System.Collections.Generic.IList<System.Text.RegularExpressions.Capture>, System.Collections.Generic.IReadOnlyCollection<System.Text.RegularExpressions.Capture>, System.Collections.Generic.IReadOnlyList<System.Text.RegularExpressions.Capture>, System.Collections.ICollection, System.Collections.IEnumerable, System.Collections.IList
{
public void CopyTo(System.Text.RegularExpressions.Capture[] array, int arrayIndex) { }
System.Collections.Generic.IEnumerator<System.Text.RegularExpressions.Capture> System.Collections.Generic.IEnumerable<System.Text.RegularExpressions.Capture>.GetEnumerator() { throw null; }
int System.Collections.Generic.IList<System.Text.RegularExpressions.Capture>.IndexOf(System.Text.RegularExpressions.Capture item) { throw null; }
void System.Collections.Generic.IList<System.Text.RegularExpressions.Capture>.Insert(int index, System.Text.RegularExpressions.Capture item) { }
void System.Collections.Generic.IList<System.Text.RegularExpressions.Capture>.RemoveAt(int index) { }
System.Text.RegularExpressions.Capture System.Collections.Generic.IList<System.Text.RegularExpressions.Capture>.this[int index] { get { throw null; } set { } }
void System.Collections.Generic.ICollection<System.Text.RegularExpressions.Capture>.Add(System.Text.RegularExpressions.Capture item) { }
void System.Collections.Generic.ICollection<System.Text.RegularExpressions.Capture>.Clear() { }
bool System.Collections.Generic.ICollection<System.Text.RegularExpressions.Capture>.Contains(System.Text.RegularExpressions.Capture item) { throw null; }
bool System.Collections.Generic.ICollection<System.Text.RegularExpressions.Capture>.Remove(System.Text.RegularExpressions.Capture item) { throw null; }
int System.Collections.IList.Add(object value) { throw null; }
void System.Collections.IList.Clear() { }
bool System.Collections.IList.Contains(object value) { throw null; }
int System.Collections.IList.IndexOf(object value) { throw null; }
void System.Collections.IList.Insert(int index, object value) { }
bool System.Collections.IList.IsFixedSize { get { throw null; } }
void System.Collections.IList.Remove(object value) { }
void System.Collections.IList.RemoveAt(int index) { }
object System.Collections.IList.this[int index] { get { throw null; } set { } }
}
public partial class GroupCollection : System.Collections.Generic.ICollection<System.Text.RegularExpressions.Group>, System.Collections.Generic.IEnumerable<System.Text.RegularExpressions.Group>, System.Collections.Generic.IList<System.Text.RegularExpressions.Group>, System.Collections.Generic.IReadOnlyCollection<System.Text.RegularExpressions.Group>, System.Collections.Generic.IReadOnlyList<System.Text.RegularExpressions.Group>, System.Collections.ICollection, System.Collections.IEnumerable, System.Collections.IList
{
public void CopyTo(System.Text.RegularExpressions.Group[] array, int arrayIndex) { }
System.Collections.Generic.IEnumerator<System.Text.RegularExpressions.Group> System.Collections.Generic.IEnumerable<System.Text.RegularExpressions.Group>.GetEnumerator() { throw null; }
int System.Collections.Generic.IList<System.Text.RegularExpressions.Group>.IndexOf(System.Text.RegularExpressions.Group item) { throw null; }
void System.Collections.Generic.IList<System.Text.RegularExpressions.Group>.Insert(int index, System.Text.RegularExpressions.Group item) { }
void System.Collections.Generic.IList<System.Text.RegularExpressions.Group>.RemoveAt(int index) { }
System.Text.RegularExpressions.Group System.Collections.Generic.IList<System.Text.RegularExpressions.Group>.this[int index] { get { throw null; } set { } }
void System.Collections.Generic.ICollection<System.Text.RegularExpressions.Group>.Add(System.Text.RegularExpressions.Group item) { }
void System.Collections.Generic.ICollection<System.Text.RegularExpressions.Group>.Clear() { }
bool System.Collections.Generic.ICollection<System.Text.RegularExpressions.Group>.Contains(System.Text.RegularExpressions.Group item) { throw null; }
bool System.Collections.Generic.ICollection<System.Text.RegularExpressions.Group>.Remove(System.Text.RegularExpressions.Group item) { throw null; }
int System.Collections.IList.Add(object value) { throw null; }
void System.Collections.IList.Clear() { }
bool System.Collections.IList.Contains(object value) { throw null; }
int System.Collections.IList.IndexOf(object value) { throw null; }
void System.Collections.IList.Insert(int index, object value) { }
bool System.Collections.IList.IsFixedSize { get { throw null; } }
void System.Collections.IList.Remove(object value) { }
void System.Collections.IList.RemoveAt(int index) { }
object System.Collections.IList.this[int index] { get { throw null; } set { } }
}
public partial class MatchCollection : System.Collections.Generic.ICollection<System.Text.RegularExpressions.Match>, System.Collections.Generic.IEnumerable<System.Text.RegularExpressions.Match>, System.Collections.Generic.IList<System.Text.RegularExpressions.Match>, System.Collections.Generic.IReadOnlyCollection<System.Text.RegularExpressions.Match>, System.Collections.Generic.IReadOnlyList<System.Text.RegularExpressions.Match>, System.Collections.ICollection, System.Collections.IEnumerable, System.Collections.IList
{
public void CopyTo(System.Text.RegularExpressions.Match[] array, int arrayIndex) { }
System.Collections.Generic.IEnumerator<System.Text.RegularExpressions.Match> System.Collections.Generic.IEnumerable<System.Text.RegularExpressions.Match>.GetEnumerator() { throw null; }
int System.Collections.Generic.IList<System.Text.RegularExpressions.Match>.IndexOf(System.Text.RegularExpressions.Match item) { throw null; }
void System.Collections.Generic.IList<System.Text.RegularExpressions.Match>.Insert(int index, System.Text.RegularExpressions.Match item) { }
void System.Collections.Generic.IList<System.Text.RegularExpressions.Match>.RemoveAt(int index) { }
System.Text.RegularExpressions.Match System.Collections.Generic.IList<System.Text.RegularExpressions.Match>.this[int index] { get { throw null; } set { } }
void System.Collections.Generic.ICollection<System.Text.RegularExpressions.Match>.Add(System.Text.RegularExpressions.Match item) { }
void System.Collections.Generic.ICollection<System.Text.RegularExpressions.Match>.Clear() { }
bool System.Collections.Generic.ICollection<System.Text.RegularExpressions.Match>.Contains(System.Text.RegularExpressions.Match item) { throw null; }
bool System.Collections.Generic.ICollection<System.Text.RegularExpressions.Match>.Remove(System.Text.RegularExpressions.Match item) { throw null; }
int System.Collections.IList.Add(object value) { throw null; }
void System.Collections.IList.Clear() { }
bool System.Collections.IList.Contains(object value) { throw null; }
int System.Collections.IList.IndexOf(object value) { throw null; }
void System.Collections.IList.Insert(int index, object value) { }
bool System.Collections.IList.IsFixedSize { get { throw null; } }
void System.Collections.IList.Remove(object value) { }
void System.Collections.IList.RemoveAt(int index) { }
object System.Collections.IList.this[int index] { get { throw null; } set { } }
}
}
3 changes: 2 additions & 1 deletion src/System.Text.RegularExpressions/ref/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"System.Collections.NonGeneric": "4.4.0-beta-24612-03"
},
"frameworks": {
"netstandard1.7": {}
"netstandard1.7": {},
"netcoreapp1.1": {},
}
}
6 changes: 6 additions & 0 deletions src/System.Text.RegularExpressions/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<data name="AlternationCantHaveComment" xml:space="preserve">
<value>Alternation conditions cannot be comments.</value>
</data>
<data name="Arg_ArrayPlusOffTooSmall" xml:space="preserve">
<value>Destination array is not long enough to copy all the items in the collection. Check array index and length.</value>
</data>
<data name="BadClassInCharRange" xml:space="preserve">
<value>Cannot include class \\{0} in character range.</value>
</data>
Expand Down Expand Up @@ -186,6 +189,9 @@
<data name="NotEnoughParens" xml:space="preserve">
<value>Not enough )'s.</value>
</data>
<data name="NotSupported_ReadOnlyCollection" xml:space="preserve">
<value>Collection is read-only.</value>
</data>
<data name="OnlyAllowedOnce" xml:space="preserve">
<value>This operation is only allowed once per object.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<Compile Include="System\Text\RegularExpressions\RegexCaptureCollection.cs" />
<Compile Include="System\Text\RegularExpressions\RegexCharClass.cs" />
<Compile Include="System\Text\RegularExpressions\RegexCode.cs" />
<Compile Include="System\Text\RegularExpressions\RegexCollectionDebuggerProxy.cs" />
<Compile Include="System\Text\RegularExpressions\RegexFCD.cs" />
<Compile Include="System\Text\RegularExpressions\RegexGroup.cs" />
<Compile Include="System\Text\RegularExpressions\RegexGroupCollection.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// contained in a compiled Regex.

using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;

namespace System.Text.RegularExpressions
Expand All @@ -19,7 +20,9 @@ namespace System.Text.RegularExpressions
/// Represents a sequence of capture substrings. The object is used
/// to return the set of captures done by a single capturing group.
/// </summary>
public class CaptureCollection : ICollection
[DebuggerDisplay("Count = {Count}")]
[DebuggerTypeProxy(typeof(RegexCollectionDebuggerProxy<Capture>))]
public class CaptureCollection : IList<Capture>, IReadOnlyList<Capture>, IList
{
private readonly Group _group;
private readonly int _capcount;
Expand All @@ -36,26 +39,19 @@ internal CaptureCollection(Group group)
/// <summary>
/// Returns the number of captures.
/// </summary>
public int Count
{
get { return _capcount; }
}
public int Count => _capcount;

/// <summary>
/// Returns a specific capture, by index, in this collection.
/// </summary>
public Capture this[int i]
{
get { return GetCapture(i); }
}
public Capture this[int i] => GetCapture(i);

/// <summary>
/// Provides an enumerator in the same order as Item[].
/// </summary>
public IEnumerator GetEnumerator()
{
return new Enumerator(this);
}
public IEnumerator GetEnumerator() => new Enumerator(this);

IEnumerator<Capture> IEnumerable<Capture>.GetEnumerator() => new Enumerator(this);

/// <summary>
/// Returns the set of captures for the group
Expand All @@ -81,15 +77,9 @@ private Capture GetCapture(int i)
return _captures[i];
}

public bool IsSynchronized
{
get { return false; }
}
public bool IsSynchronized => false;

public object SyncRoot
{
get { return _group; }
}
public object SyncRoot => _group;

public void CopyTo(Array array, int arrayIndex)
{
Expand All @@ -102,7 +92,106 @@ public void CopyTo(Array array, int arrayIndex)
}
}

private class Enumerator : IEnumerator
public void CopyTo(Capture[] array, int arrayIndex)
{
if (array == null)
throw new ArgumentNullException(nameof(array));
if (arrayIndex < 0 || arrayIndex > array.Length)
throw new ArgumentOutOfRangeException(nameof(arrayIndex));
if (array.Length - arrayIndex < Count)
throw new ArgumentException(SR.Arg_ArrayPlusOffTooSmall);

for (int i = arrayIndex, j = 0; j < Count; i++, j++)
{
array[i] = this[j];
}
}

int IList<Capture>.IndexOf(Capture item)
{
var comparer = EqualityComparer<Capture>.Default;
for (int i = 0; i < Count; i++)
{
if (comparer.Equals(this[i], item))
return i;
}
return -1;
}

void IList<Capture>.Insert(int index, Capture item)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}

void IList<Capture>.RemoveAt(int index)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}

Capture IList<Capture>.this[int index]
{
get { return this[index]; }
set { throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection); }
}

void ICollection<Capture>.Add(Capture item)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}

void ICollection<Capture>.Clear()
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}

bool ICollection<Capture>.Contains(Capture item) =>
((IList<Capture>)this).IndexOf(item) >= 0;

bool ICollection<Capture>.Remove(Capture item)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}

int IList.Add(object value)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}

void IList.Clear()
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}

bool IList.Contains(object value) =>
value is Capture && ((ICollection<Capture>)this).Contains((Capture)value);

int IList.IndexOf(object value) =>
value is Capture ? ((IList<Capture>)this).IndexOf((Capture)value) : -1;

void IList.Insert(int index, object value)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}

bool IList.IsFixedSize => true;

void IList.Remove(object value)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}

void IList.RemoveAt(int index)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}

object IList.this[int index]
{
get { return this[index]; }
set { throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection); }
}

private sealed class Enumerator : IEnumerator<Capture>
{
private readonly CaptureCollection _collection;
private int _index;
Expand Down Expand Up @@ -138,15 +227,14 @@ public Capture Current
}
}

object IEnumerator.Current
{
get { return Current; }
}
object IEnumerator.Current => Current;

void IEnumerator.Reset()
{
_index = -1;
}

void IDisposable.Dispose() { }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Diagnostics;

namespace System.Text.RegularExpressions
{
internal sealed class RegexCollectionDebuggerProxy<T>
{
private readonly ICollection<T> _collection;

public RegexCollectionDebuggerProxy(ICollection<T> collection)
{
if (collection == null)
throw new ArgumentNullException(nameof(collection));

_collection = collection;
}

[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public T[] Items
{
get
{
T[] items = new T[_collection.Count];
_collection.CopyTo(items, 0);
return items;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace System.Text.RegularExpressions
public class Group : Capture
{
// the empty group object
internal static Group _emptygroup = new Group(String.Empty, Array.Empty<int>(), 0, string.Empty);
internal static Group s_emptyGroup = new Group(string.Empty, Array.Empty<int>(), 0, string.Empty);

internal readonly int[] _caps;
internal int _capcount;
Expand Down
Loading