Locale.hh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**********
  2. This library is free software; you can redistribute it and/or modify it under
  3. the terms of the GNU Lesser General Public License as published by the
  4. Free Software Foundation; either version 3 of the License, or (at your
  5. option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
  6. This library is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
  9. more details.
  10. You should have received a copy of the GNU Lesser General Public License
  11. along with this library; if not, write to the Free Software Foundation, Inc.,
  12. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  13. **********/
  14. // "liveMedia"
  15. // Copyright (c) 1996-2019 Live Networks, Inc. All rights reserved.
  16. // Support for temporarily setting the locale (e.g., to "C" or "POSIX") for (e.g.) parsing or printing
  17. // floating-point numbers in protocol headers, or calling toupper()/tolower() on human-input strings.
  18. // C++ header
  19. #ifndef _LOCALE_HH
  20. #define _LOCALE_HH
  21. // If you're on a system that (for whatever reason) doesn't have either the "setlocale()" or the "newlocale()" function, then
  22. // add "-DLOCALE_NOT_USED" to your "config.*" file.
  23. // If you're on a system that (for whatever reason) has "setlocale()" but not "newlocale()", then
  24. // add "-DNEWLOCALE_NOT_USED" to your "config.*" file.
  25. // (Note that -DLOCALE_NOT_USED implies -DNEWLOCALE_NOT_USED; you do not need both.)
  26. // Also, for Windows systems, we define "NEWLOCALE_NOT_USED" by default, because at least some Windows systems
  27. // (or their development environments) don't have "newlocale()". If, however, your Windows system *does* have "newlocale()",
  28. // then you can override this by defining "NEWLOCALE_USED" before #including this file.
  29. // Finally, some old development environments need a header file "xlocale.h" to use "newlocale()".
  30. // Should you need this header file, add "-DNEED_XLOCALE_H" to your "config.*" file.
  31. #ifdef NEWLOCALE_USED
  32. #undef LOCALE_NOT_USED
  33. #undef NEWLOCALE_NOT_USED
  34. #else
  35. #if defined(__WIN32__) || defined(_WIN32)
  36. #define NEWLOCALE_NOT_USED 1
  37. #endif
  38. #endif
  39. #ifndef LOCALE_NOT_USED
  40. #include <locale.h>
  41. #ifndef NEWLOCALE_NOT_USED
  42. #ifdef NEED_XLOCALE_H
  43. #include <xlocale.h>
  44. #endif
  45. #endif
  46. #endif
  47. enum LocaleCategory { All, Numeric }; // define and implement more categories later, as needed
  48. class Locale {
  49. public:
  50. Locale(char const* newLocale, LocaleCategory category = All);
  51. virtual ~Locale();
  52. private:
  53. #ifndef LOCALE_NOT_USED
  54. #ifndef NEWLOCALE_NOT_USED
  55. locale_t fLocale, fPrevLocale;
  56. #else
  57. int fCategoryNum;
  58. char* fPrevLocale;
  59. #endif
  60. #endif
  61. };
  62. #endif