glue.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. Copyright (c) 2013-2022 Bruce A Henderson
  3. All rights reserved.
  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. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
  15. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
  18. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "glue.h"
  26. boost::locale::generator * bmx_boostlocale_generator_create() {
  27. boost::locale::generator * gen = new boost::locale::generator();
  28. gen->locale_cache_enabled(true);
  29. return gen;
  30. }
  31. MaxLocale * bmx_boostlocale_generator_generate(boost::locale::generator * gen, BBString * id) {
  32. char * d = (char*)bbStringToUTF8String(id);
  33. MaxLocale * loc = new MaxLocale(gen->generate(d));
  34. bbMemFree(d);
  35. return loc;
  36. }
  37. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  38. BBString * bmx_boostlocale_locale_name(MaxLocale * loc) {
  39. return bbStringFromUTF8String((const unsigned char*)std::use_facet<boost::locale::info>(loc->Locale()).name().c_str());
  40. }
  41. BBString * bmx_boostlocale_locale_language(MaxLocale * loc) {
  42. return bbStringFromUTF8String((const unsigned char*)std::use_facet<boost::locale::info>(loc->Locale()).language().c_str());
  43. }
  44. BBString * bmx_boostlocale_locale_country(MaxLocale * loc) {
  45. return bbStringFromUTF8String((const unsigned char*)std::use_facet<boost::locale::info>(loc->Locale()).country().c_str());
  46. }
  47. BBString * bmx_boostlocale_locale_variant(MaxLocale * loc) {
  48. return bbStringFromUTF8String((const unsigned char*)std::use_facet<boost::locale::info>(loc->Locale()).variant().c_str());
  49. }
  50. BBString * bmx_boostlocale_locale_encoding(MaxLocale * loc) {
  51. return bbStringFromUTF8String((const unsigned char*)std::use_facet<boost::locale::info>(loc->Locale()).encoding().c_str());
  52. }
  53. int bmx_boostlocale_locale_utf8(MaxLocale * loc) {
  54. return std::use_facet<boost::locale::info>(loc->Locale()).utf8();
  55. }
  56. void bmx_boostlocale_locale_free(MaxLocale * loc) {
  57. delete loc;
  58. }
  59. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  60. BBString * bmx_boostlocale_intasnumber(MaxLocale * loc, int value) {
  61. std::stringstream stream;
  62. stream.imbue(loc->Locale());
  63. stream << boost::locale::as::number << value;
  64. return bbStringFromUTF8String((const unsigned char*)stream.str().c_str());
  65. }
  66. BBString * bmx_boostlocale_floatasnumber(MaxLocale * loc, float value) {
  67. std::stringstream stream;
  68. stream.imbue(loc->Locale());
  69. stream << boost::locale::as::number << value;
  70. return bbStringFromUTF8String((const unsigned char*)stream.str().c_str());
  71. }
  72. BBString * bmx_boostlocale_intascurrency(MaxLocale * loc, int value) {
  73. std::stringstream stream;
  74. stream.imbue(loc->Locale());
  75. stream << boost::locale::as::currency << value;
  76. return bbStringFromUTF8String((const unsigned char*)stream.str().c_str());
  77. }
  78. BBString * bmx_boostlocale_floatascurrency(MaxLocale * loc, float value) {
  79. std::stringstream stream;
  80. stream.imbue(loc->Locale());
  81. stream << boost::locale::as::currency << value;
  82. return bbStringFromUTF8String((const unsigned char*)stream.str().c_str());
  83. }