Imported Upstream version 3.10.0

Former-commit-id: 172c8e3c300b39d5785c7a3e8dfb08ebdbc1a99b
This commit is contained in:
Jo Shields
2014-10-04 11:27:48 +01:00
parent fe777c5c82
commit 8b9b85e7f5
970 changed files with 20242 additions and 31308 deletions

View File

@@ -89,14 +89,16 @@ namespace System.Text.RegularExpressions
if (!regex.RightToLeft && ptr <= input.Length)
splits.Add (input.Substring (ptr));
return splits.ToArray ();
return splits.ToArray ();
}
virtual public Match Scan (Regex regex, string text, int start, int end)
public Match Scan (Regex regex, string text, int start, int end)
{
throw new NotImplementedException ("Scan method must be implemented in derived classes");
return Scan (regex, text, start, end, false);
}
public abstract Match Scan (Regex regex, string text, int start, int end, bool substring_mode);
virtual public string Result (string replacement, Match match)
{
return ReplacementEvaluator.Evaluate (replacement, match);

View File

@@ -41,11 +41,9 @@ namespace System.Text.RegularExpressions {
}
internal static Group Fail = new Group ();
#if !TARGET_JVM
public CaptureCollection Captures {
get { return captures; }
}
#endif
public bool Success {
get { return success; }
}

View File

@@ -91,7 +91,6 @@ namespace System.Text.RegularExpressions {
this.machine = machine;
this.text_length = text_length;
}
#if !TARGET_JVM
internal Match (Regex regex, IMachine machine, string text, int text_length, int n_groups,
int index, int length, int n_caps) :
base (text, index, length, n_caps)
@@ -103,7 +102,6 @@ namespace System.Text.RegularExpressions {
this.groups = new GroupCollection (n_groups, regex.Gap);
groups.SetValue (this, 0);
}
#endif
internal Regex Regex {
get { return regex; }
}

View File

@@ -47,7 +47,7 @@ namespace System.Text.RegularExpressions {
[Serializable]
public partial class Regex : ISerializable {
#if !TARGET_JVM && !FULL_AOT_RUNTIME
#if !FULL_AOT_RUNTIME
[MonoTODO]
public static void CompileToAssembly (RegexCompilationInfo [] regexes, AssemblyName aname)
{
@@ -306,7 +306,6 @@ namespace System.Text.RegularExpressions {
throw new ArgumentOutOfRangeException ("options");
}
#if !TARGET_JVM
private void Init ()
{
this.machineFactory = cache.Lookup (this.pattern, this.roptions);
@@ -320,7 +319,6 @@ namespace System.Text.RegularExpressions {
this.group_names = this.machineFactory.NamesMapping;
}
}
#endif
private void InitNewRegex ()
{
@@ -458,7 +456,7 @@ namespace System.Text.RegularExpressions {
throw new ArgumentNullException ("input");
if (startat < 0 || startat > input.Length)
throw new ArgumentOutOfRangeException ("startat");
return CreateMachine ().Scan (this, input, startat, input.Length);
return CreateMachine ().Scan (this, input, startat, input.Length, false);
}
public Match Match (string input, int beginning, int length)
@@ -469,7 +467,7 @@ namespace System.Text.RegularExpressions {
throw new ArgumentOutOfRangeException ("beginning");
if (length < 0 || length > input.Length - beginning)
throw new ArgumentOutOfRangeException ("length");
return CreateMachine ().Scan (this, input, beginning, beginning + length);
return CreateMachine ().Scan (this, input, beginning, beginning + length, true);
}
public MatchCollection Matches (string input)

View File

@@ -147,7 +147,7 @@ namespace System.Text.RegularExpressions {
ResetGroups ();
}
public override Match Scan (Regex regex, string text, int start, int end) {
public override Match Scan (Regex regex, string text, int start, int end, bool substring_mode) {
str = text;
string_start = start;
string_end = end;

View File

@@ -101,6 +101,7 @@ namespace System.Text.RegularExpressions {
interface IMachine {
Match Scan (Regex regex, string text, int start, int end);
Match Scan (Regex regex, string text, int start, int end, bool substring_mode);
string [] Split (Regex regex, string input, int count, int startat);
string Replace (Regex regex, string input, string replacement, int count, int startat);
string Result (string replacement, Match match);

View File

@@ -61,10 +61,23 @@ namespace System.Text.RegularExpressions {
// IMachine implementation
public override Match Scan (Regex regex, string text, int start, int end) {
public override Match Scan (Regex regex, string text, int start, int end, bool substring_mode) {
this.regex_rtl = (regex.Options & RegexOptions.RightToLeft) != 0;
if (!initialized)
{
this.text_start = regex_rtl && substring_mode ? end : start;
this.text_end = regex_rtl ? substring_mode ? start : 0 : end;
this.initialized = true;
}
else
{
this.text_start = start;
this.text_end = end;
}
this.text = text;
this.text_end = end;
this.scan_ptr = start;
this.scan_ptr = text_start;
this.substring_mode = substring_mode;
if (Eval (Mode.Match, ref scan_ptr, program_start))
return GenerateMatch (regex);
@@ -94,7 +107,7 @@ namespace System.Text.RegularExpressions {
int anch_offset = program[pc + 2];
bool anch_reverse = (flags & OpFlags.RightToLeft) != 0;
int anch_ptr = anch_reverse ? ptr - anch_offset : ptr + anch_offset;
int anch_end = text_end - match_min + anch_offset; // maximum anchor position
int anch_end = (regex_rtl ? text_start : text_end) - match_min + anch_offset; // maximum anchor position
int anch_begin = 0;
@@ -264,7 +277,7 @@ namespace System.Text.RegularExpressions {
if (reverse) {
ptr -= len;
if (ptr < 0)
if ((!regex_rtl && ptr < 0) || (regex_rtl && ptr < text_end))
goto Fail;
}
else
@@ -298,7 +311,7 @@ namespace System.Text.RegularExpressions {
if (reverse) {
ptr -= len;
if (ptr < 0)
if ((!regex_rtl && ptr < 0) || (regex_rtl && ptr < text_end))
goto Fail;
}
else if (ptr + len > text_end)
@@ -626,7 +639,7 @@ namespace System.Text.RegularExpressions {
while (true) {
int p = ptr + coff;
if (c1 < 0 || (p >= 0 && p < text_end && (c1 == text[p] || c2 == text[p]))) {
if (c1 < 0 || (p >= 0 && ((regex_rtl && p >= text_end) || (!regex_rtl && p < text_end)) && (c1 == text[p] || c2 == text[p]))) {
deep = null;
if (Eval (Mode.Match, ref ptr, pc))
break;
@@ -662,7 +675,7 @@ namespace System.Text.RegularExpressions {
while (true) {
int p = ptr + coff;
if (c1 < 0 || (p >= 0 && p < text_end && (c1 == text[p] || c2 == text[p]))) {
if (c1 < 0 || (p >= 0 && ((regex_rtl && p >= text_end) || (!regex_rtl && p < text_end)) && (c1 == text[p] || c2 == text[p]))) {
deep = null;
if (Eval (Mode.Match, ref ptr, pc))
break;
@@ -742,13 +755,13 @@ namespace System.Text.RegularExpressions {
if (!consumed) {
if ((flags & OpFlags.RightToLeft) != 0) {
if (ptr <= 0)
if ((substring_mode && ptr <= (regex_rtl ? text_end : text_start)) || (!substring_mode && ptr <= 0))
return false;
c = text[-- ptr];
}
else {
if (ptr >= text_end)
if ((!regex_rtl && ptr >= text_end) || (regex_rtl && ptr >= text_start))
return false;
c = text[ptr ++];
@@ -837,42 +850,42 @@ namespace System.Text.RegularExpressions {
private bool IsPosition (Position pos, int ptr) {
switch (pos) {
case Position.Start: case Position.StartOfString:
return ptr == 0;
return ptr == 0 || (substring_mode && ((!regex_rtl && ptr == text_start) || (regex_rtl && ptr == text_end)));
case Position.StartOfLine:
return ptr == 0 || text[ptr - 1] == '\n';
return ptr == 0 || text[ptr - 1] == '\n' || (substring_mode && ((!regex_rtl && ptr == text_start) || (regex_rtl && ptr == text_end)));
case Position.StartOfScan:
return ptr == scan_ptr;
case Position.End:
return ptr == text_end ||
(ptr == text_end - 1 && text[ptr] == '\n');
return (!regex_rtl && ptr == text_end) || (regex_rtl && ptr == text_start) ||
(((!regex_rtl && ptr == text_end - 1) || (regex_rtl && ptr == text_start - 1)) && text[ptr] == '\n');
case Position.EndOfLine:
return ptr == text_end || text[ptr] == '\n';
return (!regex_rtl && ptr == text_end) || (regex_rtl && ptr == text_start) || text[ptr] == '\n';
case Position.EndOfString:
return ptr == text_end;
return (!regex_rtl && ptr == text_end) || (regex_rtl && ptr == text_start);
case Position.Boundary:
if (text_end == 0)
if ((!regex_rtl && text_end == 0) || (regex_rtl && text_start == 0))
return false;
if (ptr == 0)
return IsWordChar (text[ptr]);
else if (ptr == text_end)
else if ((!regex_rtl && ptr == text_end) || (regex_rtl && ptr == text_start))
return IsWordChar (text[ptr - 1]);
else
return IsWordChar (text[ptr]) != IsWordChar (text[ptr - 1]);
case Position.NonBoundary:
if (text_end == 0)
if ((!regex_rtl && text_end == 0) || (regex_rtl && text_start == 0))
return false;
if (ptr == 0)
return !IsWordChar (text[ptr]);
else if (ptr == text_end)
else if ((!regex_rtl && ptr == text_end) || (regex_rtl && ptr == text_start))
return !IsWordChar (text[ptr - 1]);
else
return IsWordChar (text[ptr]) == IsWordChar (text[ptr - 1]);
@@ -1051,6 +1064,11 @@ namespace System.Text.RegularExpressions {
private int match_min;//, match_max; // match width information
private QuickSearch qs; // fast substring matcher
private bool regex_rtl;
private int text_start;
private bool substring_mode;
private bool initialized;
// match state
private int scan_ptr; // start of scan