]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/locbased.cpp
ICU-57163.0.1.tar.gz
[apple/icu.git] / icuSources / common / locbased.cpp
CommitLineData
374ca955
A
1/*
2**********************************************************************
57a6839d 3* Copyright (c) 2004-2014, International Business Machines
374ca955
A
4* Corporation and others. All Rights Reserved.
5**********************************************************************
6* Author: Alan Liu
7* Created: January 16 2004
8* Since: ICU 2.8
9**********************************************************************
10*/
11#include "locbased.h"
12#include "cstring.h"
13
14U_NAMESPACE_BEGIN
15
16Locale LocaleBased::getLocale(ULocDataLocaleType type, UErrorCode& status) const {
17 const char* id = getLocaleID(type, status);
18 return Locale((id != 0) ? id : "");
19}
20
21const char* LocaleBased::getLocaleID(ULocDataLocaleType type, UErrorCode& status) const {
22 if (U_FAILURE(status)) {
23 return NULL;
24 }
25
26 switch(type) {
27 case ULOC_VALID_LOCALE:
28 return valid;
29 case ULOC_ACTUAL_LOCALE:
30 return actual;
31 default:
32 status = U_ILLEGAL_ARGUMENT_ERROR;
33 return NULL;
34 }
35}
36
37void LocaleBased::setLocaleIDs(const char* validID, const char* actualID) {
38 if (validID != 0) {
b331163b
A
39 uprv_strncpy(valid, validID, ULOC_FULLNAME_CAPACITY);
40 valid[ULOC_FULLNAME_CAPACITY-1] = 0; // always terminate
374ca955
A
41 }
42 if (actualID != 0) {
b331163b
A
43 uprv_strncpy(actual, actualID, ULOC_FULLNAME_CAPACITY);
44 actual[ULOC_FULLNAME_CAPACITY-1] = 0; // always terminate
374ca955
A
45 }
46}
47
57a6839d
A
48void LocaleBased::setLocaleIDs(const Locale& validID, const Locale& actualID) {
49 uprv_strcpy(valid, validID.getName());
50 uprv_strcpy(actual, actualID.getName());
51}
52
374ca955 53U_NAMESPACE_END