MCPcopy Create free account
hub / github.com/Exiv2/exiv2 / FromUTF16

Function FromUTF16

xmpsdk/src/UnicodeConversions.cpp:363–383  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

361// =================================================================================================
362
363extern void FromUTF16 ( const UTF16Unit * utf16In, size_t utf16Len, std::string * utf8Str, bool bigEndian )
364{
365 UTF16_to_UTF8_Proc Converter = UTF16LE_to_UTF8;
366 if ( bigEndian ) Converter = UTF16BE_to_UTF8;
367
368 enum { kBufferSize = 16*1024 };
369 UTF8Unit u8Buffer[kBufferSize];
370 size_t readCount, writeCount;
371
372 utf8Str->erase();
373 utf8Str->reserve ( 2*utf16Len ); // As good a guess as any.
374
375 while ( utf16Len > 0 ) {
376 Converter ( utf16In, utf16Len, u8Buffer, kBufferSize, &readCount, &writeCount );
377 if ( writeCount == 0 ) UC_Throw ( "Incomplete Unicode at end of string", kXMPErr_BadXML );
378 utf8Str->append ( (const char *)u8Buffer, writeCount );
379 utf16In += readCount;
380 utf16Len -= readCount;
381 }
382
383} // FromUTF16
384
385// =================================================================================================
386

Callers

nothing calls this directly

Calls 3

ConverterClass · 0.85
reserveMethod · 0.80
eraseMethod · 0.45

Tested by

no test coverage detected