NumberFormatEntry.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //
  2. // DateTimeFormatEntry.cs
  3. //
  4. // Authors:
  5. // Jackson Harper ([email protected])
  6. // Marek Safar <[email protected]>
  7. //
  8. // (C) 2004, Novell, Inc (http://www.novell.com)
  9. // Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System.Text;
  31. using System.Globalization;
  32. namespace Mono.Tools.LocaleBuilder
  33. {
  34. public class NumberFormatEntry : Entry
  35. {
  36. public string CurrencyDecimalDigits;
  37. public string CurrencyDecimalSeparator = ",";
  38. public string CurrencyGroupSeparator = ",";
  39. public string[] CurrencyGroupSizes = new string[Constants.GROUP_SIZE];
  40. public string CurrencyNegativePattern;
  41. public string CurrencyPositivePattern;
  42. public string CurrencySymbol;
  43. public string NaNSymbol;
  44. public string NegativeSign = "-";
  45. public int NumberDecimalDigits;
  46. public string NumberDecimalSeparator = ",";
  47. public string NumberGroupSeparator = ",";
  48. public string[] NumberGroupSizes = new string[Constants.GROUP_SIZE];
  49. public string NumberNegativePattern;
  50. /*
  51. public int PercentDecimalDigits;
  52. public string PercentDecimalSeparator = ",";
  53. public string PercentGroupSeparator = ",";
  54. public string[] PercentGroupSizes = new string[Constants.GROUP_SIZE];
  55. */
  56. public string PercentNegativePattern;
  57. public string PercentPositivePattern;
  58. public string PercentSymbol = "%";
  59. public string PerMilleSymbol = "‰";
  60. public string InfinitySymbol = "Infinity";
  61. public string PositiveSign = "+";
  62. public DigitShapes DigitSubstitution = DigitShapes.None;
  63. public string[] NativeDigits = new string[10] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
  64. public int Row;
  65. public string NegativeInfinitySymbol
  66. {
  67. get
  68. {
  69. if (InfinitySymbol.StartsWith (PositiveSign))
  70. return NegativeSign + InfinitySymbol.Substring (1, InfinitySymbol.Length - 1);
  71. return NegativeSign + InfinitySymbol;
  72. }
  73. }
  74. public string PositiveInfinitySymbol
  75. {
  76. get
  77. {
  78. return InfinitySymbol;
  79. }
  80. }
  81. public void AppendTableRow (StringBuilder builder)
  82. {
  83. builder.Append ("\t{");
  84. builder.Append (EncodeStringIdx (CurrencyDecimalSeparator) + ", ");
  85. builder.Append (EncodeStringIdx (CurrencyGroupSeparator) + ", ");
  86. builder.Append (EncodeStringIdx (NumberDecimalSeparator) + ", ");
  87. builder.Append (EncodeStringIdx (NumberGroupSeparator) + ", ");
  88. builder.Append (EncodeStringIdx (CurrencySymbol) + ", ");
  89. builder.Append (EncodeStringIdx (PercentSymbol) + ", ");
  90. builder.Append (EncodeStringIdx (NaNSymbol) + ", ");
  91. builder.Append (EncodeStringIdx (PerMilleSymbol) + ", ");
  92. builder.Append (EncodeStringIdx (NegativeInfinitySymbol) + ", ");
  93. builder.Append (EncodeStringIdx (PositiveInfinitySymbol) + ", ");
  94. builder.Append (EncodeStringIdx (NegativeSign) + ", ");
  95. builder.Append (EncodeStringIdx (PositiveSign) + ", ");
  96. builder.Append (CurrencyNegativePattern + ", ");
  97. builder.Append (CurrencyPositivePattern + ", ");
  98. builder.Append (PercentNegativePattern + ", ");
  99. builder.Append (PercentPositivePattern + ", ");
  100. builder.Append (NumberNegativePattern + ", ");
  101. builder.Append (CurrencyDecimalDigits + ", ");
  102. builder.Append (NumberDecimalDigits + ", ");
  103. AppendGroupSizes (builder, CurrencyGroupSizes);
  104. builder.Append (", ");
  105. AppendGroupSizes (builder, NumberGroupSizes);
  106. builder.Append ('}');
  107. }
  108. static void AppendGroupSizes (StringBuilder builder, string[] gs)
  109. {
  110. builder.Append ('{');
  111. for (int i = 0; i < gs.Length; i++) {
  112. if (i > 0)
  113. builder.Append (", ");
  114. if (gs[i] == null)
  115. builder.Append (-1);
  116. else
  117. builder.Append (gs[i]);
  118. }
  119. builder.Append ('}');
  120. }
  121. public override string ToString ()
  122. {
  123. StringBuilder builder = new StringBuilder ();
  124. AppendTableRow (builder);
  125. return builder.ToString ();
  126. }
  127. }
  128. }