Beispiel #1
0
void CFileDataIO::WriteLongString(const CString& rstr, EUtf8Str eEncode)
{
#define	WRITE_STR_LEN(n)	WriteUInt32(n)
	if (eEncode == utf8strRaw)
	{
		CUnicodeToUTF8 utf8(rstr);
		WRITE_STR_LEN(utf8.GetLength());
		Write((LPCSTR)utf8, utf8.GetLength());
	}
	else if (eEncode == utf8strOptBOM)
	{
		if (NeedUTF8String(rstr))
		{
			CUnicodeToBOMUTF8 bomutf8(rstr);
			WRITE_STR_LEN(bomutf8.GetLength());
			Write((LPCSTR)bomutf8, bomutf8.GetLength());
		}
		else
		{
			CUnicodeToMultiByte mb(rstr);
			WRITE_STR_LEN(mb.GetLength());
			Write((LPCSTR)mb, mb.GetLength());
		}
	}
	else
	{
		CUnicodeToMultiByte mb(rstr);
		WRITE_STR_LEN(mb.GetLength());
		Write((LPCSTR)mb, mb.GetLength());
	}
#undef WRITE_STR_LEN
}
Beispiel #2
0
bool CTag::WriteNewEd2kTag(CFileDataIO* data, EUtf8Str eStrEncode) const
{
	ASSERT_VALID(this);

	// Write tag type
	uint8 uType;
	UINT uStrValLen = 0;
	LPCSTR pszValA = NULL;
	CStringA* pstrValA = NULL;
	if (IsInt())
	{
		if (m_uVal <= 0xFF)
			uType = TAGTYPE_UINT8;
		else if (m_uVal <= 0xFFFF)
			uType = TAGTYPE_UINT16;
		else
			uType = TAGTYPE_UINT32;
	}
	else if (IsStr())
	{
#ifdef _UNICODE
		if (eStrEncode == utf8strRaw)
		{
			CUnicodeToUTF8 utf8(*m_pstrVal);
			pstrValA = new CStringA((LPCSTR)utf8, utf8.GetLength());
		}
		else if (eStrEncode == utf8strOptBOM)
		{
			if (NeedUTF8String(*m_pstrVal))
			{
				CUnicodeToBOMUTF8 bomutf8(*m_pstrVal);
				pstrValA = new CStringA((LPCSTR)bomutf8, bomutf8.GetLength());
			}
			else
			{
				CUnicodeToMultiByte mb(*m_pstrVal);
				pstrValA = new CStringA((LPCSTR)mb, mb.GetLength());
			}
		}
		else
		{
			CUnicodeToMultiByte mb(*m_pstrVal);
			pstrValA = new CStringA((LPCSTR)mb, mb.GetLength());
		}
		uStrValLen = pstrValA->GetLength();
		pszValA = *pstrValA;
#else
		uStrValLen = m_pstrVal->GetLength();
		pszValA = *m_pstrVal;
#endif
		if (uStrValLen >= 1 && uStrValLen <= 16)
			uType = TAGTYPE_STR1 + uStrValLen - 1;
		else
			uType = TAGTYPE_STRING;
	}
	else
		uType = m_uType;

	// Write tag name
	if (m_pszName)
	{
		data->WriteUInt8(uType);
		UINT uTagNameLen = strlen(m_pszName);
		data->WriteUInt16(uTagNameLen);
		data->Write(m_pszName, uTagNameLen);
	}
	else
	{
		ASSERT( m_uName != 0 );
		data->WriteUInt8(uType | 0x80);
		data->WriteUInt8(m_uName);
	}

	// Write tag data
	if (uType == TAGTYPE_STRING)
	{
		data->WriteUInt16(uStrValLen);
		data->Write(pszValA, uStrValLen);
	}
	else if (uType >= TAGTYPE_STR1 && uType <= TAGTYPE_STR16)
	{
		data->Write(pszValA, uStrValLen);
	}
	else if (uType == TAGTYPE_UINT32)
	{
		data->WriteUInt32(m_uVal);
	}
	else if (uType == TAGTYPE_UINT16)
	{
		data->WriteUInt16(m_uVal);
	}
	else if (uType == TAGTYPE_UINT8)
	{
		data->WriteUInt8(m_uVal);
	}
	else if (uType == TAGTYPE_FLOAT32)
	{
		data->Write(&m_fVal, 4);
	}
	else if (uType == TAGTYPE_HASH)
	{
		data->WriteHash16(m_pData);
	}
	else if (uType == TAGTYPE_BLOB)
	{
		data->WriteUInt32(m_nBlobSize);
		data->Write(m_pData, m_nBlobSize);
	}
	else
	{
		TRACE("%s; Unknown tag: type=0x%02X\n", __FUNCTION__, uType);
		ASSERT(0);
		return false;
	}

	delete pstrValA;
	return true;
}
Beispiel #3
0
void CFileDataIO::WriteLongString(const CString& rstr, EUtf8Str eEncode)
{
#define	WRITE_STR_LEN(n)	WriteUInt32(n)
#ifdef _UNICODE
	if (eEncode == utf8strRaw)
	{
		CUnicodeToUTF8 utf8(rstr);
		WRITE_STR_LEN(utf8.GetLength());
		Write((LPCSTR)utf8, utf8.GetLength());
	}
	else if (eEncode == utf8strOptBOM)
	{
		if (NeedUTF8String(rstr))
		{
			CUnicodeToBOMUTF8 bomutf8(rstr);
			WRITE_STR_LEN(bomutf8.GetLength());
			Write((LPCSTR)bomutf8, bomutf8.GetLength());
		}
		else
		{
			CUnicodeToMultiByte mb(rstr);
			WRITE_STR_LEN(mb.GetLength());
			Write((LPCSTR)mb, mb.GetLength());
		}
	}
	else
	{
		CUnicodeToMultiByte mb(rstr);
		WRITE_STR_LEN(mb.GetLength());
		Write((LPCSTR)mb, mb.GetLength());
	}
#else
	if (eEncode == utf8strRaw)
	{
		CStringW wstr(rstr);
		CUnicodeToUTF8 utf8(wstr);
		WRITE_STR_LEN(utf8.GetLength());
		Write((LPCSTR)utf8, utf8.GetLength());
	}
	else if (eEncode == utf8strOptBOM)
	{
		CStringW wstr(rstr);
		if (NeedUTF8String(wstr))
		{
			CUnicodeToBOMUTF8 bomutf8(wstr);
			WRITE_STR_LEN(bomutf8.GetLength());
			Write((LPCSTR)bomutf8, bomutf8.GetLength());
		}
		else
		{
			CUnicodeToMultiByte mb(wstr);
			WRITE_STR_LEN(mb.GetLength());
			Write((LPCSTR)mb, mb.GetLength());
		}
	}
	else
	{
		UINT uLen = rstr.GetLength();
		WRITE_STR_LEN(uLen);
		Write((LPCSTR)rstr, uLen);
	}
#endif
#undef WRITE_STR_LEN
}