]> granicus.if.org Git - taglib/commitdiff
Added conversion from String to const wchar_t*
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Mon, 10 Jun 2013 15:09:37 +0000 (00:09 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Sun, 23 Jun 2013 16:13:25 +0000 (01:13 +0900)
taglib/toolkit/tstring.cpp
taglib/toolkit/tstring.h
tests/test_string.cpp

index d28855b8c0323f49aec06890c4bfa041f33b6bea..c83118d120e521b0e09a391b842340b6659021f3 100644 (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();
index d353bcd9afe698bf71c49e24ac9930a5154cc310..569650eb881329d563138b39b87ef17b5c8a166a 100644 (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.
      */
index f29769191f019a26a09f8725ac4253318cf53509..a815a0b46fe4fb31e1eff2b638e68928ec43cc38 100644 (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);