predictivesearch/PcsAlgorithm/Algorithm1/src/CPcsAlgorithm1Utils.cpp
branchRCL_3
changeset 3 04ab22b956c2
parent 0 e686773b3f54
child 15 e8e3147d53eb
equal deleted inserted replaced
0:e686773b3f54 3:04ab22b956c2
    74     	}
    74     	}
    75     }
    75     }
    76 }
    76 }
    77 
    77 
    78 // ----------------------------------------------------------------------------
    78 // ----------------------------------------------------------------------------
       
    79 // CPcsAlgorithm1Utils::CompareByLength()
       
    80 // Compare by length.
       
    81 // ----------------------------------------------------------------------------
       
    82 TBool CPcsAlgorithm1Utils::CompareByLength ( const HBufC& aFirst, const HBufC& aSecond )
       
    83 {
       
    84    return ( aFirst.Length() > aSecond.Length() );
       
    85 }
       
    86 
       
    87 // ----------------------------------------------------------------------------
       
    88 // CPcsAlgorithm1Utils::CompareExact()
       
    89 // Compare strings exactly case sensitively.
       
    90 // ----------------------------------------------------------------------------
       
    91 TBool CPcsAlgorithm1Utils::CompareExact ( const TDesC& aFirst, const TDesC& aSecond )
       
    92 {
       
    93     return aFirst == aSecond;
       
    94 }
       
    95 
       
    96 // ----------------------------------------------------------------------------
       
    97 // CPcsAlgorithm1Utils::CompareCollate()
       
    98 // Compare strings with collate rules depending on locale.
       
    99 // ----------------------------------------------------------------------------
       
   100 TBool CPcsAlgorithm1Utils::CompareCollate ( const TDesC& aFirst, const TDesC& aSecond )
       
   101 {
       
   102     return CPcsAlgorithm1Utils::MyCompareC(aFirst, aSecond);
       
   103 }
       
   104 
       
   105 // ----------------------------------------------------------------------------
       
   106 // CPcsAlgorithm1Utils::MyCompareKeyAndString()
       
   107 // Compare for keys and strings:
       
   108 // - Case sensitive compare for keys,
       
   109 // - Case insensitive and language dependent compare for Contact Data and Query.
       
   110 // ----------------------------------------------------------------------------
       
   111 TBool CPcsAlgorithm1Utils::MyCompareKeyAndString(const TDesC& aContactString,
       
   112                                                  const TDesC& aQueryAsString,
       
   113                                                  CPsQuery& aPsQuery)
       
   114 {
       
   115     TBool comparison = MyCompareK(aContactString, aQueryAsString, aPsQuery); 
       
   116         
       
   117     if (comparison)
       
   118         {
       
   119         // The aContactString can be longer than aQueryAsString and we want a match to be
       
   120         // successful if both strings are equal for the length of the query (aQueryAsString)
       
   121         comparison = (MyCompareC(aContactString.Left(aQueryAsString.Length()), aQueryAsString) == 0);
       
   122         }
       
   123     
       
   124     return comparison;
       
   125 }
       
   126 
       
   127 // ----------------------------------------------------------------------------
    79 // CPcsAlgorithm1Utils::MyCompareK()
   128 // CPcsAlgorithm1Utils::MyCompareK()
    80 // Case sensitive compare for keys of first 2 input params.
   129 // Case sensitive compare for keys of first 2 input params.
       
   130 // INFO: We have some cases that TPtiKey "Z" (uppercase) is mapping chars "Zz...."
       
   131 //       and TPtiKey "z" (lowercase) is mapping chars ".," or "Ää".
       
   132 //       The comparison of "Z" and "z" should fail for the keys.
    81 // ----------------------------------------------------------------------------
   133 // ----------------------------------------------------------------------------
    82 TBool CPcsAlgorithm1Utils::MyCompareK(const TDesC& aLeft, const TDesC& aRight, CPsQuery& aPsQuery)
   134 TBool CPcsAlgorithm1Utils::MyCompareK(const TDesC& aLeft, const TDesC& aRight, CPsQuery& aPsQuery)
    83 {
   135 {
    84     TBool comparison = ETrue;
   136     TBool comparison = ETrue;
    85 
   137