The Labs \ Source Viewer \ SSCLI \ System \ ParseNumbers

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. /*============================================================
  16. **
  17. ** Class:  ParseNumbers
  18. **
  19. **
  20. ** Purpose: Methods for Parsing numbers and Strings.
  21. ** All methods are implemented in native.
  22. **
  23. **
  24. ===========================================================*/
  25. namespace System
  26. {
  27.    
  28.     //This class contains only static members and does not need to be serializable.
  29.     using System;
  30.     using System.Runtime.CompilerServices;
  31.     static internal class ParseNumbers
  32.     {
  33.         internal const int PrintAsI1 = 64;
  34.         internal const int PrintAsI2 = 128;
  35.         internal const int PrintAsI4 = 256;
  36.         internal const int TreatAsUnsigned = 512;
  37.         internal const int TreatAsI1 = 1024;
  38.         internal const int TreatAsI2 = 2048;
  39.         internal const int IsTight = 4096;
  40.         internal const int NoSpace = 8192;
  41.        
  42.         //
  43.         //
  44.         // NATIVE METHODS
  45.         // For comments on these methods please see $\src\vm\COMUtilNative.cpp
  46.         //
  47.         unsafe public static long StringToLong(string s, int radix, int flags)
  48.         {
  49.             return StringToLong(s, radix, flags, null);
  50.         }
  51.         [MethodImplAttribute(MethodImplOptions.InternalCall)]
  52.         unsafe public static extern long StringToLong(string s, int radix, int flags, int* currPos);
  53.        
  54.         unsafe public static long StringToLong(string s, int radix, int flags, ref int currPos)
  55.         {
  56.             fixed (int* ppos = &currPos) {
  57.                 return StringToLong(s, radix, flags, ppos);
  58.             }
  59.         }
  60.        
  61.         unsafe public static int StringToInt(string s, int radix, int flags)
  62.         {
  63.             return StringToInt(s, radix, flags, null);
  64.         }
  65.         [MethodImplAttribute(MethodImplOptions.InternalCall)]
  66.         unsafe public static extern int StringToInt(string s, int radix, int flags, int* currPos);
  67.        
  68.         unsafe public static int StringToInt(string s, int radix, int flags, ref int currPos)
  69.         {
  70.             fixed (int* ppos = &currPos) {
  71.                 return StringToInt(s, radix, flags, ppos);
  72.             }
  73.         }
  74.        
  75.         [MethodImplAttribute(MethodImplOptions.InternalCall)]
  76.         public static extern string IntToString(int l, int radix, int width, char paddingChar, int flags);
  77.        
  78.         [MethodImplAttribute(MethodImplOptions.InternalCall)]
  79.         public static extern string LongToString(long l, int radix, int width, char paddingChar, int flags);
  80.     }
  81. }

Developer Fusion