Added conversion from String to const wchar_t*

This commit is contained in:
Tsuda Kageyu 2013-06-11 00:09:37 +09:00
parent 7e866e11ad
commit 62d55223b2
3 changed files with 18 additions and 1 deletions

View File

@ -312,6 +312,11 @@ const char *String::toCString(bool unicode) const
return d->cstring.c_str();
}
const wchar_t *String::toCWString() const
{
return d->data.c_str();
}
String::Iterator String::begin()
{
return d->data.begin();

View File

@ -205,7 +205,16 @@ namespace TagLib {
* where memory is critical.
*/
const char *toCString(bool unicode = false) const;
/*!
* Returns a pointer to the wide char version of the TagLib string. The string
* is encoded in UTF-16(without BOM/CPU byte order).
*
* /note This returns a pointer to the String's internal data without any
* conversions.
*/
const wchar_t *toCWString() const;
/*!
* Returns an iterator pointing to the beginning of the string.
*/

View File

@ -72,6 +72,9 @@ public:
String unicode2(unicode.to8Bit(true), String::UTF8);
CPPUNIT_ASSERT(unicode == unicode2);
String unicode3(L"\u65E5\u672C\u8A9E");
CPPUNIT_ASSERT(*(unicode3.toCWString() + 1) == L'\u672C');
CPPUNIT_ASSERT(strcmp(String::number(0).toCString(), "0") == 0);
CPPUNIT_ASSERT(strcmp(String::number(12345678).toCString(), "12345678") == 0);
CPPUNIT_ASSERT(strcmp(String::number(-12345678).toCString(), "-12345678") == 0);