1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___LOCALE_DIR_MESSAGES_H
#define _LIBCPP___LOCALE_DIR_MESSAGES_H
#include <__config>
#include <__iterator/back_insert_iterator.h>
#include <__locale>
#include <string>
#if _LIBCPP_HAS_LOCALIZATION
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif
# if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
// Most unix variants have catopen. These are the specific ones that don't.
# if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) && !defined(__EMSCRIPTEN__)
# define _LIBCPP_HAS_CATOPEN 1
# include <nl_types.h>
# else
# define _LIBCPP_HAS_CATOPEN 0
# endif
# else
# define _LIBCPP_HAS_CATOPEN 0
# endif
_LIBCPP_BEGIN_NAMESPACE_STD
class _LIBCPP_EXPORTED_FROM_ABI messages_base {
public:
typedef intptr_t catalog;
_LIBCPP_HIDE_FROM_ABI messages_base() {}
};
template <class _CharT>
class messages : public locale::facet, public messages_base {
public:
typedef _CharT char_type;
typedef basic_string<_CharT> string_type;
_LIBCPP_HIDE_FROM_ABI explicit messages(size_t __refs = 0) : locale::facet(__refs) {}
_LIBCPP_HIDE_FROM_ABI catalog open(const basic_string<char>& __nm, const locale& __loc) const {
return do_open(__nm, __loc);
}
_LIBCPP_HIDE_FROM_ABI string_type get(catalog __c, int __set, int __msgid, const string_type& __dflt) const {
return do_get(__c, __set, __msgid, __dflt);
}
_LIBCPP_HIDE_FROM_ABI void close(catalog __c) const { do_close(__c); }
static locale::id id;
protected:
_LIBCPP_HIDE_FROM_ABI_VIRTUAL ~messages() override {}
virtual catalog do_open(const basic_string<char>&, const locale&) const;
virtual string_type do_get(catalog, int __set, int __msgid, const string_type& __dflt) const;
virtual void do_close(catalog) const;
};
template <class _CharT>
locale::id messages<_CharT>::id;
template <class _CharT>
typename messages<_CharT>::catalog messages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const {
# if _LIBCPP_HAS_CATOPEN
return (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE);
# else // !_LIBCPP_HAS_CATOPEN
(void)__nm;
return -1;
# endif // _LIBCPP_HAS_CATOPEN
}
template <class _CharT>
typename messages<_CharT>::string_type
messages<_CharT>::do_get(catalog __c, int __set, int __msgid, const string_type& __dflt) const {
# if _LIBCPP_HAS_CATOPEN
string __ndflt;
__narrow_to_utf8<sizeof(char_type) * __CHAR_BIT__>()(
std::back_inserter(__ndflt), __dflt.c_str(), __dflt.c_str() + __dflt.size());
nl_catd __cat = (nl_catd)__c;
static_assert(sizeof(catalog) >= sizeof(nl_catd), "Unexpected nl_catd type");
char* __n = catgets(__cat, __set, __msgid, __ndflt.c_str());
string_type __w;
__widen_from_utf8<sizeof(char_type) * __CHAR_BIT__>()(std::back_inserter(__w), __n, __n + std::strlen(__n));
return __w;
# else // !_LIBCPP_HAS_CATOPEN
(void)__c;
(void)__set;
(void)__msgid;
return __dflt;
# endif // _LIBCPP_HAS_CATOPEN
}
template <class _CharT>
void messages<_CharT>::do_close(catalog __c) const {
# if _LIBCPP_HAS_CATOPEN
catclose((nl_catd)__c);
# else // !_LIBCPP_HAS_CATOPEN
(void)__c;
# endif // _LIBCPP_HAS_CATOPEN
}
extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<char>;
# if _LIBCPP_HAS_WIDE_CHARACTERS
extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<wchar_t>;
# endif
template <class _CharT>
class messages_byname : public messages<_CharT> {
public:
typedef messages_base::catalog catalog;
typedef basic_string<_CharT> string_type;
_LIBCPP_HIDE_FROM_ABI explicit messages_byname(const char*, size_t __refs = 0) : messages<_CharT>(__refs) {}
_LIBCPP_HIDE_FROM_ABI explicit messages_byname(const string&, size_t __refs = 0) : messages<_CharT>(__refs) {}
protected:
_LIBCPP_HIDE_FROM_ABI_VIRTUAL ~messages_byname() override {}
};
extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<char>;
# if _LIBCPP_HAS_WIDE_CHARACTERS
extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<wchar_t>;
# endif
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_HAS_LOCALIZATION
#endif // _LIBCPP___LOCALE_DIR_MESSAGES_H
|