bool TIFF_Manager::DecodeString ( const void * encodedPtr, size_t encodedLen, std::string* utf8Str ) const { XMP_StringPtr typePtr = (XMP_StringPtr)encodedPtr; XMP_StringPtr valuePtr = typePtr + 8; size_t valueLen = encodedLen - 8; utf8Str->erase(); if ( *typePtr == 'A' ) { utf8Str->assign ( valuePtr, valueLen ); return true; } else if ( *typePtr == 'U' ) { try { const UTF16Unit * utf16Ptr = (const UTF16Unit *) valuePtr; size_t utf16Len = valueLen >> 1; // The number of UTF-16 storage units, not bytes. if ( utf16Len == 0 ) return false; bool isBigEndian = this->bigEndian; // Default to stream endian, unless there is a BOM ... if ( (*utf16Ptr == 0xFEFF) || (*utf16Ptr == 0xFFFE) ) { // Check for an explicit BOM isBigEndian = (*((XMP_Uns8*)utf16Ptr) == 0xFE); utf16Ptr += 1; // Don't translate the BOM. utf16Len -= 1; if ( utf16Len == 0 ) return false; } UTF16_to_UTF8 ( utf16Ptr, utf16Len, isBigEndian, utf8Str ); return true; } catch ( ... ) { return false; // Ignore the tag if there are conversion errors. } } else if ( *typePtr == 'J' ) {
bool TIFF_Manager::DecodeString ( const void * encodedPtr, size_t encodedLen, std::string* utf8Str ) const { XMP_StringPtr typePtr = (XMP_StringPtr)encodedPtr; XMP_StringPtr valuePtr = typePtr + 8; size_t valueLen = encodedLen - 8; utf8Str->erase(); if ( *typePtr == 'A' ) { utf8Str->assign ( valuePtr, valueLen ); return true; } else if ( *typePtr == 'U' ) { try { const UTF16Unit * utf16Ptr = (const UTF16Unit *) valuePtr; size_t utf16Len = valueLen >> 1; // The number of UTF-16 storage units, not bytes. UTF16_to_UTF8 ( utf16Ptr, utf16Len, this->bigEndian, utf8Str ); return true; } catch ( ... ) { return false; // Ignore the tag if there are conversion errors. } } else if ( *typePtr == 'J' ) {