1//
2// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3//
4// Distributed under the Boost Software License, Version 1.0.
5// https://www.boost.org/LICENSE_1_0.txt
6
7#ifndef BOOST_LOCALE_TEST_POSIX_TOOLS_HPP
8#define BOOST_LOCALE_TEST_POSIX_TOOLS_HPP
9
10#include <clocale>
11#include <string>
12#if defined(__APPLE__) || defined(__FreeBSD__)
13# include <xlocale.h>
14#endif
15
16#ifndef LC_ALL_MASK
17using locale_t = void*;
18locale_t newlocale(int, const char*, locale_t)
19{
20 return nullptr;
21}
22void freelocale(locale_t) {}
23# define LC_ALL_MASK 0xFFFFFFFF
24#endif
25
26class locale_holder {
27 locale_t l_;
28 void reset(const locale_t l = nullptr)
29 {
30 if(l_)
31 freelocale(dataset: l_);
32 l_ = l;
33 }
34
35public:
36 explicit locale_holder(locale_t l = nullptr) : l_(l) {}
37 ~locale_holder() { reset(); }
38 locale_holder(const locale_holder&) = delete;
39 locale_holder& operator=(const locale_holder&) = delete;
40 locale_holder& operator=(locale_t l)
41 {
42 reset(l);
43 return *this;
44 }
45 operator locale_t() const { return l_; }
46};
47
48inline bool has_posix_locale(const std::string& name)
49{
50 locale_holder l(newlocale(LC_ALL_MASK, locale: name.c_str(), base: nullptr));
51 return !!l;
52}
53
54#endif
55

source code of boost/libs/locale/test/boostLocale/test/posix_tools.hpp