PageRenderTime 566ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/corlib/System.Globalization/NumberFormatInfo.cs

https://bitbucket.org/cosi2/dotnetanywhere-wb
C# | 183 lines | 164 code | 17 blank | 2 comment | 5 complexity | fc4fc6df2b3abfc321d71c7b4430fc15 MD5 | raw file
  1. #if !LOCALTEST
  2. using System.Threading;
  3. using System.IO;
  4. namespace System.Globalization {
  5. public class NumberFormatInfo : IFormatProvider {
  6. #region Static Methods/Properties
  7. private static string[] defaultNativeDigits = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
  8. public static NumberFormatInfo CurrentInfo {
  9. get {
  10. NumberFormatInfo nfi = Thread.CurrentThread.CurrentCulture.NumberFormat;
  11. return nfi;
  12. }
  13. }
  14. public static NumberFormatInfo InvariantInfo {
  15. get {
  16. NumberFormatInfo nfi = new NumberFormatInfo();
  17. nfi.isReadOnly = true;
  18. return nfi;
  19. }
  20. }
  21. public static NumberFormatInfo GetInstance(IFormatProvider provider) {
  22. if (provider != null) {
  23. NumberFormatInfo nfi;
  24. nfi = (NumberFormatInfo)provider.GetFormat(typeof(NumberFormatInfo));
  25. if (nfi != null) {
  26. return nfi;
  27. }
  28. }
  29. return CurrentInfo;
  30. }
  31. #endregion
  32. private bool isReadOnly;
  33. private int currencyDecimalDigits;
  34. private string currencyDecimalSeparator;
  35. private string currencyGroupSeparator;
  36. private int[] currencyGroupSizes;
  37. private int currencyNegativePattern;
  38. private int currencyPositivePattern;
  39. private string currencySymbol;
  40. private DigitShapes digitSubstitution;
  41. private string naNSymbol;
  42. private string[] nativeDigits;
  43. private string negativeInfinitySymbol;
  44. private string negativeSign;
  45. private int numberDecimalDigits;
  46. private string numberDecimalSeparator;
  47. private string numberGroupSeparator;
  48. private int[] numberGroupSizes;
  49. private int numberNegativePattern;
  50. private int percentDecimalDigits;
  51. private string percentDecimalSeparator;
  52. private string percentGroupSeparator;
  53. private int[] percentGroupSizes;
  54. private int percentNegativePattern;
  55. private int percentPositivePattern;
  56. private string percentSymbol;
  57. private string perMilleSymbol;
  58. private string positiveInfinitySymbol;
  59. private string positiveSign;
  60. private static int[] ConvertToIntArray(string s) {
  61. string[] list = s.Split(',');
  62. int listLen = list.Length;
  63. int[] ret = new int[listLen];
  64. for (int i = 0; i < listLen; i++) {
  65. ret[i] = int.Parse(list[i]);
  66. }
  67. return ret;
  68. }
  69. internal NumberFormatInfo(StreamReader s) {
  70. this.isReadOnly = true;
  71. // Sets up information from stream
  72. this.currencyDecimalDigits = int.Parse(s.ReadLine());
  73. this.currencyDecimalSeparator = s.ReadLine();
  74. this.currencyGroupSeparator = s.ReadLine();
  75. this.currencyGroupSizes = ConvertToIntArray(s.ReadLine());
  76. this.currencyNegativePattern = int.Parse(s.ReadLine());
  77. this.currencyPositivePattern = int.Parse(s.ReadLine());
  78. this.currencySymbol = s.ReadLine();
  79. this.digitSubstitution = (DigitShapes)int.Parse(s.ReadLine());
  80. this.naNSymbol = s.ReadLine();
  81. this.nativeDigits = s.ReadLine().Split(',');
  82. this.negativeInfinitySymbol = s.ReadLine();
  83. this.negativeSign = s.ReadLine();
  84. this.numberDecimalDigits = int.Parse(s.ReadLine());
  85. this.numberDecimalSeparator = s.ReadLine();
  86. this.numberGroupSeparator = s.ReadLine();
  87. this.numberGroupSizes = ConvertToIntArray(s.ReadLine());
  88. this.numberNegativePattern = int.Parse(s.ReadLine());
  89. this.percentDecimalDigits = int.Parse(s.ReadLine());
  90. this.percentDecimalSeparator = s.ReadLine();
  91. this.percentGroupSeparator = s.ReadLine();
  92. this.percentGroupSizes = ConvertToIntArray(s.ReadLine());
  93. this.percentNegativePattern = int.Parse(s.ReadLine());
  94. this.percentPositivePattern = int.Parse(s.ReadLine());
  95. this.percentSymbol = s.ReadLine();
  96. this.perMilleSymbol = s.ReadLine();
  97. this.positiveInfinitySymbol = s.ReadLine();
  98. this.positiveSign = s.ReadLine();
  99. }
  100. public NumberFormatInfo() {
  101. this.isReadOnly = true;
  102. // Set up defaults for invariant culture
  103. this.currencyDecimalDigits = 2;
  104. this.currencyDecimalSeparator = ".";
  105. this.currencyGroupSeparator = ",";
  106. this.currencyGroupSizes = new int[] { 3 };
  107. this.currencyNegativePattern = 0;
  108. this.currencyPositivePattern = 0;
  109. this.currencySymbol = "$";
  110. this.digitSubstitution = DigitShapes.None;
  111. this.naNSymbol = "NaN";
  112. this.nativeDigits = defaultNativeDigits;
  113. this.negativeInfinitySymbol = "-Infinity";
  114. this.negativeSign = "-";
  115. this.numberDecimalDigits = 2;
  116. this.numberDecimalSeparator = ".";
  117. this.numberGroupSeparator = ",";
  118. this.numberGroupSizes = new int[] { 3 };
  119. this.numberNegativePattern = 1;
  120. this.percentDecimalDigits = 2;
  121. this.percentDecimalSeparator = ".";
  122. this.percentGroupSeparator = ",";
  123. this.percentGroupSizes = new int[] { 3 };
  124. this.percentNegativePattern = 0;
  125. this.percentPositivePattern = 0;
  126. this.percentSymbol = "%";
  127. this.perMilleSymbol = "\x2030";
  128. this.positiveInfinitySymbol = "Infinity";
  129. this.positiveSign = "+";
  130. }
  131. public bool IsReadOnly { get { return this.isReadOnly; } }
  132. public int CurrencyDecimalDigits { get { return this.currencyDecimalDigits; } }
  133. public string CurrencyDecimalSeparator { get { return this.currencyDecimalSeparator; } }
  134. public string CurrencyGroupSeparator { get { return this.currencyGroupSeparator; } }
  135. public int[] CurrencyGroupSizes { get { return this.currencyGroupSizes; } }
  136. public int CurrencyNegativePattern { get { return this.currencyNegativePattern; } }
  137. public int CurrencyPositivePattern { get { return this.currencyPositivePattern; } }
  138. public string CurrencySymbol { get { return this.currencySymbol; } }
  139. public DigitShapes DigitSubstitution { get { return this.digitSubstitution; } }
  140. public string NaNSymbol { get { return this.naNSymbol; } }
  141. public string[] NativeDigits { get { return this.nativeDigits; } }
  142. public string NegativeInfinitySymbol { get { return this.negativeInfinitySymbol; } }
  143. public string NegativeSign { get { return this.negativeSign; } }
  144. public int NumberDecimalDigits { get { return this.numberDecimalDigits; } }
  145. public string NumberDecimalSeparator { get { return this.numberDecimalSeparator; } }
  146. public string NumberGroupSeparator { get { return this.numberGroupSeparator; } }
  147. public int[] NumberGroupSizes { get { return this.numberGroupSizes; } }
  148. public int NumberNegativePattern { get { return this.numberNegativePattern; } }
  149. public int PercentDecimalDigits { get { return this.percentDecimalDigits; } }
  150. public string PercentDecimalSeparator { get { return this.percentDecimalSeparator; } }
  151. public string PercentGroupSeparator { get { return this.percentGroupSeparator; } }
  152. public int[] PercentGroupSizes { get { return this.percentGroupSizes; } }
  153. public int PercentNegativePattern { get { return this.percentNegativePattern; } }
  154. public int PercentPositivePattern { get { return this.percentPositivePattern; } }
  155. public string PercentSymbol { get { return this.percentSymbol; } }
  156. public string PerMilleSymbol { get { return this.perMilleSymbol; } }
  157. public string PositiveInfinitySymbol { get { return this.positiveInfinitySymbol; } }
  158. public string PositiveSign { get { return this.positiveSign; } }
  159. #region IFormatProvider Members
  160. public object GetFormat(Type formatType) {
  161. throw new Exception("The method or operation is not implemented.");
  162. }
  163. #endregion
  164. }
  165. }
  166. #endif