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

◆ TryParseByteX()

static bool System.Buffers.Text.Utf8Parser.TryParseByteX ( ReadOnlySpan< byte > source,
out byte value,
out int bytesConsumed )
inlinestaticprivate

Definition at line 3110 of file Utf8Parser.cs.

3111 {
3112 if (source.Length < 1)
3113 {
3114 bytesConsumed = 0;
3115 value = 0;
3116 return false;
3117 }
3118 ReadOnlySpan<byte> charToHexLookup = HexConverter.CharToHexLookup;
3119 byte index = source[0];
3120 byte b = charToHexLookup[index];
3121 if (b == byte.MaxValue)
3122 {
3123 bytesConsumed = 0;
3124 value = 0;
3125 return false;
3126 }
3127 uint num = b;
3128 if (source.Length <= 2)
3129 {
3130 for (int i = 1; i < source.Length; i++)
3131 {
3132 index = source[i];
3133 b = charToHexLookup[index];
3134 if (b == byte.MaxValue)
3135 {
3136 bytesConsumed = i;
3137 value = (byte)num;
3138 return true;
3139 }
3140 num = (num << 4) + b;
3141 }
3142 }
3143 else
3144 {
3145 for (int j = 1; j < 2; j++)
3146 {
3147 index = source[j];
3148 b = charToHexLookup[index];
3149 if (b == byte.MaxValue)
3150 {
3151 bytesConsumed = j;
3152 value = (byte)num;
3153 return true;
3154 }
3155 num = (num << 4) + b;
3156 }
3157 for (int k = 2; k < source.Length; k++)
3158 {
3159 index = source[k];
3160 b = charToHexLookup[index];
3161 if (b == byte.MaxValue)
3162 {
3163 bytesConsumed = k;
3164 value = (byte)num;
3165 return true;
3166 }
3167 if (num > 15)
3168 {
3169 bytesConsumed = 0;
3170 value = 0;
3171 return false;
3172 }
3173 num = (num << 4) + b;
3174 }
3175 }
3176 bytesConsumed = source.Length;
3177 value = (byte)num;
3178 return true;
3179 }

References System.HexConverter.CharToHexLookup, System.index, System.source, and System.value.

Referenced by System.Buffers.Text.Utf8Parser.TryParse(), and System.Buffers.Text.Utf8Parser.TryParse().