Fredrik Roubert | 64339d3 | 2016-10-21 19:43:16 +0200 | [diff] [blame] | 1 | // Copyright (C) 2016 and later: Unicode, Inc. and others. |
| 2 | // License & terms of use: http://www.unicode.org/copyright.html |
Jean-Baptiste Queru | ac04d0b | 2009-07-17 17:11:19 -0700 | [diff] [blame] | 3 | /* |
| 4 | ********************************************************************** |
ccornelius | fceb398 | 2014-04-16 12:27:14 -0700 | [diff] [blame] | 5 | * Copyright (c) 2004-2014, International Business Machines |
Jean-Baptiste Queru | ac04d0b | 2009-07-17 17:11:19 -0700 | [diff] [blame] | 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 "cstring.h" |
| 15 | |
| 16 | U_NAMESPACE_BEGIN |
| 17 | |
| 18 | Locale LocaleBased::getLocale(ULocDataLocaleType type, UErrorCode& status) const { |
| 19 | const char* id = getLocaleID(type, status); |
| 20 | return Locale((id != 0) ? id : ""); |
| 21 | } |
| 22 | |
| 23 | const char* LocaleBased::getLocaleID(ULocDataLocaleType type, UErrorCode& status) const { |
| 24 | if (U_FAILURE(status)) { |
| 25 | return NULL; |
| 26 | } |
| 27 | |
| 28 | switch(type) { |
| 29 | case ULOC_VALID_LOCALE: |
| 30 | return valid; |
| 31 | case ULOC_ACTUAL_LOCALE: |
| 32 | return actual; |
| 33 | default: |
| 34 | status = U_ILLEGAL_ARGUMENT_ERROR; |
| 35 | return NULL; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | void LocaleBased::setLocaleIDs(const char* validID, const char* actualID) { |
| 40 | if (validID != 0) { |
ccornelius | f9878a2 | 2014-11-20 18:09:39 -0800 | [diff] [blame] | 41 | uprv_strncpy(valid, validID, ULOC_FULLNAME_CAPACITY); |
| 42 | valid[ULOC_FULLNAME_CAPACITY-1] = 0; // always terminate |
Jean-Baptiste Queru | ac04d0b | 2009-07-17 17:11:19 -0700 | [diff] [blame] | 43 | } |
| 44 | if (actualID != 0) { |
ccornelius | f9878a2 | 2014-11-20 18:09:39 -0800 | [diff] [blame] | 45 | uprv_strncpy(actual, actualID, ULOC_FULLNAME_CAPACITY); |
| 46 | actual[ULOC_FULLNAME_CAPACITY-1] = 0; // always terminate |
Jean-Baptiste Queru | ac04d0b | 2009-07-17 17:11:19 -0700 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | |
ccornelius | fceb398 | 2014-04-16 12:27:14 -0700 | [diff] [blame] | 50 | void LocaleBased::setLocaleIDs(const Locale& validID, const Locale& actualID) { |
| 51 | uprv_strcpy(valid, validID.getName()); |
| 52 | uprv_strcpy(actual, actualID.getName()); |
| 53 | } |
| 54 | |
Jean-Baptiste Queru | ac04d0b | 2009-07-17 17:11:19 -0700 | [diff] [blame] | 55 | U_NAMESPACE_END |