trunk/branch integration: TextEncoding update

This commit is contained in:
Marian Krivos
2011-08-22 18:22:56 +00:00
parent d35ecf85a2
commit e066d033a2
8 changed files with 391 additions and 80 deletions

View File

@@ -55,6 +55,7 @@ TextIterator::TextIterator(const std::string& str, const TextEncoding& encoding)
{
}
TextIterator::TextIterator(const std::string::const_iterator& begin, const std::string::const_iterator& end, const TextEncoding& encoding):
_pEncoding(&encoding),
_it(begin),
@@ -116,22 +117,36 @@ int TextIterator::operator * () const
{
poco_check_ptr (_pEncoding);
poco_assert (_it != _end);
std::string::const_iterator it = _it;
unsigned char c = (unsigned char) *_it;
int n = _pEncoding->characterMap()[c];
if (n >= -1)
return n;
unsigned char buffer[TextEncoding::MAX_SEQUENCE_LENGTH];
unsigned char* p = buffer;
if (it != _end)
*p++ = *it++;
else
*p++ = 0;
int read = 1;
int n = _pEncoding->queryConvert(buffer, 1);
while (-1 > n && (_end - it) >= -n - read)
{
while (read < -n && it != _end)
{
*p++ = *it++;
read++;
}
n = _pEncoding->queryConvert(buffer, read);
}
if (-1 > n)
{
return -1;
}
else
{
poco_assert_dbg (n >= -TextEncoding::MAX_SEQUENCE_LENGTH);
unsigned char buffer[TextEncoding::MAX_SEQUENCE_LENGTH];
unsigned char* p = buffer;
std::string::const_iterator it = _it;
while (n < 0 && it != _end) { *p++ = *it++; ++n; }
if (n == 0)
return _pEncoding->convert(buffer);
else
return -1;
return n;
}
}
@@ -141,12 +156,31 @@ TextIterator& TextIterator::operator ++ ()
poco_check_ptr (_pEncoding);
poco_assert (_it != _end);
unsigned char c = (unsigned char) *_it;
int n = _pEncoding->characterMap()[c];
if (n >= -1)
++_it;
unsigned char buffer[TextEncoding::MAX_SEQUENCE_LENGTH];
unsigned char* p = buffer;
if (_it != _end)
*p++ = *_it++;
else
while (n < 0 && _it != _end) { ++_it; ++n; }
*p++ = 0;
int read = 1;
int n = _pEncoding->sequenceLength(buffer, 1);
while (-1 > n && (_end - _it) >= -n - read)
{
while (read < -n && _it != _end)
{
*p++ = *_it++;
read++;
}
n = _pEncoding->sequenceLength(buffer, read);
}
while (read < n && _it != _end)
{
_it++;
read++;
}
return *this;
}