Windows2003-3790/inetcore/outlookexpress/mailnews/fechrcnv/convbase.cpp
2020-09-30 16:53:55 +02:00

80 lines
1.9 KiB
C++

// =================================================================================
// Internet Character Set Conversion: Base Class
// =================================================================================
#include "pch.hxx"
#include "ConvBase.h"
CINetCodeConverter::CINetCodeConverter()
{
nNumOverflowBytes = 0;
}
HRESULT CINetCodeConverter::GetStringSizeA(BYTE const* pbySource, long lSourceSize, long* plDestSize)
{
fOutputMode = FALSE;
return WalkString(pbySource, lSourceSize, plDestSize);
}
HRESULT CINetCodeConverter::ConvertStringA(BYTE const* pbySource, long lSourceSize, BYTE* pbyDest, long lDestSize, long* lConvertedSize)
{
HRESULT hr;
fOutputMode = TRUE;
pbyOutput = pbyDest;
lOutputLimit = lDestSize;
// Output those bytes which could not be output at previous time.
if (FAILED(hr = OutputOverflowBuffer()))
return hr;
return WalkString(pbySource, lSourceSize, lConvertedSize);
}
HRESULT CINetCodeConverter::WalkString(BYTE const* pbySource, long lSourceSize, long* lConvertedSize)
{
HRESULT hr = S_OK;
lNumOutputBytes = 0;
if (pbySource) {
while (lSourceSize-- > 0) {
if (FAILED(hr = ConvertByte(*pbySource++)))
break;
}
} else {
hr = CleanUp();
}
if (lConvertedSize)
*lConvertedSize = lNumOutputBytes;
return hr;
}
HRESULT CINetCodeConverter::EndOfDest(BYTE by)
{
if (nNumOverflowBytes < MAXOVERFLOWBYTES)
OverflowBuffer[nNumOverflowBytes++] = by;
return E_FAIL;
}
HRESULT CINetCodeConverter::OutputOverflowBuffer()
{
for (int n = 0; n < nNumOverflowBytes; n++) {
if (lNumOutputBytes < lOutputLimit) {
*pbyOutput++ = OverflowBuffer[n];
lNumOutputBytes++;
} else {
// Overflow again
for (int n2 = 0; n < nNumOverflowBytes; n++, n2++)
OverflowBuffer[n2] = OverflowBuffer[n];
nNumOverflowBytes = n2;
return E_FAIL;
}
}
return S_OK;
}