BsHString.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #pragma once
  2. namespace BansheeEngine
  3. {
  4. /**
  5. * @brief String handle. Provides a wrapper around an Unicode string, primarily
  6. * for localization purposes.
  7. *
  8. * Actual value for this string is looked up in a global string table based
  9. * on the provided identifier string and currently active language. If such value
  10. * doesn't exist then the identifier is used as is.
  11. *
  12. * Use {0}, {1}, etc. in the string value for values that might change dynamically.
  13. */
  14. class BS_CORE_EXPORT HString
  15. {
  16. public:
  17. /**
  18. * @brief Creates a new localized string with the specified identifier. If the identifier
  19. * doesn't previously exist in the string table, identifier value will also be used
  20. * for initializing the default language version of the string.
  21. *
  22. * @param identifier String you can use for later referencing the localized string.
  23. * @param stringTableId Unique identifier of the string table to retrieve the string from.
  24. */
  25. explicit HString(const WString& identifier, UINT32 stringTableId = 0);
  26. /**
  27. * @brief Creates a new localized string with the specified identifier and sets the default language version
  28. * of the string. If a string with that identifier already exists default language string will be updated.
  29. *
  30. * @param identifier String you can use for later referencing the localized string.
  31. * @param default Default string to assign to the specified identifier. Language to which it
  32. * will be assigned depends on the StringTable::DEFAULT_LANGUAGE value.
  33. * @param stringTableId Unique identifier of the string table to retrieve the string from.
  34. */
  35. explicit HString(const WString& identifier, const WString& default, UINT32 stringTableId = 0);
  36. /**
  37. * @brief Creates a new empty localized string.
  38. *
  39. * @param stringTableId Unique identifier of the string table to retrieve the string from.
  40. */
  41. HString(UINT32 stringTableId = 0);
  42. HString(const HString& copy);
  43. ~HString();
  44. HString& operator=(const HString& rhs);
  45. operator const WString& () const;
  46. const WString& getValue() const;
  47. /**
  48. * @brief Sets a value of a string parameter. Parameters are specified as bracketed values
  49. * within the string itself (e.g. {0}, {1}) etc. Use ^ as an escape character.
  50. *
  51. * @note Useful for strings that have dynamically changing values, like numbers, embedded in them.
  52. */
  53. void setParameter(UINT32 idx, const WString& value);
  54. /**
  55. * @brief Returns an empty string.
  56. */
  57. static const HString& dummy();
  58. private:
  59. SPtr<LocalizedStringData> mStringData;
  60. WString* mParameters;
  61. mutable bool mIsDirty;
  62. mutable WString mCachedString;
  63. mutable WString* mStringPtr;
  64. };
  65. }