mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-16 23:34:10 +02:00
82 lines
1.4 KiB
Beef
82 lines
1.4 KiB
Beef
![]() |
using System;
|
||
|
|
||
|
namespace System
|
||
|
{
|
||
|
struct Int : int, IInteger, IHashable, IFormattable, IOpComparable, IIsNaN, IOpNegatable, IOpAddable
|
||
|
{
|
||
|
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 value)
|
||
|
{
|
||
|
return (SelfBase)value;
|
||
|
}
|
||
|
|
||
|
int IHashable.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;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|