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