[dali_1.1.15] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / character-set-conversion.cpp
index aa2721a..ac8b317 100644 (file)
@@ -24,6 +24,9 @@ namespace Dali
 namespace Toolkit
 {
 
+namespace Text
+{
+
 namespace
 {
   const static uint8_t U1 = 1u;
@@ -68,6 +71,11 @@ namespace
   };
 } // namespace
 
+uint8_t GetUtf8Length( uint8_t utf8LeadByte )
+{
+  return UTF8_LENGTH[utf8LeadByte];
+}
+
 uint32_t GetNumberOfUtf8Characters( const uint8_t* const utf8, uint32_t length )
 {
   uint32_t numberOfCharacters = 0u;
@@ -173,11 +181,13 @@ uint32_t Utf8ToUtf32( const uint8_t* const utf8, uint32_t length, uint32_t* utf3
   return numberOfCharacters;
 }
 
-void Utf32ToUtf8( const uint32_t* const utf32, uint32_t numberOfCharacters, uint8_t* utf8 )
+uint32_t Utf32ToUtf8( const uint32_t* const utf32, uint32_t numberOfCharacters, uint8_t* utf8 )
 {
   const uint32_t* begin = utf32;
   const uint32_t* end = utf32 + numberOfCharacters;
 
+  uint8_t* utf8Begin = utf8;
+
   for( ; begin < end; ++begin )
   {
     const uint32_t code = *begin;
@@ -205,8 +215,23 @@ void Utf32ToUtf8( const uint32_t* const utf32, uint32_t numberOfCharacters, uint
       *utf8++ = static_cast<uint8_t>(   code          & 0x3f ) | 0x80u; // continuation byte
     }
   }
+
+  return utf8 - utf8Begin;
 }
 
+void Utf32ToUtf8( const uint32_t* const utf32, uint32_t numberOfCharacters, std::string& utf8 )
+{
+  utf8.clear();
+
+  uint32_t numberOfBytes = GetNumberOfUtf8Bytes( &utf32[0], numberOfCharacters );
+  utf8.resize( numberOfBytes );
+
+  // This is a bit horrible but std::string returns a (signed) char*
+  Utf32ToUtf8( utf32, numberOfCharacters, reinterpret_cast<uint8_t*>(&utf8[0]) );
+}
+
+} // namespace Text
+
 } // namespace Toolkit
 
 } // namespace Dali