15#include "kmime_charfreq.h" 
   19CharFreq::CharFreq(  const TQByteArray & buf )  
   33    count( buf.data(), buf.size() );  
   36CharFreq::CharFreq(  const char * buf,  size_t len )  
   53static inline bool isWS(  char ch ) {  return ( ch ==  '\t' || ch ==  ' ' ); }  
   55void CharFreq::count(  const char * it,  size_t len ) {  
   57  const char * end = it + len;  
   58  uint currentLineLength = 0;  
   62  char prevPrevChar = 0;  
   64  for ( ; it != end ; ++it ) {  
   67    case '\0': ++NUL;  break;  
   68    case '\r': ++CR;   break;  
   70      if ( prevChar ==  '\r' ) { --currentLineLength; ++CRLF; }  
   71      if ( currentLineLength >= lineMax ) lineMax = currentLineLength-1;  
   72      if ( currentLineLength <= lineMin ) lineMin = currentLineLength-1;  
   74    if ( isWS( prevChar ) || ( prevChar ==  '\r' && isWS( prevPrevChar ) ) )  
   76      currentLineLength = 0;  
   80    if ( prevChar ==  '\n' && end - it >= 5 && !tqstrncmp(  "From ", it, 5 ) )  
   87    if ( (c ==  '\t') || ((c >=  ' ') && (c <=  '~')) )  
   89    else if ( (c == 127) || (c <  ' ') )  
   95    prevPrevChar = prevChar;  
  100  if ( currentLineLength >= lineMax ) lineMax = currentLineLength;  
  101  if ( currentLineLength <= lineMin ) lineMin = currentLineLength;  
  104  if ( isWS( prevChar ) )  
  110bool CharFreq::isEightBitData()  const {  
  111  return type() == EightBitData;  
  114bool CharFreq::isEightBitText()  const {  
  115  return type() == EightBitText;  
  118bool CharFreq::isSevenBitData()  const {  
  119  return type() == SevenBitData;  
  122bool CharFreq::isSevenBitText()  const {  
  123  return type() == SevenBitText;  
  126bool CharFreq::hasTrailingWhitespace()  const {  
  130bool CharFreq::hasLeadingFrom()  const {  
  134CharFreq::Type CharFreq::type()  const {  
  136  tqDebug(  "Total: %d; NUL: %d; CTL: %d;\n" 
  137      "CR: %d; LF: %d; CRLF: %d;\n" 
  138      "lineMin: %d; lineMax: %d;\n" 
  139      "printable: %d; eightBit: %d;\n" 
  140          "trailing whitespace: %s;\n" 
  141          "leading 'From ': %s;\n",  
  142      total, NUL, CTL, CR, LF, CRLF, lineMin, lineMax,  
  144      mTrailingWS ?  "yes" :  "no" , mLeadingFrom ?  "yes" :  "no" );  
  151    if ( lineMax > 988 )  return EightBitData;   
  152    if ( CR != CRLF || controlCodesRatio() > 0.2 )  return EightBitData;  
  157  if ( lineMax > 988 )  return SevenBitData;  
  158  if ( CR != CRLF || controlCodesRatio() > 0.2 )  return SevenBitData;  
  164float CharFreq::printableRatio()  const {  
  165  if ( total )  return float(printable) / float(total);  
  169float CharFreq::controlCodesRatio()  const {  
  170  if ( total )  return float(CTL) / float(total);  
  
           
        
        
          
         
        
      
      
    
    
    
  
 |