forked from CosmosOS/Cosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInt16Impl.cs
59 lines (51 loc) · 1.56 KB
/
Int16Impl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Globalization;
using Cosmos.Common;
using IL2CPU.API;
using IL2CPU.API.Attribs;
namespace Cosmos.System_Plugs.System
{
[Plug(Target = typeof(short))]
public static class Int16Impl
{
//[PlugMethod(Signature = "System_String___System_Int16_ToString____")]
public static string ToString(ref short aThis)
{
return StringHelper.GetNumberString(aThis);
}
public static bool TryParse(string s, NumberStyles style, IFormatProvider provider, out short result)
{
throw new NotImplementedException();
}
public static Int16 Parse(string s)
{
const string digits = "0123456789";
Int16 result = 0;
int z = 0;
bool neg = false;
if (s.Length >= 1)
{
if (s[0] == '+') z = 1;
if (s[0] == '-')
{
z = 1;
neg = true;
}
}
for (int i = z; i < s.Length; i++)
{
Int16 ind = (Int16)digits.IndexOf(s[i]);
if (ind == -1)
{
global::System.Console.Write("Digit '");
global::System.Console.Write(s[i]);
global::System.Console.WriteLine("' not found!");
throw new FormatException();
}
result = (Int16)((result * 10) + ind);
}
if (neg) result *= -1;
return result;
}
}
}