BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
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 40 of file base64.h.

Member Typedef Documentation

◆ byte_t

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

Definition at line 42 of file base64.h.

◆ char_type

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

Definition at line 43 of file base64.h.

◆ traits_type

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

Definition at line 44 of file base64.h.

Member Function Documentation

◆ _getCharType()

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

Definition at line 326 of file base64.h.

326 {
327 if ( _base64Chars[62] == _Ch ) return 62;
328
329 if ( _base64Chars[63] == _Ch ) return 63;
330
331 if ( ( _base64Chars[0] <= _Ch ) && ( _base64Chars[25] >= _Ch ) )
332 return _Ch - _base64Chars[0];
333
334 if ( ( _base64Chars[26] <= _Ch ) && ( _base64Chars[51] >= _Ch ) )
335 return _Ch - _base64Chars[26] + 26;
336
337 if ( ( _base64Chars[52] <= _Ch ) && ( _base64Chars[61] >= _Ch ) )
338 return _Ch - _base64Chars[52] + 52;
339
340 if ( _Ch == _Tr::to_int_type( '=' ) ) return _EQUAL_CHAR;
341
342 return _UNKNOWN_CHAR;
343 }

Referenced by get().

◆ get()

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 198 of file base64.h.

198 {
200 int _Char;
201
202 while ( _First != _Last )
203 {
204
205 // Take octet
206 _3to4.zero();
207
208 // -- 0 --
209 // Search next valid char...
210 while ( ( _Char = _getCharType( *_First ) ) < 0 && _Char == _UNKNOWN_CHAR )
211 {
212 if ( ++_First == _Last )
213 {
215 return _First; // unexpected EOF
216 }
217 }
218
219 if ( _Char == _EQUAL_CHAR )
220 {
221 // Error! First character in octet can't be '='
222 _St |= _IOS_FAILBIT;
223 return _First;
224 }
225 else _3to4.b64_0( _Char );
226
227 // -- 1 --
228 // Search next valid char...
229 while ( ++_First != _Last )
230 if ( ( _Char = _getCharType( *_First ) ) != _UNKNOWN_CHAR ) break;
231
232 if ( _First == _Last )
233 {
234 _St |= _IOS_FAILBIT | _IOS_EOFBIT; // unexpected EOF
235 return _First;
236 }
237
238 if ( _Char == _EQUAL_CHAR )
239 {
240 // Error! Second character in octet can't be '='
241 _St |= _IOS_FAILBIT;
242 return _First;
243 }
244 else _3to4.b64_1( _Char );
245
246 // -- 2 --
247 // Search next valid char...
248 while ( ++_First != _Last )
249 if ( ( _Char = _getCharType( *_First ) ) != _UNKNOWN_CHAR ) break;
250
251 if ( _First == _Last )
252 {
253 // Error! Unexpected EOF. Must be '=' or base64 character
255 return _First;
256 }
257
258 if ( _Char == _EQUAL_CHAR )
259 {
260 // OK!
261 _3to4.b64_2( 0 );
262 _3to4.b64_3( 0 );
263
264 // chek for EOF
265 if ( ++_First == _Last )
266 {
267 // Error! Unexpected EOF. Must be '='. Ignore it.
268 //_St |= _IOS_BADBIT|_IOS_EOFBIT;
269 _St |= _IOS_EOFBIT;
270 }
271 else if ( _getCharType( *_First ) != _EQUAL_CHAR )
272 {
273 // Error! Must be '='. Ignore it.
274 //_St |= _IOS_BADBIT;
275 }
276 else ++_First; // Skip '='
277
278 // write 1 byte to output
279 *_To = (byte_t)_3to4.get_0();
280 return _First;
281 }
282 else _3to4.b64_2( _Char );
283
284 // -- 3 --
285 // Search next valid char...
286 while ( ++_First != _Last )
287 if ( ( _Char = _getCharType( *_First ) ) != _UNKNOWN_CHAR ) break;
288
289 if ( _First == _Last )
290 {
291 // Unexpected EOF. It's error. But ignore it.
292 //_St |= _IOS_FAILBIT|_IOS_EOFBIT;
293 _St |= _IOS_EOFBIT;
294
295 return _First;
296 }
297
298 if ( _Char == _EQUAL_CHAR )
299 {
300 // OK!
301 _3to4.b64_3( 0 );
302
303 // write to output 2 bytes
304 *_To = (byte_t)_3to4.get_0();
305 *_To = (byte_t)_3to4.get_1();
306
307 ++_First; // set position to next character
308
309 return _First;
310 }
311 else _3to4.b64_3( _Char );
312
313 // write to output 3 bytes
314 *_To = (byte_t)_3to4.get_0();
315 *_To = (byte_t)_3to4.get_1();
316 *_To = (byte_t)_3to4.get_2();
317
318 ++_First;
319
320 } // while(_First != _Last)
321
322 return ( _First );
323 }
unsigned char byte_t
Definition base64.h:42
int _getCharType(int _Ch) const
Definition base64.h:326

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

◆ put()

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 129 of file base64.h.

129 {
131 int line_octets = 0;
132
133 while ( _First != _Last )
134 {
135 _3to4.zero();
136
137 // берём по 3 символа
138 _3to4.set_0( *_First );
139 _First++;
140
141 if ( _First == _Last )
142 {
144 ++_To;
146 ++_To;
147 *_To = _Tr::to_char_type( '=' );
148 ++_To;
149 *_To = _Tr::to_char_type( '=' );
150 ++_To;
151 goto __end;
152 }
153
154 _3to4.set_1( *_First );
155 _First++;
156
157 if ( _First == _Last )
158 {
160 ++_To;
162 ++_To;
164 ++_To;
165 *_To = _Tr::to_char_type( '=' );
166 ++_To;
167 goto __end;
168 }
169
170 _3to4.set_2( *_First );
171 _First++;
172
174 ++_To;
176 ++_To;
178 ++_To;
180 ++_To;
181
182 if ( line_octets == 17 ) // base64 позволяет длину строки не более 72 символов
183 {
184 //_To = _Endl(_To);
185 *_To = '\n';
186 ++_To;
187 line_octets = 0;
188 }
189 else ++line_octets;
190 }
191
192 __end:;
193
194 return ( _First );
195 }

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


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