/src/wxwidgets/include/wx/unix/private/uilocale.h
Line | Count | Source (jump to first uncovered line) |
1 | | /////////////////////////////////////////////////////////////////////////////// |
2 | | // Name: wx/unix/private/uilocale.h |
3 | | // Purpose: Various locale-related helpers used under Unix systems only |
4 | | // Author: Vadim Zeitlin |
5 | | // Created: 2021-08-14 (extracted from src/common/intl.cpp) |
6 | | // Copyright: (c) 2021 Vadim Zeitlin <vadim@wxwidgets.org> |
7 | | // Licence: wxWindows licence |
8 | | /////////////////////////////////////////////////////////////////////////////// |
9 | | |
10 | | #ifndef _WX_UNIX_PRIVATE_UILOCALE_H_ |
11 | | #define _WX_UNIX_PRIVATE_UILOCALE_H_ |
12 | | |
13 | | #include "wx/string.h" |
14 | | |
15 | | // get just the language part ("en" in "en_GB") |
16 | | inline wxString ExtractLang(const wxString& langFull) |
17 | 0 | { |
18 | 0 | return langFull.BeforeFirst('_'); |
19 | 0 | } |
20 | | |
21 | | // get everything else (including the leading '_') |
22 | | inline wxString ExtractNotLang(const wxString& langFull) |
23 | 0 | { |
24 | 0 | size_t pos = langFull.find('_'); |
25 | 0 | if ( pos != wxString::npos ) |
26 | 0 | return langFull.substr(pos); |
27 | 0 | else |
28 | 0 | return wxString(); |
29 | 0 | } |
30 | | |
31 | | const char *wxSetlocaleTryAll(int c, const wxLocaleIdent& lc); |
32 | | |
33 | | // Extract date format from D_T_FMT value. |
34 | | wxString wxGetDateFormatOnly(const wxString& fmt); |
35 | | |
36 | | // Helper class changing the global locale to the one specified by the |
37 | | // environment variables in its ctor and restoring it in its dtor. |
38 | | namespace |
39 | | { |
40 | | |
41 | | class TempLocaleSetter |
42 | | { |
43 | | public: |
44 | | explicit TempLocaleSetter(int localeCategory, |
45 | | const wxString& localeId = wxString()) |
46 | | : m_localeCategory(localeCategory), |
47 | | m_localeOrig(strdup(setlocale(localeCategory, nullptr))) |
48 | 2 | { |
49 | 2 | setlocale(localeCategory, localeId.mb_str()); |
50 | 2 | } Unexecuted instantiation: uilocale.cpp:(anonymous namespace)::TempLocaleSetter::TempLocaleSetter(int, wxString const&) intl.cpp:(anonymous namespace)::TempLocaleSetter::TempLocaleSetter(int, wxString const&) Line | Count | Source | 48 | 2 | { | 49 | 2 | setlocale(localeCategory, localeId.mb_str()); | 50 | 2 | } |
|
51 | | |
52 | | ~TempLocaleSetter() |
53 | 2 | { |
54 | 2 | setlocale(m_localeCategory, m_localeOrig); |
55 | 2 | free(m_localeOrig); |
56 | 2 | } Unexecuted instantiation: uilocale.cpp:(anonymous namespace)::TempLocaleSetter::~TempLocaleSetter() intl.cpp:(anonymous namespace)::TempLocaleSetter::~TempLocaleSetter() Line | Count | Source | 53 | 2 | { | 54 | 2 | setlocale(m_localeCategory, m_localeOrig); | 55 | 2 | free(m_localeOrig); | 56 | 2 | } |
|
57 | | |
58 | | private: |
59 | | const int m_localeCategory; |
60 | | char* const m_localeOrig; |
61 | | |
62 | | wxDECLARE_NO_COPY_CLASS(TempLocaleSetter); |
63 | | }; |
64 | | |
65 | | } // anonymous namespace |
66 | | |
67 | | #endif // _WX_UNIX_PRIVATE_UILOCALE_H_ |