NumberFormatEntry.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. public int PercentDecimalDigits;
  51. public string PercentDecimalSeparator = ",";
  52. public string PercentGroupSeparator = ",";
  53. public string[] PercentGroupSizes = new string[Constants.GROUP_SIZE];
  54. public string PercentNegativePattern;
  55. public string PercentPositivePattern;
  56. public string PercentSymbol = "%";
  57. public string PerMilleSymbol = "‰";
  58. public string InfinitySymbol = "Infinity";
  59. public string PositiveSign = "+";
  60. public DigitShapes DigitSubstitution = DigitShapes.None;
  61. public string[] NativeDigits = new string[10] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
  62. public int Row;
  63. public string NegativeInfinitySymbol
  64. {
  65. get
  66. {
  67. if (InfinitySymbol.StartsWith (PositiveSign))
  68. return NegativeSign + InfinitySymbol.Substring (1, InfinitySymbol.Length - 1);
  69. return NegativeSign + InfinitySymbol;
  70. }
  71. }
  72. public string PositiveInfinitySymbol
  73. {
  74. get
  75. {
  76. return InfinitySymbol;
  77. }
  78. }
  79. public void AppendTableRow (StringBuilder builder)
  80. {
  81. builder.Append ("\t{");
  82. builder.Append (EncodeStringIdx (CurrencyDecimalSeparator) + ", ");
  83. builder.Append (EncodeStringIdx (CurrencyGroupSeparator) + ", ");
  84. builder.Append (EncodeStringIdx (PercentDecimalSeparator) + ", ");
  85. builder.Append (EncodeStringIdx (PercentGroupSeparator) + ", ");
  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 (PercentDecimalDigits + ", ");
  103. builder.Append (NumberDecimalDigits + ", ");
  104. AppendGroupSizes (builder, CurrencyGroupSizes);
  105. builder.Append (", ");
  106. AppendGroupSizes (builder, PercentGroupSizes);
  107. builder.Append (", ");
  108. AppendGroupSizes (builder, NumberGroupSizes);
  109. builder.Append ('}');
  110. }
  111. static void AppendGroupSizes (StringBuilder builder, string[] gs)
  112. {
  113. builder.Append ('{');
  114. for (int i = 0; i < gs.Length; i++) {
  115. if (i > 0)
  116. builder.Append (", ");
  117. if (gs[i] == null)
  118. builder.Append (-1);
  119. else
  120. builder.Append (gs[i]);
  121. }
  122. builder.Append ('}');
  123. }
  124. public override string ToString ()
  125. {
  126. StringBuilder builder = new StringBuilder ();
  127. AppendTableRow (builder);
  128. return builder.ToString ();
  129. }
  130. }
  131. }