resbund_cnv.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. *******************************************************************************
  5. *
  6. * Copyright (C) 1997-2006, International Business Machines
  7. * Corporation and others. All Rights Reserved.
  8. *
  9. *******************************************************************************
  10. * file name: resbund_cnv.cpp
  11. * encoding: UTF-8
  12. * tab size: 8 (not used)
  13. * indentation:4
  14. *
  15. * created on: 2004aug25
  16. * created by: Markus W. Scherer
  17. *
  18. * Character conversion functions moved here from resbund.cpp
  19. */
  20. #include "unicode/utypes.h"
  21. #include "unicode/resbund.h"
  22. #include "uinvchar.h"
  23. U_NAMESPACE_BEGIN
  24. ResourceBundle::ResourceBundle( const UnicodeString& path,
  25. const Locale& locale,
  26. UErrorCode& error)
  27. :UObject(), fLocale(nullptr)
  28. {
  29. constructForLocale(path, locale, error);
  30. }
  31. ResourceBundle::ResourceBundle( const UnicodeString& path,
  32. UErrorCode& error)
  33. :UObject(), fLocale(nullptr)
  34. {
  35. constructForLocale(path, Locale::getDefault(), error);
  36. }
  37. void
  38. ResourceBundle::constructForLocale(const UnicodeString& path,
  39. const Locale& locale,
  40. UErrorCode& error)
  41. {
  42. if (path.isEmpty()) {
  43. fResource = ures_open(nullptr, locale.getName(), &error);
  44. }
  45. else {
  46. UnicodeString nullTerminatedPath(path);
  47. nullTerminatedPath.append((char16_t)0);
  48. fResource = ures_openU(nullTerminatedPath.getBuffer(), locale.getName(), &error);
  49. }
  50. }
  51. U_NAMESPACE_END