locbased.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 "cstring.h"
  15. U_NAMESPACE_BEGIN
  16. Locale LocaleBased::getLocale(ULocDataLocaleType type, UErrorCode& status) const {
  17. const char* id = getLocaleID(type, status);
  18. return Locale((id != 0) ? id : "");
  19. }
  20. const char* LocaleBased::getLocaleID(ULocDataLocaleType type, UErrorCode& status) const {
  21. if (U_FAILURE(status)) {
  22. return nullptr;
  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 nullptr;
  32. }
  33. }
  34. void LocaleBased::setLocaleIDs(const char* validID, const char* actualID) {
  35. if (validID != 0) {
  36. uprv_strncpy(valid, validID, ULOC_FULLNAME_CAPACITY);
  37. valid[ULOC_FULLNAME_CAPACITY-1] = 0; // always terminate
  38. }
  39. if (actualID != 0) {
  40. uprv_strncpy(actual, actualID, ULOC_FULLNAME_CAPACITY);
  41. actual[ULOC_FULLNAME_CAPACITY-1] = 0; // always terminate
  42. }
  43. }
  44. void LocaleBased::setLocaleIDs(const Locale& validID, const Locale& actualID) {
  45. uprv_strcpy(valid, validID.getName());
  46. uprv_strcpy(actual, actualID.getName());
  47. }
  48. U_NAMESPACE_END