1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-16 15:24:10 +02:00

Rework hex parsing flags. New 'Hex' flag, 'AllowHexSpecifier' allows hex

This commit is contained in:
Brian Fiete 2023-06-22 07:52:43 -04:00
parent 4ab140a4f4
commit 269716c0d4
11 changed files with 23 additions and 22 deletions

View file

@ -506,11 +506,11 @@ namespace Beefy.utils
case typeof(Int64): return (.)(int64)val; case typeof(Int64): return (.)(int64)val;
case typeof(Int): return (.)(int)val; case typeof(Int): return (.)(int)val;
case typeof(String): case typeof(String):
if (int32.Parse((String)val) case .Ok(var fVal)) if (int32.Parse((String)val, .AllowHexSpecifier) case .Ok(var fVal))
return (.)fVal; return (.)fVal;
return defaultVal; return defaultVal;
case typeof(StringView): case typeof(StringView):
if (int32.Parse((StringView)val) case .Ok(var fVal)) if (int32.Parse((StringView)val, .AllowHexSpecifier) case .Ok(var fVal))
return (.)fVal; return (.)fVal;
return defaultVal; return defaultVal;
default: return defaultVal; default: return defaultVal;
@ -529,11 +529,11 @@ namespace Beefy.utils
case typeof(Int64): return (.)(int64)val; case typeof(Int64): return (.)(int64)val;
case typeof(Int): return (.)(int)val; case typeof(Int): return (.)(int)val;
case typeof(String): case typeof(String):
if (int64.Parse((String)val) case .Ok(var parsedVal)) if (int64.Parse((String)val, .AllowHexSpecifier) case .Ok(var parsedVal))
return (.)parsedVal; return (.)parsedVal;
return defaultVal; return defaultVal;
case typeof(StringView): case typeof(StringView):
if (int64.Parse((StringView)val) case .Ok(var parsedVal)) if (int64.Parse((StringView)val, .AllowHexSpecifier) case .Ok(var parsedVal))
return (.)parsedVal; return (.)parsedVal;
return defaultVal; return defaultVal;
default: return defaultVal; default: return defaultVal;
@ -552,11 +552,11 @@ namespace Beefy.utils
case typeof(Int64): return (.)(int64)val; case typeof(Int64): return (.)(int64)val;
case typeof(Int): return (.)(int)val; case typeof(Int): return (.)(int)val;
case typeof(String): case typeof(String):
if (int64.Parse((String)val) case .Ok(var parsedVal)) if (int64.Parse((String)val, .AllowHexSpecifier) case .Ok(var parsedVal))
return (.)parsedVal; return (.)parsedVal;
return defaultVal; return defaultVal;
case typeof(StringView): case typeof(StringView):
if (int64.Parse((StringView)val) case .Ok(var parsedVal)) if (int64.Parse((StringView)val, .AllowHexSpecifier) case .Ok(var parsedVal))
return (.)parsedVal; return (.)parsedVal;
return defaultVal; return defaultVal;
default: return defaultVal; default: return defaultVal;
@ -1841,7 +1841,7 @@ namespace Beefy.utils
} }
else else
{ {
var parseVal = int64.Parse(strView); var parseVal = int64.Parse(strView, .AllowHexSpecifier);
if (parseVal case .Ok(var intVal)) if (parseVal case .Ok(var intVal))
aValue = new:mBumpAllocator box intVal; aValue = new:mBumpAllocator box intVal;
else else
@ -2242,7 +2242,7 @@ namespace Beefy.utils
} }
} }
switch (Int64.Parse(value)) switch (Int64.Parse(value, .AllowHexSpecifier))
{ {
case .Err: return null; case .Err: return null;
case .Ok(let num): return new:mBumpAllocator box num; case .Ok(let num): return new:mBumpAllocator box num;

View file

@ -692,11 +692,11 @@ namespace System.Globalization {
} }
// private const NumberStyles InvalidNumberStyles = unchecked((NumberStyles) 0xFFFFFC00); // private const NumberStyles InvalidNumberStyles = unchecked((NumberStyles) 0xFFFFFC00);
private const NumberStyles InvalidNumberStyles = ~(NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite private const NumberStyles InvalidNumberStyles = ~(.AllowLeadingWhite | .AllowTrailingWhite
| NumberStyles.AllowLeadingSign | NumberStyles.AllowTrailingSign | .AllowLeadingSign | .AllowTrailingSign
| NumberStyles.AllowParentheses | NumberStyles.AllowDecimalPoint | .AllowParentheses | .AllowDecimalPoint
| NumberStyles.AllowThousands | NumberStyles.AllowExponent | .AllowThousands | .AllowExponent
| NumberStyles.AllowCurrencySymbol | NumberStyles.AllowHexSpecifier); | .AllowCurrencySymbol | .AllowHexSpecifier | .Hex);
/*internal static void ValidateParseStyleInteger(NumberStyles style) { /*internal static void ValidateParseStyleInteger(NumberStyles style) {
// Check for undefined flags // Check for undefined flags

View file

@ -45,10 +45,11 @@ namespace System.Globalization
AllowHexSpecifier = 0x00000200, //Allow specifiying hexadecimal. AllowHexSpecifier = 0x00000200, //Allow specifiying hexadecimal.
//Common uses. These represent some of the most common combinations of these flags. //Common uses. These represent some of the most common combinations of these flags.
Hex = 0x00000400,
Integer = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign, Integer = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign,
HexNumber = AllowLeadingWhite | AllowTrailingWhite | AllowHexSpecifier, HexNumber = AllowLeadingWhite | AllowTrailingWhite | AllowHexSpecifier | Hex,
Number = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign | AllowTrailingSign | Number = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign | AllowTrailingSign |
AllowDecimalPoint | AllowThousands, AllowDecimalPoint | AllowThousands,

View file

@ -85,7 +85,7 @@ namespace System
bool isNeg = false; bool isNeg = false;
int16 result = 0; int16 result = 0;
int16 radix = style.HasFlag(.AllowHexSpecifier) ? 0x10 : 10; int16 radix = style.HasFlag(.Hex) ? 0x10 : 10;
for (int32 i = 0; i < val.Length; i++) for (int32 i = 0; i < val.Length; i++)
{ {

View file

@ -134,7 +134,7 @@ namespace System
bool isNeg = false; bool isNeg = false;
int32 result = 0; int32 result = 0;
int32 radix = style.HasFlag(.AllowHexSpecifier) ? 0x10 : 10; int32 radix = style.HasFlag(.Hex) ? 0x10 : 10;
for (int32 i = 0; i < val.Length; i++) for (int32 i = 0; i < val.Length; i++)
{ {

View file

@ -115,7 +115,7 @@ namespace System
bool isNeg = false; bool isNeg = false;
int64 result = 0; int64 result = 0;
int64 radix = style.HasFlag(.AllowHexSpecifier) ? 0x10 : 10; int64 radix = style.HasFlag(.Hex) ? 0x10 : 10;
for (int32 i = 0; i < val.Length; i++) for (int32 i = 0; i < val.Length; i++)
{ {

View file

@ -85,7 +85,7 @@ namespace System
bool isNeg = false; bool isNeg = false;
int8 result = 0; int8 result = 0;
int8 radix = style.HasFlag(.AllowHexSpecifier) ? 0x10 : 10; int8 radix = style.HasFlag(.Hex) ? 0x10 : 10;
for (int32 i = 0; i < val.Length; i++) for (int32 i = 0; i < val.Length; i++)
{ {

View file

@ -85,7 +85,7 @@ namespace System
uint16 result = 0; uint16 result = 0;
uint16 prevResult = 0; uint16 prevResult = 0;
uint16 radix = style.HasFlag(.AllowHexSpecifier) ? 0x10 : 10; uint16 radix = style.HasFlag(.Hex) ? 0x10 : 10;
for (int32 i = 0; i < val.Length; i++) for (int32 i = 0; i < val.Length; i++)
{ {

View file

@ -113,7 +113,7 @@ namespace System
uint32 result = 0; uint32 result = 0;
uint32 prevResult = 0; uint32 prevResult = 0;
uint32 radix = style.HasFlag(.AllowHexSpecifier) ? 0x10 : 10; uint32 radix = style.HasFlag(.Hex) ? 0x10 : 10;
for (int32 i = 0; i < val.Length; i++) for (int32 i = 0; i < val.Length; i++)
{ {

View file

@ -97,7 +97,7 @@ namespace System
uint64 result = 0; uint64 result = 0;
uint64 prevResult = 0; uint64 prevResult = 0;
uint64 radix = style.HasFlag(.AllowHexSpecifier) ? 0x10 : 10; uint64 radix = style.HasFlag(.Hex) ? 0x10 : 10;
for (int32 i = 0; i < val.Length; i++) for (int32 i = 0; i < val.Length; i++)
{ {

View file

@ -85,7 +85,7 @@ namespace System
uint8 result = 0; uint8 result = 0;
uint8 prevResult = 0; uint8 prevResult = 0;
uint8 radix = style.HasFlag(.AllowHexSpecifier) ? 0x10 : 10; uint8 radix = style.HasFlag(.Hex) ? 0x10 : 10;
for (int32 i = 0; i < val.Length; i++) for (int32 i = 0; i < val.Length; i++)
{ {