trunk: TextEncoding fixes

This commit is contained in:
Marian Krivos 2012-02-09 15:15:39 +00:00
parent 4f6c5241c1
commit 7c3339c549
7 changed files with 59 additions and 10 deletions

View File

@ -61,6 +61,8 @@ public:
const CharacterMap& characterMap() const;
int convert(const unsigned char* bytes) const;
int convert(int ch, unsigned char* bytes, int length) const;
int queryConvert(const unsigned char* bytes, int length) const;
int sequenceLength(const unsigned char* bytes, int length) const;
private:
static const char* _names[];

View File

@ -59,6 +59,8 @@ public:
const CharacterMap& characterMap() const;
int convert(const unsigned char* bytes) const;
int convert(int ch, unsigned char* bytes, int length) const;
int queryConvert(const unsigned char* bytes, int length) const;
int sequenceLength(const unsigned char* bytes, int length) const;
private:
static const char* _names[];

View File

@ -59,6 +59,8 @@ public:
const CharacterMap& characterMap() const;
int convert(const unsigned char* bytes) const;
int convert(int ch, unsigned char* bytes, int length) const;
int queryConvert(const unsigned char* bytes, int length) const;
int sequenceLength(const unsigned char* bytes, int length) const;
private:
static const char* _names[];

View File

@ -106,13 +106,13 @@ const TextEncoding::CharacterMap& Latin1Encoding::characterMap() const
int Latin1Encoding::convert(const unsigned char* bytes) const
{
return *bytes;
return _charMap[*bytes];
}
int Latin1Encoding::convert(int ch, unsigned char* bytes, int length) const
{
if (ch >= 0 && ch <= 255)
if (ch >= 0 && ch <= 255 && _charMap[ch] == ch)
{
if (bytes && length >= 1)
*bytes = (unsigned char) ch;
@ -125,7 +125,7 @@ int Latin1Encoding::convert(int ch, unsigned char* bytes, int length) const
int Latin1Encoding::queryConvert(const unsigned char* bytes, int length) const
{
if (1 <= length)
return *bytes;
return _charMap[*bytes];
else
return -1;
}

View File

@ -106,16 +106,16 @@ const TextEncoding::CharacterMap& Latin2Encoding::characterMap() const
int Latin2Encoding::convert(const unsigned char* bytes) const
{
return *bytes;
return _charMap[*bytes];
}
int Latin2Encoding::convert(int ch, unsigned char* bytes, int length) const
{
if (ch >= 0 && ch <= 255)
if (ch >= 0 && ch <= 255 && _charMap[ch] == ch)
{
if (bytes && length >= 1)
*bytes = ch;
*bytes = (unsigned char) ch;
return 1;
}
else switch (ch)
@ -133,5 +133,19 @@ int Latin2Encoding::convert(int ch, unsigned char* bytes, int length) const
}
}
int Latin2Encoding::queryConvert(const unsigned char* bytes, int length) const
{
if (1 <= length)
return _charMap[*bytes];
else
return -1;
}
int Latin2Encoding::sequenceLength(const unsigned char* bytes, int length) const
{
return 1;
}
} // namespace Poco

View File

@ -106,13 +106,13 @@ const TextEncoding::CharacterMap& Windows1250Encoding::characterMap() const
int Windows1250Encoding::convert(const unsigned char* bytes) const
{
return *bytes;
return _charMap[*bytes];
}
int Windows1250Encoding::convert(int ch, unsigned char* bytes, int length) const
{
if (ch >= 0 && ch <= 255)
if (ch >= 0 && ch <= 255 && _charMap[ch] == ch)
{
if (bytes && length >= 1)
*bytes = (unsigned char) ch;
@ -121,5 +121,20 @@ int Windows1250Encoding::convert(int ch, unsigned char* bytes, int length) const
else return 0;
}
int Windows1250Encoding::queryConvert(const unsigned char* bytes, int length) const
{
if (1 <= length)
return _charMap[*bytes];
else
return -1;
}
int Windows1250Encoding::sequenceLength(const unsigned char* bytes, int length) const
{
return 1;
}
} // namespace Poco

View File

@ -106,13 +106,13 @@ const TextEncoding::CharacterMap& Windows1251Encoding::characterMap() const
int Windows1251Encoding::convert(const unsigned char* bytes) const
{
return *bytes;
return _charMap[*bytes];
}
int Windows1251Encoding::convert(int ch, unsigned char* bytes, int length) const
{
if (ch >= 0 && ch <= 255)
if (ch >= 0 && ch <= 255 && _charMap[ch] == ch)
{
if (bytes && length >= 1)
*bytes = (unsigned char) ch;
@ -121,5 +121,19 @@ int Windows1251Encoding::convert(int ch, unsigned char* bytes, int length) const
else return 0;
}
int Windows1251Encoding::queryConvert(const unsigned char* bytes, int length) const
{
if (1 <= length)
return _charMap[*bytes];
else
return -1;
}
int Windows1251Encoding::sequenceLength(const unsigned char* bytes, int length) const
{
return 1;
}
} // namespace Poco