Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ EmitMatchCharacterClass()

void System.Text.RegularExpressions.RegexCompiler.EmitMatchCharacterClass ( string charClass,
bool caseInsensitive )
inlineprivateinherited

Definition at line 3892 of file RegexCompiler.cs.

3893 {
3894 switch (charClass)
3895 {
3896 case "\0\u0001\0\0":
3897 Pop();
3898 Ldc(1);
3899 return;
3900 case "\0\0\u0001\t":
3902 return;
3903 case "\0\0\u0001\ufff7":
3905 Ldc(0);
3906 Ceq();
3907 return;
3908 case "\0\0\u0001d":
3910 return;
3911 case "\u0001\0\u0001d":
3913 Ldc(0);
3914 Ceq();
3915 return;
3916 }
3917 bool invariant = false;
3918 if (caseInsensitive)
3919 {
3921 if (!invariant)
3922 {
3923 CallToLower();
3924 }
3925 }
3926 if (!invariant && RegexCharClass.TryGetSingleRange(charClass, out var lowInclusive, out var highInclusive))
3927 {
3929 {
3931 Ceq();
3932 }
3933 else
3934 {
3936 Sub();
3938 CltUn();
3939 }
3940 if (RegexCharClass.IsNegated(charClass))
3941 {
3942 Ldc(0);
3943 Ceq();
3944 }
3945 return;
3946 }
3947 if (!invariant && RegexCharClass.TryGetSingleUnicodeCategory(charClass, out var category, out var negated))
3948 {
3950 Ldc((int)category);
3951 Ceq();
3952 if (negated)
3953 {
3954 Ldc(0);
3955 Ceq();
3956 }
3957 return;
3958 }
3959 RentedLocalBuilder tempLocal = RentInt32Local();
3960 RentedLocalBuilder resultLocal;
3961 try
3962 {
3964 if (!invariant)
3965 {
3966 Span<char> chars = stackalloc char[3];
3967 int setChars = RegexCharClass.GetSetChars(charClass, chars);
3968 if (setChars > 0 && !RegexCharClass.IsNegated(charClass))
3969 {
3971 Ldc(chars[0]);
3972 Ceq();
3974 Ldc(chars[1]);
3975 Ceq();
3976 Or();
3977 if (setChars == 3)
3978 {
3980 Ldc(chars[2]);
3981 Ceq();
3982 Or();
3983 }
3984 return;
3985 }
3986 }
3988 try
3989 {
3990 RegexCharClass.CharClassAnalysisResults charClassAnalysisResults = RegexCharClass.Analyze(charClass);
3991 Label l = DefineLabel();
3992 Label l2 = DefineLabel();
3993 if (!invariant)
3994 {
3995 if (charClassAnalysisResults.ContainsNoAscii)
3996 {
3998 Ldc(128);
3999 Blt(l2);
4001 Br(l);
4002 MarkLabel(l2);
4003 Ldc(0);
4005 MarkLabel(l);
4007 return;
4008 }
4009 if (charClassAnalysisResults.AllAsciiContained)
4010 {
4012 Ldc(128);
4013 Blt(l2);
4015 Br(l);
4016 MarkLabel(l2);
4017 Ldc(1);
4019 MarkLabel(l);
4021 return;
4022 }
4023 }
4024 string str = string.Create(8, (charClass, invariant), delegate(Span<char> dest, (string charClass, bool invariant) state)
4025 {
4026 for (int i = 0; i < 128; i++)
4027 {
4028 char c = (char)i;
4029 if (state.invariant ? RegexCharClass.CharInClass(char.ToLowerInvariant(c), state.charClass) : RegexCharClass.CharInClass(c, state.charClass))
4030 {
4031 dest[i >> 4] |= (char)(ushort)(1 << (i & 0xF));
4032 }
4033 }
4034 });
4036 Ldc(128);
4037 Bge(l2);
4038 Ldstr(str);
4040 Ldc(4);
4041 Shr();
4043 Ldc(1);
4045 Ldc(15);
4046 And();
4047 Ldc(31);
4048 And();
4049 Shl();
4050 And();
4051 Ldc(0);
4052 CgtUn();
4054 Br(l);
4055 MarkLabel(l2);
4056 if (charClassAnalysisResults.ContainsOnlyAscii)
4057 {
4058 Ldc(0);
4060 }
4061 else if (charClassAnalysisResults.AllNonAsciiContained)
4062 {
4063 Ldc(1);
4065 }
4066 else
4067 {
4069 }
4070 MarkLabel(l);
4072 }
4073 finally
4074 {
4075 ((IDisposable)resultLocal).Dispose();
4076 }
4077 }
4078 finally
4079 {
4080 ((IDisposable)tempLocal).Dispose();
4081 }
4082 void EmitCharInClass()
4083 {
4085 if (invariant)
4086 {
4087 CallToLower();
4088 }
4092 }
4093 }
static readonly MethodInfo s_charIsWhiteSpaceMethod
static readonly MethodInfo s_stringGetCharsMethod
static readonly MethodInfo s_charIsDigitMethod
static readonly MethodInfo s_charGetUnicodeInfo
static readonly MethodInfo s_charInClassMethod

References System.Text.RegularExpressions.RegexCharClass.Analyze(), System.Text.RegularExpressions.RegexCompiler.And(), System.Reflection.Emit.Bge, System.Reflection.Emit.Blt, System.Reflection.Emit.Br, System.Reflection.Emit.Call, System.Text.RegularExpressions.RegexCompiler.CallToLower(), System.Text.RegularExpressions.RegexCompiler.Ceq(), System.Text.RegularExpressions.RegexCompiler.CgtUn(), System.Text.RegularExpressions.RegexCharClass.CharInClass(), System.chars, System.Text.RegularExpressions.RegexCompiler.CltUn(), System.Text.RegularExpressions.RegexCompiler.DefineLabel(), System.Text.RegularExpressions.RegexCharClass.GetSetChars(), System.Text.RegularExpressions.i, System.Text.RegularExpressions.RegexCharClass.IsNegated(), System.Text.RegularExpressions.RegexCompiler.Ldc(), System.Reflection.Emit.Ldloc, System.Reflection.Emit.Ldstr, System.Text.RegularExpressions.RegexCompiler.MarkLabel(), System.Text.RegularExpressions.RegexCompiler.Or(), System.Text.RegularExpressions.RegexCompiler.Pop(), System.Text.RegularExpressions.RegexCompiler.RentInt32Local(), System.Text.RegularExpressions.RegexCompiler.s_charGetUnicodeInfo, System.Text.RegularExpressions.RegexCompiler.s_charInClassMethod, System.Text.RegularExpressions.RegexCompiler.s_charIsDigitMethod, System.Text.RegularExpressions.RegexCompiler.s_charIsWhiteSpaceMethod, System.Text.RegularExpressions.RegexCompiler.s_stringGetCharsMethod, System.Text.RegularExpressions.RegexCompiler.Shl(), System.Text.RegularExpressions.RegexCompiler.Shr(), System.state, System.Reflection.Emit.Stloc, System.Text.RegularExpressions.str, System.Text.RegularExpressions.RegexCompiler.Sub(), System.Text.RegularExpressions.RegexCharClass.TryGetSingleRange(), System.Text.RegularExpressions.RegexCharClass.TryGetSingleUnicodeCategory(), and System.Text.RegularExpressions.RegexCompiler.UseToLowerInvariant.

Referenced by System.Text.RegularExpressions.RegexCompiler.GenerateFindFirstChar(), System.Text.RegularExpressions.RegexCompiler.GenerateOneCode(), and System.Text.RegularExpressions.RegexCompiler.TryGenerateNonBacktrackingGo().