コード例 #1
0
ファイル: TIFF_Support.cpp プロジェクト: JanX2/exempi
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' ) {
コード例 #2
0
ファイル: TIFF_Support.cpp プロジェクト: Metrilus/xmp-sharp
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' ) {