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

◆ TryParseUInt16X()

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

Definition at line 3181 of file Utf8Parser.cs.

3182 {
3183 if (source.Length < 1)
3184 {
3185 bytesConsumed = 0;
3186 value = 0;
3187 return false;
3188 }
3189 ReadOnlySpan<byte> charToHexLookup = HexConverter.CharToHexLookup;
3190 byte index = source[0];
3191 byte b = charToHexLookup[index];
3192 if (b == byte.MaxValue)
3193 {
3194 bytesConsumed = 0;
3195 value = 0;
3196 return false;
3197 }
3198 uint num = b;
3199 if (source.Length <= 4)
3200 {
3201 for (int i = 1; i < source.Length; i++)
3202 {
3203 index = source[i];
3204 b = charToHexLookup[index];
3205 if (b == byte.MaxValue)
3206 {
3207 bytesConsumed = i;
3208 value = (ushort)num;
3209 return true;
3210 }
3211 num = (num << 4) + b;
3212 }
3213 }
3214 else
3215 {
3216 for (int j = 1; j < 4; j++)
3217 {
3218 index = source[j];
3219 b = charToHexLookup[index];
3220 if (b == byte.MaxValue)
3221 {
3222 bytesConsumed = j;
3223 value = (ushort)num;
3224 return true;
3225 }
3226 num = (num << 4) + b;
3227 }
3228 for (int k = 4; k < source.Length; k++)
3229 {
3230 index = source[k];
3231 b = charToHexLookup[index];
3232 if (b == byte.MaxValue)
3233 {
3234 bytesConsumed = k;
3235 value = (ushort)num;
3236 return true;
3237 }
3238 if (num > 4095)
3239 {
3240 bytesConsumed = 0;
3241 value = 0;
3242 return false;
3243 }
3244 num = (num << 4) + b;
3245 }
3246 }
3247 bytesConsumed = source.Length;
3248 value = (ushort)num;
3249 return true;
3250 }

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

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