1 | /** @file
|
---|
2 | * IPRT - Locale and Related Info.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2017-2022 Oracle and/or its affiliates.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox base platform packages, as
|
---|
9 | * available from https://www.virtualbox.org.
|
---|
10 | *
|
---|
11 | * This program is free software; you can redistribute it and/or
|
---|
12 | * modify it under the terms of the GNU General Public License
|
---|
13 | * as published by the Free Software Foundation, in version 3 of the
|
---|
14 | * License.
|
---|
15 | *
|
---|
16 | * This program is distributed in the hope that it will be useful, but
|
---|
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | * General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
23 | *
|
---|
24 | * The contents of this file may alternatively be used under the terms
|
---|
25 | * of the Common Development and Distribution License Version 1.0
|
---|
26 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
27 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
28 | * CDDL are applicable instead of those of the GPL.
|
---|
29 | *
|
---|
30 | * You may elect to license modified versions of this file under the
|
---|
31 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
32 | *
|
---|
33 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef IPRT_INCLUDED_locale_h
|
---|
37 | #define IPRT_INCLUDED_locale_h
|
---|
38 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
39 | # pragma once
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #include <iprt/cdefs.h>
|
---|
43 | #include <iprt/types.h>
|
---|
44 |
|
---|
45 | RT_C_DECLS_BEGIN
|
---|
46 |
|
---|
47 | /** @defgroup grp_rt_locale RTLocale - Locale and Related Info
|
---|
48 | * @ingroup grp_rt
|
---|
49 | * @{
|
---|
50 | */
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Returns the setlocale(LC_ALL,NULL) return value.
|
---|
54 | *
|
---|
55 | * @returns IPRT status code.
|
---|
56 | * @retval VERR_NOT_SUPPORTED if not supported.
|
---|
57 | * @param pszName Where to return the name.
|
---|
58 | * @param cbName The size of the name buffer.
|
---|
59 | */
|
---|
60 | RTDECL(int) RTLocaleQueryLocaleName(char *pszName, size_t cbName);
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Returns a normalized base locale name ('{ll}_{CC}' or 'C').
|
---|
64 | *
|
---|
65 | * @returns IPRT status code.
|
---|
66 | * @retval VERR_NOT_SUPPORTED if not supported.
|
---|
67 | * @param pszName Where to return the name.
|
---|
68 | * @param cbName The size of the name buffer.
|
---|
69 | *
|
---|
70 | * @sa RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2
|
---|
71 | */
|
---|
72 | RTDECL(int) RTLocaleQueryNormalizedBaseLocaleName(char *pszName, size_t cbName);
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Gets the two letter country code (ISO 3166-1 alpha-2) for the current user.
|
---|
76 | *
|
---|
77 | * This is not necessarily the country from the locale name, when possible the
|
---|
78 | * source is a different setting (host specific).
|
---|
79 | *
|
---|
80 | * @returns IPRT status code.
|
---|
81 | * @retval VERR_NOT_SUPPORTED if not supported.
|
---|
82 | * @param pszCountryCode Pointer buffer that's at least three bytes in size.
|
---|
83 | * The country code will be returned here on success.
|
---|
84 | */
|
---|
85 | RTDECL(int) RTLocaleQueryUserCountryCode(char pszCountryCode[3]);
|
---|
86 |
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Checks whether @a a_psz seems to start with a
|
---|
90 | * language-code-underscore-country-code sequence.
|
---|
91 | *
|
---|
92 | * We perform a check for a likely ISO 639-1 language code, followed by an
|
---|
93 | * underscore, followed by a likely ISO 3166-1 alpha-2 country code.
|
---|
94 | *
|
---|
95 | * @return true if probable '{ll}_{CC}' sequence, false if surely not.
|
---|
96 | * @param a_psz The string to test the start of.
|
---|
97 | *
|
---|
98 | * @note User must include iprt/ctype.h separately.
|
---|
99 | */
|
---|
100 | #define RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2(a_psz) \
|
---|
101 | ( RT_C_IS_LOWER((a_psz)[0]) \
|
---|
102 | && RT_C_IS_LOWER((a_psz)[1]) \
|
---|
103 | && (a_psz)[2] == '_' \
|
---|
104 | && RT_C_IS_UPPER((a_psz)[3]) \
|
---|
105 | && RT_C_IS_UPPER((a_psz)[4]) )
|
---|
106 |
|
---|
107 |
|
---|
108 | /** @} */
|
---|
109 |
|
---|
110 | RT_C_DECLS_END
|
---|
111 |
|
---|
112 | #endif /* !IPRT_INCLUDED_locale_h */
|
---|
113 |
|
---|