mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-18 16:10:26 +02:00
86 lines
1.5 KiB
Beef
86 lines
1.5 KiB
Beef
using System;
|
|
|
|
namespace System
|
|
{
|
|
struct Int : int, IInteger, IHashable, IFormattable, IOpComparable, IIsNaN, IOpNegatable, IOpAddable, IOpSubtractable
|
|
{
|
|
public enum ParseError
|
|
{
|
|
case Ok;
|
|
case NoValue;
|
|
case InvalidChar(int partialResult);
|
|
}
|
|
|
|
public static int operator<=>(Self a, Self b)
|
|
{
|
|
return (SelfBase)a <=> (SelfBase)b;
|
|
}
|
|
|
|
public static Self operator+(Self lhs, Self rhs)
|
|
{
|
|
return (SelfBase)lhs + (SelfBase)rhs;
|
|
}
|
|
|
|
public static Self operator-(Self lhs, Self rhs)
|
|
{
|
|
return (SelfBase)lhs - (SelfBase)rhs;
|
|
}
|
|
|
|
public static Self operator-(Self value)
|
|
{
|
|
return (SelfBase)value;
|
|
}
|
|
|
|
public int GetHashCode()
|
|
{
|
|
return (int)this;
|
|
}
|
|
|
|
bool IIsNaN.IsNaN
|
|
{
|
|
[SkipCall]
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
|
{
|
|
if (sizeof(int) == sizeof(int64))
|
|
{
|
|
((int64)this).ToString(outString, format, formatProvider);
|
|
}
|
|
else
|
|
{
|
|
((int32)this).ToString(outString, format, formatProvider);
|
|
}
|
|
}
|
|
|
|
public override void ToString(String outString)
|
|
{
|
|
if (sizeof(int) == sizeof(int64))
|
|
{
|
|
((int64)this).ToString(outString);
|
|
}
|
|
else
|
|
{
|
|
((int32)this).ToString(outString);
|
|
}
|
|
}
|
|
|
|
public static Result<int, ParseError> Parse(StringView val)
|
|
{
|
|
if (sizeof(int) == sizeof(int64))
|
|
{
|
|
var result = Int64.Parse(val);
|
|
return *(Result<int, ParseError>*)&result;
|
|
}
|
|
else
|
|
{
|
|
var result = Int32.Parse(val);
|
|
return *(Result<int, ParseError>*)&result;
|
|
}
|
|
}
|
|
}
|
|
}
|