locbased.cpp (1407B)
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, const Locale& actual, 19 ULocDataLocaleType type, UErrorCode& status) { 20 if (U_FAILURE(status)) { 21 return Locale::getRoot(); 22 } 23 24 switch(type) { 25 case ULOC_VALID_LOCALE: 26 return valid; 27 case ULOC_ACTUAL_LOCALE: 28 return actual; 29 default: 30 status = U_ILLEGAL_ARGUMENT_ERROR; 31 return Locale::getRoot(); 32 } 33 } 34 35 const char* LocaleBased::getLocaleID(const Locale& valid, const Locale& actual, 36 ULocDataLocaleType type, UErrorCode& status) { 37 const Locale& locale = getLocale(valid, actual, type, status); 38 39 if (U_FAILURE(status)) { 40 return nullptr; 41 } 42 43 return locale == Locale::getRoot() ? kRootLocaleName : locale.getName(); 44 } 45 46 U_NAMESPACE_END