Skip to content

Commit abc1c61

Browse files
committed
[libc++] Granularize <locale>
1 parent 179cc20 commit abc1c61

File tree

43 files changed

+3865
-3532
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3865
-3532
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,13 +511,19 @@ set(files
511511
__iterator/unreachable_sentinel.h
512512
__iterator/wrap_iter.h
513513
__locale
514+
__locale_dir/check_grouping.h
515+
__locale_dir/get_c_locale.h
514516
__locale_dir/locale_base_api.h
515517
__locale_dir/locale_base_api/android.h
516518
__locale_dir/locale_base_api/bsd_locale_fallbacks.h
517519
__locale_dir/locale_base_api/ibm.h
518520
__locale_dir/locale_base_api/musl.h
519521
__locale_dir/locale_base_api/openbsd.h
522+
__locale_dir/messages.h
523+
__locale_dir/money.h
524+
__locale_dir/num.h
520525
__locale_dir/pad_and_output.h
526+
__locale_dir/scan_keyword.h
521527
__locale_dir/support/apple.h
522528
__locale_dir/support/bsd_like.h
523529
__locale_dir/support/freebsd.h
@@ -526,6 +532,9 @@ set(files
526532
__locale_dir/support/no_locale/characters.h
527533
__locale_dir/support/no_locale/strtonum.h
528534
__locale_dir/support/windows.h
535+
__locale_dir/time.h
536+
__locale_dir/wbuffer_convert.h
537+
__locale_dir/wstring_convert.h
529538
__math/abs.h
530539
__math/copysign.h
531540
__math/error_functions.h

libcxx/include/__chrono/formatter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@
5050
# include <__format/formatter.h>
5151
# include <__format/parser_std_format_spec.h>
5252
# include <__format/write_escaped.h>
53+
# include <__iterator/istreambuf_iterator.h>
54+
# include <__iterator/ostreambuf_iterator.h>
55+
# include <__locale_dir/time.h>
5356
# include <__memory/addressof.h>
5457
# include <__type_traits/is_specialization.h>
5558
# include <cmath>
5659
# include <ctime>
5760
# include <limits>
58-
# include <locale>
5961
# include <sstream>
6062
# include <string_view>
6163

libcxx/include/__filesystem/path.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
#if _LIBCPP_HAS_LOCALIZATION
3131
# include <iomanip> // for quoted
32-
# include <locale>
3332
#endif
3433

3534
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

libcxx/include/__filesystem/u8path.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,9 @@
1313
#include <__algorithm/unwrap_iter.h>
1414
#include <__config>
1515
#include <__filesystem/path.h>
16+
#include <__locale>
1617
#include <string>
1718

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

0 commit comments

Comments
 (0)