summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/ParseNumbers.cs
blob: 5287e2766965a10c18dc545da47c3c465d7709dd (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

/*============================================================
**
**
**
** Purpose: Methods for Parsing numbers and Strings.
** All methods are implemented in native.
**
** 
===========================================================*/

//This class contains only static members and does not need to be serializable.

using System;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;

namespace System
{
    internal static class ParseNumbers
    {
        internal const int PrintAsI1 = 0x40;
        internal const int PrintAsI2 = 0x80;
        internal const int PrintAsI4 = 0x100;
        internal const int TreatAsUnsigned = 0x200;
        internal const int TreatAsI1 = 0x400;
        internal const int TreatAsI2 = 0x800;
        internal const int IsTight = 0x1000;
        internal const int NoSpace = 0x2000;

        //
        //
        // NATIVE METHODS
        // For comments on these methods please see $\src\vm\COMUtilNative.cpp
        //
        public unsafe static long StringToLong(System.String s, int radix, int flags)
        {
            return StringToLong(s, radix, flags, null);
        }
        [MethodImplAttribute(MethodImplOptions.InternalCall)]
        public unsafe extern static long StringToLong(System.String s, int radix, int flags, int* currPos);

        public unsafe static long StringToLong(System.String s, int radix, int flags, ref int currPos)
        {
            fixed (int* ppos = &currPos)
            {
                return StringToLong(s, radix, flags, ppos);
            }
        }

        public unsafe static int StringToInt(System.String s, int radix, int flags)
        {
            return StringToInt(s, radix, flags, null);
        }
        [MethodImplAttribute(MethodImplOptions.InternalCall)]
        public unsafe extern static int StringToInt(System.String s, int radix, int flags, int* currPos);

        public unsafe static int StringToInt(System.String s, int radix, int flags, ref int currPos)
        {
            fixed (int* ppos = &currPos)
            {
                return StringToInt(s, radix, flags, ppos);
            }
        }

        [MethodImplAttribute(MethodImplOptions.InternalCall)]
        public extern static String IntToString(int l, int radix, int width, char paddingChar, int flags);

        [MethodImplAttribute(MethodImplOptions.InternalCall)]
        public extern static String LongToString(long l, int radix, int width, char paddingChar, int flags);
    }
}