locale.bmx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. ' Copyright (c) 2013-2022 Bruce A Henderson
  2. ' All rights reserved.
  3. '
  4. ' Redistribution and use in source and binary forms, with or without
  5. ' modification, are permitted provided that the following conditions are met:
  6. ' * Redistributions of source code must retain the above copyright
  7. ' notice, this list of conditions and the following disclaimer.
  8. ' * Redistributions in binary form must reproduce the above copyright
  9. ' notice, this list of conditions and the following disclaimer in the
  10. ' documentation and/or other materials provided with the distribution.
  11. ' * Neither the name of the copyright holder nor the
  12. ' names of its contributors may be used to endorse or promote products
  13. ' derived from this software without specific prior written permission.
  14. '
  15. ' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
  16. ' EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. ' WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. ' DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. ' DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. ' (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. ' LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. ' ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. ' (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. ' SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. '
  26. SuperStrict
  27. Rem
  28. bbdoc: Boost Locale
  29. End Rem
  30. Module Boost.Locale
  31. ModuleInfo "Version: 1.04"
  32. ModuleInfo "License: BSD"
  33. ModuleInfo "Copyright: Wrapper - 2013-2022 Bruce A Henderson"
  34. ModuleInfo "History: 1.04"
  35. ModuleInfo "History: Refactored."
  36. ModuleInfo "History: 1.03"
  37. ModuleInfo "History: Update to Boost 1.80."
  38. ModuleInfo "History: 1.02"
  39. ModuleInfo "History: Update to Boost 1.67."
  40. ModuleInfo "History: 1.01"
  41. ModuleInfo "History: Update to Boost 1.65.1."
  42. ModuleInfo "History: 1.00"
  43. ModuleInfo "History: Initial Release."
  44. ModuleInfo "CC_OPTS: -fexceptions"
  45. ?Not Win32
  46. ModuleInfo "CC_OPTS: -DBOOST_LOCALE_NO_WINAPI_BACKEND -DBOOST_LOCALE_NO_STD_BACKEND -DBOOST_LOCALE_WITH_ICONV"
  47. Import "-liconv"
  48. ?Win32
  49. ModuleInfo "CC_OPTS: -DBOOST_LOCALE_NO_POSIX_BACKEND -DBOOST_LOCALE_NO_STD_BACKEND"
  50. ?
  51. Import Boost.Core
  52. Import "common.bmx"
  53. Private
  54. Global localeGenerator:TBLGenerator = New TBLGenerator()
  55. Public
  56. Rem
  57. bbdoc:
  58. End Rem
  59. Type TBLGenerator
  60. Field genPtr:Byte Ptr
  61. Method New()
  62. genPtr = bmx_boostlocale_generator_create()
  63. End Method
  64. Method generate:TBLLocale(id:String)
  65. Return New TBLLocale(_generate(id))
  66. End Method
  67. Private
  68. Method _generate:Byte Ptr(id:String)
  69. Return bmx_boostlocale_generator_generate(genPtr, id)
  70. End Method
  71. End Type
  72. Rem
  73. bbdoc: The system default locale
  74. End Rem
  75. Global defaultLocale:TBLLocale = localeGenerator.Generate("")
  76. Rem
  77. bbdoc: The current locale
  78. End Rem
  79. Global currentLocale:TBLLocale = defaultLocale
  80. Rem
  81. bbdoc: Sets the current locale.
  82. End Rem
  83. Function SetLocale(locale:Object)
  84. If locale Then
  85. If String(locale) Then
  86. currentLocale = New TBLLocale(String(locale))
  87. Else If TBLLocale(locale) Then
  88. currentLocale = TBLLocale(locale)
  89. End If
  90. End If
  91. End Function
  92. Rem
  93. bbdoc:
  94. End Rem
  95. Type TBLLocale
  96. Field localePtr:Byte Ptr
  97. Private
  98. Method New()
  99. End Method
  100. Method New(localePtr:Byte Ptr)
  101. Self.localePtr = localePtr
  102. End Method
  103. Public
  104. Method New(locale:String)
  105. New(localeGenerator._generate(locale))
  106. End Method
  107. Method name:String()
  108. Return bmx_boostlocale_locale_name(localePtr)
  109. End Method
  110. Method language:String()
  111. Return bmx_boostlocale_locale_language(localePtr)
  112. End Method
  113. Method country:String()
  114. Return bmx_boostlocale_locale_country(localePtr)
  115. End Method
  116. Method variant:String()
  117. Return bmx_boostlocale_locale_variant(localePtr)
  118. End Method
  119. Method encoding:String()
  120. Return bmx_boostlocale_locale_encoding(localePtr)
  121. End Method
  122. Method utf8:Int()
  123. Return bmx_boostlocale_locale_utf8(localePtr)
  124. End Method
  125. Method Delete()
  126. If localePtr Then
  127. bmx_boostlocale_locale_free(localePtr)
  128. localePtr = Null
  129. End If
  130. End Method
  131. End Type
  132. Rem
  133. bbdoc: Return an int as a locale formatted string, using the current locale.
  134. End Rem
  135. Function IntAsNumber:String(value:Int)
  136. Return bmx_boostlocale_intasnumber(currentLocale.localePtr, value)
  137. End Function
  138. Rem
  139. bbdoc: Return a float as a locale formatted string, using the current locale.
  140. End Rem
  141. Function FloatAsNumber:String(value:Float)
  142. Return bmx_boostlocale_floatasnumber(currentLocale.localePtr, value)
  143. End Function
  144. Rem
  145. bbdoc: Return an int as a locale formatted currency string, using the current locale.
  146. End Rem
  147. Function IntAsCurrency:String(value:Int)
  148. Return bmx_boostlocale_intascurrency(currentLocale.localePtr, value)
  149. End Function
  150. Rem
  151. bbdoc: Return a float as a locale formatted currency string, using the current locale.
  152. End Rem
  153. Function FloatAsCurrency:String(value:Float)
  154. Return bmx_boostlocale_floatascurrency(currentLocale.localePtr, value)
  155. End Function