Locale.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "il2cpp-config.h"
  2. #if IL2CPP_TARGET_WINDOWS
  3. #include "os/Locale.h"
  4. #include "WindowsHelpers.h"
  5. #include <locale.h>
  6. #include <vector>
  7. namespace il2cpp
  8. {
  9. namespace os
  10. {
  11. #if IL2CPP_TARGET_WINDOWS_DESKTOP
  12. std::string Locale::GetLocale()
  13. {
  14. LCID lcid = GetThreadLocale();
  15. int number_of_characters = GetLocaleInfo(lcid, LOCALE_SNAME, NULL, 0);
  16. std::vector<WCHAR> locale_name(number_of_characters);
  17. if (GetLocaleInfo(lcid, LOCALE_SNAME, &locale_name[0], number_of_characters) == 0)
  18. return std::string();
  19. std::vector<char> locale_name_char(number_of_characters);
  20. if (WideCharToMultiByte(CP_ACP, 0, &locale_name[0], number_of_characters, &locale_name_char[0], number_of_characters, NULL, NULL) == 0)
  21. return std::string();
  22. return std::string(locale_name_char.begin(), locale_name_char.end());
  23. }
  24. #endif
  25. #if IL2CPP_SUPPORT_LOCALE_INDEPENDENT_PARSING
  26. static _locale_t s_cLocale = NULL;
  27. #endif
  28. void Locale::Initialize()
  29. {
  30. #if IL2CPP_SUPPORT_LOCALE_INDEPENDENT_PARSING
  31. s_cLocale = _create_locale(LC_ALL, "C");
  32. #endif
  33. }
  34. void Locale::UnInitialize()
  35. {
  36. #if IL2CPP_SUPPORT_LOCALE_INDEPENDENT_PARSING
  37. _free_locale(s_cLocale);
  38. s_cLocale = NULL;
  39. #endif
  40. }
  41. #if IL2CPP_SUPPORT_LOCALE_INDEPENDENT_PARSING
  42. double Locale::DoubleParseLocaleIndependentImpl(char *ptr, char** endptr)
  43. {
  44. return _strtod_l(ptr, endptr, s_cLocale);
  45. }
  46. #endif
  47. } /* namespace os */
  48. } /* namespace il2cpp */
  49. #endif