logsui/logscntfinder/src/logspredictivetranslator.cpp
changeset 16 c5af8598d22c
parent 11 64a47b97e1e1
child 21 2f0af9ba7665
equal deleted inserted replaced
14:f27aebe284bb 16:c5af8598d22c
   190                                                    const QString& pattern ) const
   190                                                    const QString& pattern ) const
   191 {
   191 {
   192     LOGS_QDEBUG( "logs [FINDER] -> LogsPredictiveTranslator::translatePattern()" )
   192     LOGS_QDEBUG( "logs [FINDER] -> LogsPredictiveTranslator::translatePattern()" )
   193     QString result = translate( pattern );
   193     QString result = translate( pattern );
   194     
   194     
       
   195     if ( !result.length() ) {
       
   196         result = pattern;
       
   197     }
   195     LOGS_QDEBUG( "logs [FINDER] <- LogsPredictiveTranslator::translatePattern()" )
   198     LOGS_QDEBUG( "logs [FINDER] <- LogsPredictiveTranslator::translatePattern()" )
   196     return result;
   199     return result;
   197 }
   200 }
   198 
   201 
   199 // -----------------------------------------------------------------------------
   202 // -----------------------------------------------------------------------------
   203 const QString LogsPredictiveTranslator::translate( const QString& text,
   206 const QString LogsPredictiveTranslator::translate( const QString& text,
   204                                                    bool* ok, int count ) const
   207                                                    bool* ok, int count ) const
   205 {
   208 {
   206     LOGS_QDEBUG( "logs [FINDER] -> LogsPredictiveTranslator::translate()" )
   209     LOGS_QDEBUG( "logs [FINDER] -> LogsPredictiveTranslator::translate()" )
   207     LOGS_QDEBUG_2( "logs [FINDER] text ", text );
   210     LOGS_QDEBUG_2( "logs [FINDER] text ", text );
       
   211     QString result;
       
   212     bool isok = ok ? *ok : true;
   208     
   213     
   209     count = count == -1 ? text.length() : count;
   214     count = count == -1 ? text.length() : count;
   210     bool isok = ok ? *ok : true;
       
   211     QString result;
       
   212     const QChar* content = text.data();
   215     const QChar* content = text.data();
   213     int index = 0;
   216     int index = 0;
   214     while( index < count && isok ) {
   217     while( index < count && isok ) {
   215         QChar ch = translateChar( *content++, isok );
   218         QChar ch = translateChar( *content++, isok );
   216         if ( !ch.isNull() ) {
   219         if ( !ch.isNull() ) {
   217             result.append( ch );
   220             result.append( ch );
   218         }
   221         }
   219         index++;
   222         index++;
   220     }
   223     }
       
   224     
   221     if ( ok ) {
   225     if ( ok ) {
   222         *ok = isok;
   226         *ok = isok;
   223     }
   227     }
   224     LOGS_QDEBUG( "logs [FINDER] <- LogsPredictiveTranslator::translate()" )
   228     LOGS_QDEBUG( "logs [FINDER] <- LogsPredictiveTranslator::translate()" )
   225     return result;
   229     return result;