68 lines
1.9 KiB
C++
68 lines
1.9 KiB
C++
/* lw-support/src/lib/Exceptions/BadString.cpp
|
|
*
|
|
* (c)2005, Laurence Withers. Released under the GNU GPL. See file
|
|
* COPYING for more information / terms of license.
|
|
*/
|
|
|
|
namespace lw {
|
|
|
|
|
|
|
|
std::wstring BadSourceChar::buildDesc(const char* seqStart,
|
|
const char* seqEnd, int seqOffset, const std::wstring& encodingName,
|
|
const std::wstring& reason)
|
|
{
|
|
std::wostringstream o;
|
|
|
|
o << L"Error parsing a string. Details:\n"
|
|
L" Encoding : " << encodingName << L"\n"
|
|
L" Reason : " << reason << L"\n"
|
|
L" Byte offset : " << seqOffset << L"\n"
|
|
L" Bad sequence: ";
|
|
o << std::hex << std::setfill(L'0');
|
|
for(; seqStart != seqEnd; ++seqStart)
|
|
o << std::setw(2) << (uint)(uint8_t)(*seqStart);
|
|
|
|
return o.str();
|
|
}
|
|
|
|
|
|
BadSourceChar::BadSourceChar(const char* seqStart, const char* seqEnd,
|
|
int seqOffset, const std::wstring& encodingName, const std::wstring& reason)
|
|
: BadString(buildDesc(
|
|
seqStart, seqEnd, seqOffset, encodingName, reason)),
|
|
byteSeq(seqStart, seqEnd), seqOffset(seqOffset),
|
|
encoding(encodingName), reason(reason)
|
|
{
|
|
}
|
|
|
|
|
|
|
|
std::wstring CannotConvertChar::buildDesc(wchar_t srcChar, int seqOffset,
|
|
const std::wstring& srcEnc, const std::wstring& destEnc)
|
|
{
|
|
std::wostringstream o;
|
|
|
|
o << L"Error converting a string. Details:\n"
|
|
L" Source encoding : " << srcEnc << L"\n"
|
|
L" Destination encoding: " << destEnc << L"\n"
|
|
L" Byte offset : " << seqOffset << L"\n"
|
|
L" Source character : 0x" << std::hex << uint(srcChar)
|
|
<< L", ``" << srcChar << L"''.";
|
|
|
|
return o.str();
|
|
}
|
|
|
|
|
|
|
|
CannotConvertChar::CannotConvertChar(wchar_t srcChar, int seqOffset,
|
|
const std::wstring& srcEnc, const std::wstring& destEnc)
|
|
: BadString(buildDesc(srcChar, seqOffset, srcEnc, destEnc)),
|
|
srcChar(srcChar), seqOffset(seqOffset), srcEnc(srcEnc), destEnc(destEnc)
|
|
{
|
|
}
|
|
|
|
|
|
|
|
}
|