File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4141namespace Poco {
4242
4343
44- HexBinaryDecoderBuf::HexBinaryDecoderBuf (std::istream& istr): _istr(istr)
44+ HexBinaryDecoderBuf::HexBinaryDecoderBuf (std::istream& istr):
45+ _buf (*istr.rdbuf())
4546{
4647}
4748
@@ -61,13 +62,13 @@ int HexBinaryDecoderBuf::readFromDevice()
6162 else if (n >= ' A' && n <= ' F' )
6263 c = n - ' A' + 10 ;
6364 else if (n >= ' a' && n <= ' f' )
64- c = n - ' a' + 10 ;
65- else throw DataFormatException ();
66- c <<= 4 ;
67- if ((n = readOne ()) == -1 ) return - 1 ;
68- if (n >= ' 0' && n <= ' 9' )
69- c |= n - ' 0' ;
70- else if (n >= ' A' && n <= ' F' )
65+ c = n - ' a' + 10 ;
66+ else throw DataFormatException ();
67+ c <<= 4 ;
68+ if ((n = readOne ()) == -1 ) throw DataFormatException () ;
69+ if (n >= ' 0' && n <= ' 9' )
70+ c |= n - ' 0' ;
71+ else if (n >= ' A' && n <= ' F' )
7172 c |= n - ' A' + 10 ;
7273 else if (n >= ' a' && n <= ' f' )
7374 c |= n - ' a' + 10 ;
@@ -78,10 +79,10 @@ int HexBinaryDecoderBuf::readFromDevice()
7879
7980int HexBinaryDecoderBuf::readOne ()
8081{
81- int ch = _istr. get ();
82- while (ch == ' ' || ch == ' \r ' || ch == ' \t ' || ch == ' \n ' )
83- ch = _istr. get ();
84- return ch;
82+ int ch = _buf. sbumpc ();
83+ while (ch == ' ' || ch == ' \r ' || ch == ' \t ' || ch == ' \n ' )
84+ ch = _buf. sbumpc ();
85+ return ch;
8586}
8687
8788
Original file line number Diff line number Diff line change 11//
22// HexBinaryEncoder.cpp
33//
4- // $Id: //poco/svn /Foundation/src/HexBinaryEncoder.cpp#2 $
4+ // $Id: //poco/1.4 /Foundation/src/HexBinaryEncoder.cpp#2 $
55//
66// Library: Foundation
77// Package: Streams
@@ -41,10 +41,10 @@ namespace Poco {
4141
4242
4343HexBinaryEncoderBuf::HexBinaryEncoderBuf (std::ostream& ostr):
44- _pos (0 ),
45- _lineLength (72 ),
46- _uppercase (0 ),
47- _ostr ( ostr)
44+ _pos (0 ),
45+ _lineLength (72 ),
46+ _uppercase (0 ),
47+ _buf (* ostr.rdbuf() )
4848{
4949}
5050
@@ -81,24 +81,25 @@ void HexBinaryEncoderBuf::setUppercase(bool flag)
8181
8282int HexBinaryEncoderBuf::writeToDevice (char c)
8383{
84- static const char digits[] = " 0123456789abcdef0123456789ABCDEF" ;
85- _ostr.put (digits[_uppercase + ((c >> 4 ) & 0xF )]);
86- ++_pos;
87- _ostr.put (digits[_uppercase + (c & 0xF )]);
88- if (++_pos >= _lineLength && _lineLength > 0 )
89- {
90- _ostr << std::endl;
91- _pos = 0 ;
92- }
93- return _ostr ? charToInt (c) : -1 ;
84+ static const int eof = std::char_traits<char >::eof ();
85+ static const char digits[] = " 0123456789abcdef0123456789ABCDEF" ;
86+
87+ if (_buf.sputc (digits[_uppercase + ((c >> 4 ) & 0xF )]) == eof) return eof;
88+ ++_pos;
89+ if (_buf.sputc (digits[_uppercase + (c & 0xF )]) == eof) return eof;
90+ if (++_pos >= _lineLength && _lineLength > 0 )
91+ {
92+ if (_buf.sputc (' \n ' ) == eof) return eof;
93+ _pos = 0 ;
94+ }
95+ return charToInt (c);
9496}
9597
9698
9799int HexBinaryEncoderBuf::close ()
98100{
99- sync ();
100- _ostr.flush ();
101- return _ostr ? 0 : -1 ;
101+ sync ();
102+ return _buf.pubsync ();
102103}
103104
104105
You can’t perform that action at this time.
0 commit comments