OverSim
base64< _E, _Tr > Class Template Reference

#include <base64.h>

Classes

struct  crlf
struct  crlfsp
struct  noline
struct  three2four

Public Types

typedef unsigned char byte_t
typedef _E char_type
typedef _Tr traits_type

Public Member Functions

template<class _II , class _OI , class _State , class _Endline >
_II put (_II _First, _II _Last, _OI _To, _State &_St, _Endline _Endl) const
template<class _II , class _OI , class _State >
_II get (_II _First, _II _Last, _OI _To, _State &_St) const

Protected Member Functions

int _getCharType (int _Ch) const

Detailed Description

template<class _E = char, class _Tr = std::char_traits<_E>>
class base64< _E, _Tr >

Definition at line 42 of file base64.h.

Member Typedef Documentation

template<class _E = char, class _Tr = std::char_traits<_E>>
typedef unsigned char base64< _E, _Tr >::byte_t

Definition at line 46 of file base64.h.

template<class _E = char, class _Tr = std::char_traits<_E>>
typedef _E base64< _E, _Tr >::char_type

Definition at line 47 of file base64.h.

template<class _E = char, class _Tr = std::char_traits<_E>>
typedef _Tr base64< _E, _Tr >::traits_type

Definition at line 48 of file base64.h.

Member Function Documentation

template<class _E = char, class _Tr = std::char_traits<_E>>
int base64< _E, _Tr >::_getCharType ( int  _Ch) const
inlineprotected

Definition at line 352 of file base64.h.

Referenced by base64< _E, _Tr >::get().

{
if(_base64Chars[62] == _Ch)
return 62;
if(_base64Chars[63] == _Ch)
return 63;
if((_base64Chars[0] <= _Ch) && (_base64Chars[25] >= _Ch))
return _Ch - _base64Chars[0];
if((_base64Chars[26] <= _Ch) && (_base64Chars[51] >= _Ch))
return _Ch - _base64Chars[26] + 26;
if((_base64Chars[52] <= _Ch) && (_base64Chars[61] >= _Ch))
return _Ch - _base64Chars[52] + 52;
if(_Ch == _Tr::to_int_type('='))
return _EQUAL_CHAR;
return _UNKNOWN_CHAR;
}
template<class _E = char, class _Tr = std::char_traits<_E>>
template<class _II , class _OI , class _State >
_II base64< _E, _Tr >::get ( _II  _First,
_II  _Last,
_OI  _To,
_State &  _St 
) const
inline

Definition at line 215 of file base64.h.

Referenced by XmlRpc::XmlRpcValue::binaryFromXml().

{
three2four _3to4;
int _Char;
while(_First != _Last)
{
// Take octet
_3to4.zero();
// -- 0 --
// Search next valid char...
while((_Char = _getCharType(*_First)) < 0 && _Char == _UNKNOWN_CHAR)
{
if(++_First == _Last)
{
_St |= _IOS_FAILBIT|_IOS_EOFBIT; return _First; // unexpected EOF
}
}
if(_Char == _EQUAL_CHAR){
// Error! First character in octet can't be '='
_St |= _IOS_FAILBIT;
return _First;
}
else
_3to4.b64_0(_Char);
// -- 1 --
// Search next valid char...
while(++_First != _Last)
if((_Char = _getCharType(*_First)) != _UNKNOWN_CHAR)
break;
if(_First == _Last) {
_St |= _IOS_FAILBIT|_IOS_EOFBIT; // unexpected EOF
return _First;
}
if(_Char == _EQUAL_CHAR){
// Error! Second character in octet can't be '='
_St |= _IOS_FAILBIT;
return _First;
}
else
_3to4.b64_1(_Char);
// -- 2 --
// Search next valid char...
while(++_First != _Last)
if((_Char = _getCharType(*_First)) != _UNKNOWN_CHAR)
break;
if(_First == _Last) {
// Error! Unexpected EOF. Must be '=' or base64 character
return _First;
}
if(_Char == _EQUAL_CHAR){
// OK!
_3to4.b64_2(0);
_3to4.b64_3(0);
// chek for EOF
if(++_First == _Last)
{
// Error! Unexpected EOF. Must be '='. Ignore it.
//_St |= _IOS_BADBIT|_IOS_EOFBIT;
_St |= _IOS_EOFBIT;
}
else
if(_getCharType(*_First) != _EQUAL_CHAR)
{
// Error! Must be '='. Ignore it.
//_St |= _IOS_BADBIT;
}
else
++_First; // Skip '='
// write 1 byte to output
*_To = (byte_t) _3to4.get_0();
return _First;
}
else
_3to4.b64_2(_Char);
// -- 3 --
// Search next valid char...
while(++_First != _Last)
if((_Char = _getCharType(*_First)) != _UNKNOWN_CHAR)
break;
if(_First == _Last) {
// Unexpected EOF. It's error. But ignore it.
//_St |= _IOS_FAILBIT|_IOS_EOFBIT;
_St |= _IOS_EOFBIT;
return _First;
}
if(_Char == _EQUAL_CHAR)
{
// OK!
_3to4.b64_3(0);
// write to output 2 bytes
*_To = (byte_t) _3to4.get_0();
*_To = (byte_t) _3to4.get_1();
++_First; // set position to next character
return _First;
}
else
_3to4.b64_3(_Char);
// write to output 3 bytes
*_To = (byte_t) _3to4.get_0();
*_To = (byte_t) _3to4.get_1();
*_To = (byte_t) _3to4.get_2();
++_First;
} // while(_First != _Last)
return (_First);
}
template<class _E = char, class _Tr = std::char_traits<_E>>
template<class _II , class _OI , class _State , class _Endline >
_II base64< _E, _Tr >::put ( _II  _First,
_II  _Last,
_OI  _To,
_State &  _St,
_Endline  _Endl 
) const
inline

Definition at line 155 of file base64.h.

Referenced by XmlRpc::XmlRpcValue::binaryToXml(), XmlRpc::XmlRpcClient::generateHeader(), and XmlRpc::XmlRpcValue::write().

{
three2four _3to4;
int line_octets = 0;
while(_First != _Last)
{
_3to4.zero();
// берём по 3 символа
_3to4.set_0(*_First);
_First++;
if(_First == _Last)
{
*_To = _Tr::to_char_type(_base64Chars[_3to4.b64_0()]); ++_To;
*_To = _Tr::to_char_type(_base64Chars[_3to4.b64_1()]); ++_To;
*_To = _Tr::to_char_type('='); ++_To;
*_To = _Tr::to_char_type('='); ++_To;
goto __end;
}
_3to4.set_1(*_First);
_First++;
if(_First == _Last)
{
*_To = _Tr::to_char_type(_base64Chars[_3to4.b64_0()]); ++_To;
*_To = _Tr::to_char_type(_base64Chars[_3to4.b64_1()]); ++_To;
*_To = _Tr::to_char_type(_base64Chars[_3to4.b64_2()]); ++_To;
*_To = _Tr::to_char_type('='); ++_To;
goto __end;
}
_3to4.set_2(*_First);
_First++;
*_To = _Tr::to_char_type(_base64Chars[_3to4.b64_0()]); ++_To;
*_To = _Tr::to_char_type(_base64Chars[_3to4.b64_1()]); ++_To;
*_To = _Tr::to_char_type(_base64Chars[_3to4.b64_2()]); ++_To;
*_To = _Tr::to_char_type(_base64Chars[_3to4.b64_3()]); ++_To;
if(line_octets == 17) // base64 позволяет длину строки не более 72 символов
{
//_To = _Endl(_To);
*_To = '\n'; ++_To;
line_octets = 0;
}
else
++line_octets;
}
__end: ;
return (_First);
}

The documentation for this class was generated from the following file: