0001 int encode ( HuffTable* table, Bitmap* codeString, char* s ) { //按照编码表对Bitmap串编码 0002 int n = 0; //待返回的编码串总长n 0003 for ( size_t m = strlen ( s ), i = 0; i < m; i++ ) { //对于明文中的每个字符 0004 char** pCharCode = table->get ( s[i] ); //取出其对应的编码串 0005 //if ( !pCharCode ) pCharCode = table->get ( s[i] + 'A' - 'a' ); //小写字母转为大写 0006 //if ( !pCharCode ) pCharCode = table->get ( ' ' ); //无法识别的字符统一视作空格 0007 printf ( "%s", *pCharCode ); //输出当前字符的编码 0008 for ( size_t m = strlen ( *pCharCode ), j = 0; j < m; j++ ) //将当前字符的编码接入编码串 0009 '1' == * ( *pCharCode + j ) ? codeString->set ( n++ ) : codeString->clear ( n++ ); 0010 } 0011 printf ( "\n" ); return n; 0012 } //二进制编码串记录于位图codeString中