ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

60 lines
1.5 KiB

  1. #define CPPCMS_SOURCE
  2. #include "icu_util.h"
  3. #ifdef HAVE_ICU
  4. #include "locale_charset.h"
  5. #include "utf_iterator.h"
  6. namespace cppcms { namespace impl {
  7. std::string icu_to_utf8(icu::UnicodeString const &str)
  8. {
  9. std::string tmp;
  10. tmp.reserve(str.length());
  11. uint16_t const *begin=reinterpret_cast<uint16_t const *>(str.getBuffer());
  12. uint16_t const *end=begin+str.length();
  13. while(begin<end) {
  14. uint32_t v=utf16::next(begin,end);
  15. if(v!=utf::illegal) {
  16. utf8::seq s=utf8::encode(v);
  17. tmp.append(s.c,s.len);
  18. }
  19. }
  20. return tmp;
  21. }
  22. icu::UnicodeString utf8_to_icu(std::string const &s)
  23. {
  24. icu::UnicodeString tmp(int32_t(s.size()),0,0);
  25. char const *begin=s.data();
  26. char const *end=begin+s.size();
  27. while(begin < end) {
  28. uint32_t v=utf8::next(begin,end);
  29. if(v!=utf::illegal)
  30. tmp.append((UChar32)(v));
  31. }
  32. return tmp;
  33. }
  34. std::string icu_to_std(icu::UnicodeString const &str,std::locale const &l)
  35. {
  36. uint16_t const *begin=reinterpret_cast<uint16_t const *>(str.getBuffer());
  37. uint16_t const *end=begin+str.length();
  38. return std::use_facet<locale::charset>(l).from_utf16(begin,end);
  39. }
  40. icu::UnicodeString std_to_icu(std::string const &str,std::locale const &l)
  41. {
  42. char const *begin=str.data();
  43. char const *end=str.data()+str.size();
  44. std::basic_string<uint16_t> tmp = std::use_facet<locale::charset>(l).to_utf16(begin,end);
  45. return icu::UnicodeString(reinterpret_cast<UChar const *>(tmp.data()),tmp.size());
  46. }
  47. } } // cppcms::impl
  48. #endif