Mercurial > libavformat.hg
changeset 1180:92fdb5e2a2d7 libavformat
simplify b64_encode()
maybe this should be moved to libavutil ...
author | michael |
---|---|
date | Tue, 18 Jul 2006 18:51:35 +0000 |
parents | 6b79be0860e3 |
children | c2f51d81c72e |
files | http.c |
diffstat | 1 files changed, 9 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/http.c Mon Jul 17 21:51:21 2006 +0000 +++ b/http.c Tue Jul 18 18:51:35 2006 +0000 @@ -285,6 +285,7 @@ /***************************************************************************** * b64_encode: stolen from VLC's http.c + * simplified by michael *****************************************************************************/ static char *b64_encode( const unsigned char *src ) @@ -300,32 +301,17 @@ }else return NULL; - for( ;; ) - { - if( *src ) - { - i_bits = ( i_bits << 8 )|( *src++ ); - i_shift += 8; - } - else if( i_shift > 0 ) - { - i_bits <<= 6 - i_shift; - i_shift = 6; - } - else - { - *dst++ = '='; - break; - } + while(*src){ + i_bits = (i_bits << 8) + *src++; + i_shift += 8; - while( i_shift >= 6 ) - { + do{ + *dst++ = b64[(i_bits << 6 >> i_shift) & 0x3f]; i_shift -= 6; - *dst++ = b64[(i_bits >> i_shift)&0x3f]; - } + }while( i_shift > 6 || (*src == 0 && i_shift>0)); } - - *dst++ = '\0'; + *dst++ = '='; + *dst = '\0'; return ret; }