mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-30 13:47:10 +01:00
trunk/branch integration: optimalization
This commit is contained in:
@@ -41,7 +41,8 @@
|
|||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
HexBinaryDecoderBuf::HexBinaryDecoderBuf(std::istream& istr): _istr(istr)
|
HexBinaryDecoderBuf::HexBinaryDecoderBuf(std::istream& istr):
|
||||||
|
_buf(*istr.rdbuf())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,13 +62,13 @@ int HexBinaryDecoderBuf::readFromDevice()
|
|||||||
else if (n >= 'A' && n <= 'F')
|
else if (n >= 'A' && n <= 'F')
|
||||||
c = n - 'A' + 10;
|
c = n - 'A' + 10;
|
||||||
else if (n >= 'a' && n <= 'f')
|
else if (n >= 'a' && n <= 'f')
|
||||||
c = n - 'a' + 10;
|
c = n - 'a' + 10;
|
||||||
else throw DataFormatException();
|
else throw DataFormatException();
|
||||||
c <<= 4;
|
c <<= 4;
|
||||||
if ((n = readOne()) == -1) return -1;
|
if ((n = readOne()) == -1) throw DataFormatException();
|
||||||
if (n >= '0' && n <= '9')
|
if (n >= '0' && n <= '9')
|
||||||
c |= n - '0';
|
c |= n - '0';
|
||||||
else if (n >= 'A' && n <= 'F')
|
else if (n >= 'A' && n <= 'F')
|
||||||
c |= n - 'A' + 10;
|
c |= n - 'A' + 10;
|
||||||
else if (n >= 'a' && n <= 'f')
|
else if (n >= 'a' && n <= 'f')
|
||||||
c |= n - 'a' + 10;
|
c |= n - 'a' + 10;
|
||||||
@@ -78,10 +79,10 @@ int HexBinaryDecoderBuf::readFromDevice()
|
|||||||
|
|
||||||
int HexBinaryDecoderBuf::readOne()
|
int HexBinaryDecoderBuf::readOne()
|
||||||
{
|
{
|
||||||
int ch = _istr.get();
|
int ch = _buf.sbumpc();
|
||||||
while (ch == ' ' || ch == '\r' || ch == '\t' || ch == '\n')
|
while (ch == ' ' || ch == '\r' || ch == '\t' || ch == '\n')
|
||||||
ch = _istr.get();
|
ch = _buf.sbumpc();
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// HexBinaryEncoder.cpp
|
// HexBinaryEncoder.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/HexBinaryEncoder.cpp#2 $
|
// $Id: //poco/1.4/Foundation/src/HexBinaryEncoder.cpp#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Streams
|
// Package: Streams
|
||||||
@@ -41,10 +41,10 @@ namespace Poco {
|
|||||||
|
|
||||||
|
|
||||||
HexBinaryEncoderBuf::HexBinaryEncoderBuf(std::ostream& ostr):
|
HexBinaryEncoderBuf::HexBinaryEncoderBuf(std::ostream& ostr):
|
||||||
_pos(0),
|
_pos(0),
|
||||||
_lineLength(72),
|
_lineLength(72),
|
||||||
_uppercase(0),
|
_uppercase(0),
|
||||||
_ostr(ostr)
|
_buf(*ostr.rdbuf())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,24 +81,25 @@ void HexBinaryEncoderBuf::setUppercase(bool flag)
|
|||||||
|
|
||||||
int HexBinaryEncoderBuf::writeToDevice(char c)
|
int HexBinaryEncoderBuf::writeToDevice(char c)
|
||||||
{
|
{
|
||||||
static const char digits[] = "0123456789abcdef0123456789ABCDEF";
|
static const int eof = std::char_traits<char>::eof();
|
||||||
_ostr.put(digits[_uppercase + ((c >> 4) & 0xF)]);
|
static const char digits[] = "0123456789abcdef0123456789ABCDEF";
|
||||||
++_pos;
|
|
||||||
_ostr.put(digits[_uppercase + (c & 0xF)]);
|
if (_buf.sputc(digits[_uppercase + ((c >> 4) & 0xF)]) == eof) return eof;
|
||||||
if (++_pos >= _lineLength && _lineLength > 0)
|
++_pos;
|
||||||
{
|
if (_buf.sputc(digits[_uppercase + (c & 0xF)]) == eof) return eof;
|
||||||
_ostr << std::endl;
|
if (++_pos >= _lineLength && _lineLength > 0)
|
||||||
_pos = 0;
|
{
|
||||||
}
|
if (_buf.sputc('\n') == eof) return eof;
|
||||||
return _ostr ? charToInt(c) : -1;
|
_pos = 0;
|
||||||
|
}
|
||||||
|
return charToInt(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int HexBinaryEncoderBuf::close()
|
int HexBinaryEncoderBuf::close()
|
||||||
{
|
{
|
||||||
sync();
|
sync();
|
||||||
_ostr.flush();
|
return _buf.pubsync();
|
||||||
return _ostr ? 0 : -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user