19 #ifndef OPENXCOM_LOCALIZEDTEXT_H
20 #define OPENXCOM_LOCALIZEDTEXT_H
31 #ifndef OX_REQUIRED_RESULT
32 # if defined(__GNUC_) && !defined(__INTEL_COMPILER) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
33 # define OX_REQUIRED_RESULT __attribute__ ((warn_unused_result))
35 # define OX_REQUIRED_RESULT
78 : _text(text), _nextArg(0)
87 : _text(text), _nextArg(replaced + 1)
96 inline LocalizedText::operator std::wstring
const& ()
const
107 template <
typename T>
110 std::wostringstream os;
111 os <<
'{' << _nextArg <<
'}';
112 std::wstring marker(os.str());
113 size_t pos = _text.find(marker);
114 if (std::string::npos == pos)
116 std::wstring ntext(_text);
119 std::wstring tval(os.str());
120 for ( ; std::wstring::npos != pos; pos = ntext.find(marker, pos + tval.length()))
122 ntext.replace(pos, marker.length(), tval);
133 template <
typename T>
136 std::wostringstream os;
137 os <<
'{' << _nextArg <<
'}';
138 std::wstring marker(os.str());
139 size_t pos = _text.find(marker);
140 if (std::string::npos != pos)
144 std::wstring tval(os.str());
145 for ( ; std::wstring::npos != pos; pos = _text.find(marker, pos + tval.length()))
147 _text.replace(pos, marker.length(), tval);
155 inline std::wostream &operator<<(std::wostream &os,
const LocalizedText &txt)
157 os << static_cast<std::wstring const &>(txt);
LocalizedText()
Create the empty string.
Definition: LocalizedText.h:51
std::string asUTF8() const OX_REQUIRED_RESULT
Return the UTF-8 representation of this string.
Definition: LocalizedText.cpp:72
#define OX_REQUIRED_RESULT
This is used to enable warning of unused results, to warn the user of costly function calls...
Definition: LocalizedText.h:35
A string that is already translated.
Definition: LocalizedText.h:45
LocalizedText arg(std::wstring const &) const OX_REQUIRED_RESULT
Replace next argument.
Definition: LocalizedText.cpp:30
const wchar_t * c_str() const OX_REQUIRED_RESULT
Get a pointer to underlying wchat_t data.
Definition: LocalizedText.h:57