logsui/logscntfinder/src/logscntentry.cpp
changeset 4 e52d42f9500c
parent 2 7119b73b84d6
child 15 76d2cf7a585e
equal deleted inserted replaced
2:7119b73b84d6 4:e52d42f9500c
   201 {
   201 {
   202     LogsPredictiveTranslator* translator = LogsPredictiveTranslator::instance();
   202     LogsPredictiveTranslator* translator = LogsPredictiveTranslator::instance();
   203     
   203     
   204     mCached=true;
   204     mCached=true;
   205     mPhoneNumber.mText = number;
   205     mPhoneNumber.mText = number;
   206     mPhoneNumber.mTranslatedText = translator->translate( mPhoneNumber.mText );
   206     mPhoneNumber.mTranslatedText = translator->translateText( mPhoneNumber.mText );
   207     
   207     
   208 }
   208 }
   209 
   209 
   210 
   210 
   211 // -----------------------------------------------------------------------------
   211 // -----------------------------------------------------------------------------
   219     QListIterator<QString> iter( translator->nameTokens( text ) );
   219     QListIterator<QString> iter( translator->nameTokens( text ) );
   220 
   220 
   221     while( iter.hasNext() ) {
   221     while( iter.hasNext() ) {
   222         LogsCntText txt;
   222         LogsCntText txt;
   223         txt.mText = iter.next();
   223         txt.mText = iter.next();
   224         txt.mTranslatedText = translator->translate( txt.mText );
   224         txt.mTranslatedText = translator->translateText( txt.mText );
   225         textlist.append( txt );
   225         textlist.append( txt );
   226     }
   226     }
   227     if ( textlist.count() == 0 ) {
   227     if ( textlist.count() == 0 ) {
   228         textlist.append( LogsCntText() );
   228         textlist.append( LogsCntText() );
   229     }
   229     }
   276     bool hasSeparators = translator->hasPatternSeparators( pattern );
   276     bool hasSeparators = translator->hasPatternSeparators( pattern );
   277     
   277     
   278     //simple
   278     //simple
   279     while( names.hasNext() ) {
   279     while( names.hasNext() ) {
   280         LogsCntText& nameItem = names.next();
   280         LogsCntText& nameItem = names.next();
   281         nameItem.mHighlights = 
   281         //must use non-optimized version with whole pattern
   282                 translator->startsWith( nameItem.mText, pattern, false );
   282         nameItem.mHighlights = startsWith( nameItem, pattern, false );
   283     }
   283     }
   284     
   284     
   285     //complex
   285     //complex
   286     QListIterator<QString> patternArray( translator->patternTokens( pattern ) );
   286     QListIterator<QString> patternArray( translator->patternTokens( pattern ) );
   287     while( hasSeparators && patternArray.hasNext() ) {
   287     while( hasSeparators && patternArray.hasNext() ) {
   288         QString patternItem = patternArray.next();
   288         QString patternItem = patternArray.next();
   289         names.toFront();
   289         names.toFront();
   290         while( names.hasNext() ) {
   290         while( names.hasNext() ) {
   291             LogsCntText& nameItem = names.next();
   291             LogsCntText& nameItem = names.next();
   292             int matchSize = translator->startsWith( nameItem.mText, 
   292             int matchSize = startsWith( nameItem, patternItem, !hasSeparators );
   293                                                     patternItem, !hasSeparators );
       
   294             nameItem.mHighlights = matchSize > nameItem.mHighlights ?
   293             nameItem.mHighlights = matchSize > nameItem.mHighlights ?
   295                                    matchSize : nameItem.mHighlights; 
   294                                    matchSize : nameItem.mHighlights; 
   296         }
   295         }
   297     }
   296     }
   298 }
   297 }
       
   298 
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // LogsCntEntry::startsWith()
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 int LogsCntEntry::startsWith( const LogsCntText& nameItem, 
       
   305                               const QString& pattern, bool optimize ) const
       
   306 {
       
   307     LOGS_QDEBUG( "logs [FINDER] -> LogsCntEntry::startsWith()" )
       
   308     //assumed that text has found based on pattern, thus only checking with
       
   309     //first char is enough, if mightContainZeroes eq false
       
   310     const QString& text = nameItem.mTranslatedText;
       
   311     
       
   312     int matchCount = pattern.length();
       
   313     if ( text.isEmpty() || matchCount > text.length() ) {
       
   314         matchCount = 0;
       
   315     } else {
       
   316         if ( !optimize ) {
       
   317             matchCount = text.startsWith( pattern ) ? matchCount : 0; 
       
   318         } else {
       
   319             matchCount = *text.data() == *pattern.data() ? 
       
   320                          matchCount : 0;
       
   321         }
       
   322     }
       
   323     LOGS_QDEBUG( "logs [FINDER] -> LogsCntEntry::startsWith()" )
       
   324     return matchCount;
       
   325 }
       
   326 
   299 
   327 
   300 // -----------------------------------------------------------------------------
   328 // -----------------------------------------------------------------------------
   301 // LogsCntEntry::setSpeedDial()
   329 // LogsCntEntry::setSpeedDial()
   302 // -----------------------------------------------------------------------------
   330 // -----------------------------------------------------------------------------
   303 //
   331 //