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 @@ -21,7 +21,16 @@ public ValueListBuilder(Span<T> initialSpan)
_pos = 0;
}

public int Length => _pos;
public int Length
{
get => _pos;
set
{
Debug.Assert(value >= 0);
Debug.Assert(value <= _span.Length);
_pos = value;
}
}

public ref T this[int index]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,16 @@ private Regex(string pattern, RegexOptions options, TimeSpan matchTimeout, bool
internalMatchTimeout = matchTimeout;

// Cache handling. Try to look up this regex in the cache.
string cultureKey = (options & RegexOptions.CultureInvariant) != 0 ?
CultureInfo.InvariantCulture.ToString() :
CultureInfo.CurrentCulture.ToString();
var key = new CachedCodeEntryKey(options, cultureKey, pattern);
CultureInfo culture = (options & RegexOptions.CultureInvariant) != 0 ?
CultureInfo.InvariantCulture :
CultureInfo.CurrentCulture;
var key = new CachedCodeEntryKey(options, culture.ToString(), pattern);
CachedCodeEntry cached = GetCachedCode(key, false);

if (cached == null)
{
// Parse the input
RegexTree tree = RegexParser.Parse(pattern, roptions);
RegexTree tree = RegexParser.Parse(pattern, roptions, culture);

// Extract the relevant information
capnames = tree.CapNames;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;

namespace System.Text.RegularExpressions
{
Expand All @@ -39,20 +37,7 @@ public RegexBoyerMoore(string pattern, bool caseInsensitive, bool rightToLeft, C
// Sorry, you just can't use Boyer-Moore to find an empty pattern.
// We're doing this for your own protection. (Really, for speed.)
Debug.Assert(pattern.Length != 0, "RegexBoyerMoore called with an empty string. This is bad for perf");

if (caseInsensitive)
{
pattern = string.Create(pattern.Length, (pattern, culture), (span, state) =>
{
// We do the ToLower character by character for consistency. With surrogate chars, doing
// a ToLower on the entire string could actually change the surrogate pair. This is more correct
// linguistically, but since Regex doesn't support surrogates, it's more important to be
// consistent.
TextInfo textInfo = state.culture.TextInfo;
for (int i = 0; i < state.pattern.Length; i++)
span[i] = textInfo.ToLower(state.pattern[i]);
});
}
Debug.Assert(!caseInsensitive || pattern.ToLower(culture) == pattern, "RegexBoyerMoore called with a pattern which is not lowercased with caseInsensitive true.");

Pattern = pattern;
RightToLeft = rightToLeft;
Expand Down Expand Up @@ -229,17 +214,7 @@ private bool MatchPattern(string text, int index)
return false;
}

TextInfo textinfo = _culture.TextInfo;
for (int i = 0; i < Pattern.Length; i++)
{
Debug.Assert(textinfo.ToLower(Pattern[i]) == Pattern[i], "pattern should be converted to lower case in constructor!");
if (textinfo.ToLower(text[index + i]) != Pattern[i])
{
return false;
}
}

return true;
return (0 == string.Compare(Pattern, 0, text, index, Pattern.Length, CaseInsensitive, _culture));
}
else
{
Expand Down
Loading