Skip to content

Commit

Permalink
Improve field names
Browse files Browse the repository at this point in the history
  • Loading branch information
justinvp committed Jan 15, 2015
1 parent 00c7f03 commit 8dc937b
Showing 1 changed file with 69 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ namespace System.Text.RegularExpressions
{
internal sealed class RegexInterpreter : RegexRunner
{
private readonly RegexCode _runcode;
private readonly CultureInfo _runculture;
private int _runoperator;
private int _runcodepos;
private bool _runrtl;
private bool _runci;
private readonly RegexCode _code;
private readonly CultureInfo _culture;
private int _operator;
private int _codepos;
private bool _rightToLeft;
private bool _caseInsensitive;

internal RegexInterpreter(RegexCode code, CultureInfo culture)
{
Debug.Assert(code != null, "code cannot be null.");
Debug.Assert(culture != null, "culture cannot be null.");

_runcode = code;
_runculture = culture;
_code = code;
_culture = culture;
}

protected override void InitTrackCount()
{
_runtrackcount = _runcode._trackcount;
_runtrackcount = _code._trackcount;
}

private void Advance()
Expand All @@ -41,18 +41,18 @@ private void Advance()

private void Advance(int i)
{
_runcodepos += (i + 1);
SetOperator(_runcode._codes[_runcodepos]);
_codepos += (i + 1);
SetOperator(_code._codes[_codepos]);
}

private void Goto(int newpos)
{
// when branching backward, ensure storage
if (newpos < _runcodepos)
if (newpos < _codepos)
EnsureStorage();

SetOperator(_runcode._codes[newpos]);
_runcodepos = newpos;
SetOperator(_code._codes[newpos]);
_codepos = newpos;
}

private void Textto(int newpos)
Expand Down Expand Up @@ -83,41 +83,41 @@ private int Trackpos()

private void TrackPush()
{
_runtrack[--_runtrackpos] = _runcodepos;
_runtrack[--_runtrackpos] = _codepos;
}

private void TrackPush(int I1)
{
_runtrack[--_runtrackpos] = I1;
_runtrack[--_runtrackpos] = _runcodepos;
_runtrack[--_runtrackpos] = _codepos;
}

private void TrackPush(int I1, int I2)
{
_runtrack[--_runtrackpos] = I1;
_runtrack[--_runtrackpos] = I2;
_runtrack[--_runtrackpos] = _runcodepos;
_runtrack[--_runtrackpos] = _codepos;
}

private void TrackPush(int I1, int I2, int I3)
{
_runtrack[--_runtrackpos] = I1;
_runtrack[--_runtrackpos] = I2;
_runtrack[--_runtrackpos] = I3;
_runtrack[--_runtrackpos] = _runcodepos;
_runtrack[--_runtrackpos] = _codepos;
}

private void TrackPush2(int I1)
{
_runtrack[--_runtrackpos] = I1;
_runtrack[--_runtrackpos] = -_runcodepos;
_runtrack[--_runtrackpos] = -_codepos;
}

private void TrackPush2(int I1, int I2)
{
_runtrack[--_runtrackpos] = I1;
_runtrack[--_runtrackpos] = I2;
_runtrack[--_runtrackpos] = -_runcodepos;
_runtrack[--_runtrackpos] = -_codepos;
}

private void Backtrack()
Expand All @@ -136,25 +136,25 @@ private void Backtrack()
if (newpos < 0)
{
newpos = -newpos;
SetOperator(_runcode._codes[newpos] | RegexCode.Back2);
SetOperator(_code._codes[newpos] | RegexCode.Back2);
}
else
{
SetOperator(_runcode._codes[newpos] | RegexCode.Back);
SetOperator(_code._codes[newpos] | RegexCode.Back);
}

// When branching backward, ensure storage
if (newpos < _runcodepos)
if (newpos < _codepos)
EnsureStorage();

_runcodepos = newpos;
_codepos = newpos;
}

private void SetOperator(int op)
{
_runci = (0 != (op & RegexCode.Ci));
_runrtl = (0 != (op & RegexCode.Rtl));
_runoperator = op & ~(RegexCode.Rtl | RegexCode.Ci);
_caseInsensitive = (0 != (op & RegexCode.Ci));
_rightToLeft = (0 != (op & RegexCode.Rtl));
_operator = op & ~(RegexCode.Rtl | RegexCode.Ci);
}

private void TrackPop()
Expand Down Expand Up @@ -223,12 +223,12 @@ private int StackPeek(int i)

private int Operator()
{
return _runoperator;
return _operator;
}

private int Operand(int i)
{
return _runcode._codes[_runcodepos + i + 1];
return _code._codes[_codepos + i + 1];
}

private int Leftchars()
Expand All @@ -243,27 +243,27 @@ private int Rightchars()

private int Bump()
{
return _runrtl ? -1 : 1;
return _rightToLeft ? -1 : 1;
}

private int Forwardchars()
{
return _runrtl ? _runtextpos - _runtextbeg : _runtextend - _runtextpos;
return _rightToLeft ? _runtextpos - _runtextbeg : _runtextend - _runtextpos;
}

private char Forwardcharnext()
{
char ch = (_runrtl ? _runtext[--_runtextpos] : _runtext[_runtextpos++]);
char ch = (_rightToLeft ? _runtext[--_runtextpos] : _runtext[_runtextpos++]);

return (_runci ? _runculture.TextInfo.ToLower(ch) : ch);
return (_caseInsensitive ? _culture.TextInfo.ToLower(ch) : ch);
}

private bool Stringmatch(String str)
{
int c;
int pos;

if (!_runrtl)
if (!_rightToLeft)
{
if (_runtextend - _runtextpos < (c = str.Length))
return false;
Expand All @@ -278,7 +278,7 @@ private bool Stringmatch(String str)
pos = _runtextpos;
}

if (!_runci)
if (!_caseInsensitive)
{
while (c != 0)
if (str[--c] != _runtext[--pos])
Expand All @@ -287,11 +287,11 @@ private bool Stringmatch(String str)
else
{
while (c != 0)
if (str[--c] != _runculture.TextInfo.ToLower(_runtext[--pos]))
if (str[--c] != _culture.TextInfo.ToLower(_runtext[--pos]))
return false;
}

if (!_runrtl)
if (!_rightToLeft)
{
pos += str.Length;
}
Expand All @@ -307,7 +307,7 @@ private bool Refmatch(int index, int len)
int pos;
int cmpos;

if (!_runrtl)
if (!_rightToLeft)
{
if (_runtextend - _runtextpos < len)
return false;
Expand All @@ -325,7 +325,7 @@ private bool Refmatch(int index, int len)

c = len;

if (!_runci)
if (!_caseInsensitive)
{
while (c-- != 0)
if (_runtext[--cmpos] != _runtext[--pos])
Expand All @@ -334,11 +334,11 @@ private bool Refmatch(int index, int len)
else
{
while (c-- != 0)
if (_runculture.TextInfo.ToLower(_runtext[--cmpos]) != _runculture.TextInfo.ToLower(_runtext[--pos]))
if (_culture.TextInfo.ToLower(_runtext[--cmpos]) != _culture.TextInfo.ToLower(_runtext[--pos]))
return false;
}

if (!_runrtl)
if (!_rightToLeft)
{
pos += len;
}
Expand All @@ -350,7 +350,7 @@ private bool Refmatch(int index, int len)

private void Backwardnext()
{
_runtextpos += _runrtl ? 1 : -1;
_runtextpos += _rightToLeft ? 1 : -1;
}

private char CharAt(int j)
Expand All @@ -363,68 +363,68 @@ protected override bool FindFirstChar()
int i;
String set;

if (0 != (_runcode._anchors & (RegexFCD.Beginning | RegexFCD.Start | RegexFCD.EndZ | RegexFCD.End)))
if (0 != (_code._anchors & (RegexFCD.Beginning | RegexFCD.Start | RegexFCD.EndZ | RegexFCD.End)))
{
if (!_runcode._rightToLeft)
if (!_code._rightToLeft)
{
if ((0 != (_runcode._anchors & RegexFCD.Beginning) && _runtextpos > _runtextbeg) ||
(0 != (_runcode._anchors & RegexFCD.Start) && _runtextpos > _runtextstart))
if ((0 != (_code._anchors & RegexFCD.Beginning) && _runtextpos > _runtextbeg) ||
(0 != (_code._anchors & RegexFCD.Start) && _runtextpos > _runtextstart))
{
_runtextpos = _runtextend;
return false;
}
if (0 != (_runcode._anchors & RegexFCD.EndZ) && _runtextpos < _runtextend - 1)
if (0 != (_code._anchors & RegexFCD.EndZ) && _runtextpos < _runtextend - 1)
{
_runtextpos = _runtextend - 1;
}
else if (0 != (_runcode._anchors & RegexFCD.End) && _runtextpos < _runtextend)
else if (0 != (_code._anchors & RegexFCD.End) && _runtextpos < _runtextend)
{
_runtextpos = _runtextend;
}
}
else
{
if ((0 != (_runcode._anchors & RegexFCD.End) && _runtextpos < _runtextend) ||
(0 != (_runcode._anchors & RegexFCD.EndZ) && (_runtextpos < _runtextend - 1 ||
if ((0 != (_code._anchors & RegexFCD.End) && _runtextpos < _runtextend) ||
(0 != (_code._anchors & RegexFCD.EndZ) && (_runtextpos < _runtextend - 1 ||
(_runtextpos == _runtextend - 1 && CharAt(_runtextpos) != '\n'))) ||
(0 != (_runcode._anchors & RegexFCD.Start) && _runtextpos < _runtextstart))
(0 != (_code._anchors & RegexFCD.Start) && _runtextpos < _runtextstart))
{
_runtextpos = _runtextbeg;
return false;
}
if (0 != (_runcode._anchors & RegexFCD.Beginning) && _runtextpos > _runtextbeg)
if (0 != (_code._anchors & RegexFCD.Beginning) && _runtextpos > _runtextbeg)
{
_runtextpos = _runtextbeg;
}
}

if (_runcode._bmPrefix != null)
if (_code._bmPrefix != null)
{
return _runcode._bmPrefix.IsMatch(_runtext, _runtextpos, _runtextbeg, _runtextend);
return _code._bmPrefix.IsMatch(_runtext, _runtextpos, _runtextbeg, _runtextend);
}

return true; // found a valid start or end anchor
}
else if (_runcode._bmPrefix != null)
else if (_code._bmPrefix != null)
{
_runtextpos = _runcode._bmPrefix.Scan(_runtext, _runtextpos, _runtextbeg, _runtextend);
_runtextpos = _code._bmPrefix.Scan(_runtext, _runtextpos, _runtextbeg, _runtextend);

if (_runtextpos == -1)
{
_runtextpos = (_runcode._rightToLeft ? _runtextbeg : _runtextend);
_runtextpos = (_code._rightToLeft ? _runtextbeg : _runtextend);
return false;
}

return true;
}
else if (_runcode._fcPrefix == null)
else if (_code._fcPrefix == null)
{
return true;
}

_runrtl = _runcode._rightToLeft;
_runci = _runcode._fcPrefix.CaseInsensitive;
set = _runcode._fcPrefix.Prefix;
_rightToLeft = _code._rightToLeft;
_caseInsensitive = _code._fcPrefix.CaseInsensitive;
set = _code._fcPrefix.Prefix;

if (RegexCharClass.IsSingleton(set))
{
Expand Down Expand Up @@ -886,15 +886,15 @@ protected override void Go()
continue;

case RegexCode.Set:
if (Forwardchars() < 1 || !RegexCharClass.CharInClass(Forwardcharnext(), _runcode._strings[Operand(0)]))
if (Forwardchars() < 1 || !RegexCharClass.CharInClass(Forwardcharnext(), _code._strings[Operand(0)]))
break;

Advance(1);
continue;

case RegexCode.Multi:
{
if (!Stringmatch(_runcode._strings[Operand(0)]))
if (!Stringmatch(_code._strings[Operand(0)]))
break;

Advance(1);
Expand Down Expand Up @@ -961,7 +961,7 @@ protected override void Go()
if (Forwardchars() < c)
break;

String set = _runcode._strings[Operand(0)];
String set = _code._strings[Operand(0)];

while (c-- > 0)
if (!RegexCharClass.CharInClass(Forwardcharnext(), set))
Expand Down Expand Up @@ -1030,7 +1030,7 @@ protected override void Go()
if (c > Forwardchars())
c = Forwardchars();

String set = _runcode._strings[Operand(0)];
String set = _code._strings[Operand(0)];
int i;

for (i = c; i > 0; i--)
Expand Down Expand Up @@ -1151,7 +1151,7 @@ protected override void Go()
int pos = TrackPeek(1);
Textto(pos);

if (!RegexCharClass.CharInClass(Forwardcharnext(), _runcode._strings[Operand(0)]))
if (!RegexCharClass.CharInClass(Forwardcharnext(), _code._strings[Operand(0)]))
break;

int i = TrackPeek();
Expand Down Expand Up @@ -1179,9 +1179,9 @@ protected override void Go()
internal override void DumpState()
{
base.DumpState();
Debug.WriteLine(" " + _runcode.OpcodeDescription(_runcodepos) +
((_runoperator & RegexCode.Back) != 0 ? " Back" : "") +
((_runoperator & RegexCode.Back2) != 0 ? " Back2" : ""));
Debug.WriteLine(" " + _code.OpcodeDescription(_codepos) +
((_operator & RegexCode.Back) != 0 ? " Back" : "") +
((_operator & RegexCode.Back2) != 0 ? " Back2" : ""));
Debug.WriteLine("");
}
#endif
Expand Down

0 comments on commit 8dc937b

Please sign in to comment.