/src/icu/icu4c/source/common/locbased.cpp
Line | Count | Source |
1 | | // © 2016 and later: Unicode, Inc. and others. |
2 | | // License & terms of use: http://www.unicode.org/copyright.html |
3 | | /* |
4 | | ********************************************************************** |
5 | | * Copyright (c) 2004-2014, International Business Machines |
6 | | * Corporation and others. All Rights Reserved. |
7 | | ********************************************************************** |
8 | | * Author: Alan Liu |
9 | | * Created: January 16 2004 |
10 | | * Since: ICU 2.8 |
11 | | ********************************************************************** |
12 | | */ |
13 | | #include "locbased.h" |
14 | | #include "uresimp.h" |
15 | | |
16 | | U_NAMESPACE_BEGIN |
17 | | |
18 | | const Locale& LocaleBased::getLocale(const Locale& valid U_LIFETIME_BOUND, |
19 | | const Locale& actual U_LIFETIME_BOUND, |
20 | | ULocDataLocaleType type, |
21 | 12.3k | UErrorCode& status) { |
22 | 12.3k | if (U_FAILURE(status)) { |
23 | 0 | return Locale::getRoot(); |
24 | 0 | } |
25 | | |
26 | 12.3k | switch(type) { |
27 | 12.2k | case ULOC_VALID_LOCALE: |
28 | 12.2k | return valid; |
29 | 178 | case ULOC_ACTUAL_LOCALE: |
30 | 178 | return actual; |
31 | 0 | default: |
32 | 0 | status = U_ILLEGAL_ARGUMENT_ERROR; |
33 | 0 | return Locale::getRoot(); |
34 | 12.3k | } |
35 | 12.3k | } |
36 | | |
37 | | const char* LocaleBased::getLocaleID(const Locale& valid, const Locale& actual, |
38 | 0 | ULocDataLocaleType type, UErrorCode& status) { |
39 | 0 | const Locale& locale = getLocale(valid, actual, type, status); |
40 | |
|
41 | 0 | if (U_FAILURE(status)) { |
42 | 0 | return nullptr; |
43 | 0 | } |
44 | | |
45 | 0 | return locale == Locale::getRoot() ? kRootLocaleName : locale.getName(); |
46 | 0 | } |
47 | | |
48 | | U_NAMESPACE_END |