calendarui/regionalplugins/calenregionalutil/src/calenextrarowformatter.cpp
changeset 50 579cc610882e
parent 49 5de72ea7a065
child 58 ef813d54df51
equal deleted inserted replaced
49:5de72ea7a065 50:579cc610882e
    22 #include <eikenv.h>
    22 #include <eikenv.h>
    23 
    23 
    24 #include "calendarui_debug.h"
    24 #include "calendarui_debug.h"
    25 #include "CalenExtraRowFormatter.h"
    25 #include "CalenExtraRowFormatter.h"
    26 
    26 
       
    27 // Constants
       
    28 const TInt KZero( 0 );
       
    29 
    27 // -----------------------------------------------------------------------------
    30 // -----------------------------------------------------------------------------
    28 // CollapseDuplicatesL
    31 // CollapseDuplicatesL
    29 // -----------------------------------------------------------------------------
    32 // -----------------------------------------------------------------------------
    30 //
    33 //
    31 void CollapseDuplicatesL( TDes& aStr, TInt aPos, const TDesC& aSub )
    34 void CollapseDuplicatesL( TDes& aStr, TInt aPos, const TDesC& aSub )
    32     {
    35     {
    33     TRACE_ENTRY_POINT;
    36     TRACE_ENTRY_POINT;
    34     
    37     
    35     const TInt sublen = aSub.Length();
    38     const TInt sublen = aSub.Length();
    36     if (aStr.Length() == 0 || sublen == 0)
    39     if (aStr.Length() == KZero || sublen == KZero || aPos < KZero || (aPos >aStr.Length()))
    37         {
    40         {
    38         return;
    41         return;
    39         }
    42         }
    40 
    43 
    41     TPtrC remaining = aStr.Mid( aPos );
    44     TPtrC remaining = aStr.Mid( aPos );
    42     TInt fstInRemaining = remaining.Find( aSub );
    45     TInt fstInRemaining = remaining.Find( aSub );
    43     
    46     
    44     if ( fstInRemaining >= 0 )
    47     if ( fstInRemaining >= KZero )
    45         {
    48         {
    46         TInt restPos = fstInRemaining + sublen;
    49         TInt restPos = fstInRemaining + sublen;
    47         TPtrC rest = remaining.Mid( restPos );
    50         TPtrC rest = remaining.Mid( restPos );
    48         TInt sndInRest = rest.Find( aSub );
    51         TInt sndInRest = rest.Find( aSub );
    49 
    52 
    50         // 1) two substrings found in sequence 
    53         // 1) two substrings found in sequence 
    51         if (sndInRest == 0)
    54         if (sndInRest == KZero)
    52             { 
    55             { 
    53             // replace second substring with empty string
    56             // replace second substring with empty string
    54             TInt fst = aPos + fstInRemaining;
    57             TInt fst = aPos + fstInRemaining;
    55             TInt snd = aPos + restPos + sndInRest;
    58             TInt snd = aPos + restPos + sndInRest;
    56             aStr.Replace( snd, sublen, KNullDesC);
    59             aStr.Replace( snd, sublen, KNullDesC);
    57             // continue collapsing from first 
    60             // continue collapsing from first 
    58             CollapseDuplicatesL( aStr, fst, aSub );
    61             CollapseDuplicatesL( aStr, fst, aSub );
    59             }
    62             }
    60         // 2) substring found later in string 
    63         // 2) substring found later in string 
    61         else if (sndInRest > 0)
    64         else if (sndInRest > KZero)
    62             {         
    65             {         
    63             // continue collapsing from this second substring
    66             // continue collapsing from this second substring
    64             TInt snd = aPos + restPos + sndInRest;
    67             TInt snd = aPos + restPos + sndInRest;
    65             CollapseDuplicatesL( aStr, snd, aSub );
    68             CollapseDuplicatesL( aStr, snd, aSub );
    66             }
    69             }
    87     {
    90     {
    88     TRACE_ENTRY_POINT;
    91     TRACE_ENTRY_POINT;
    89     
    92     
    90     // Trailing
    93     // Trailing
    91     const TInt sublen = aSub.Length();
    94     const TInt sublen = aSub.Length();
    92     if ( aStr.Right( sublen ).Find( aSub ) == 0 )
    95     if ( aStr.Right( sublen ).Find( aSub ) == KZero )
    93         {
    96         {
    94         aStr.Replace( aStr.Length() - sublen, sublen, KNullDesC );
    97         aStr.Replace( aStr.Length() - sublen, sublen, KNullDesC );
    95         }
    98         }
    96 
    99 
    97     // Leading 
   100     // Leading 
    98     if ( aStr.Left( sublen ).Find( aSub ) == 0 )
   101     if ( aStr.Left( sublen ).Find( aSub ) == KZero )
    99         {
   102         {
   100         aStr.Replace( 0, sublen, KNullDesC );
   103         aStr.Replace( KZero, sublen, KNullDesC );
   101         }
   104         }
   102         
   105         
   103     TRACE_EXIT_POINT;
   106     TRACE_EXIT_POINT;
   104     }
   107     }
   105 
   108 
   160     RArray<CCalenLunarLocalizedInfo::TField>& aPrioritizedFields )
   163     RArray<CCalenLunarLocalizedInfo::TField>& aPrioritizedFields )
   161 {
   164 {
   162 	TRACE_ENTRY_POINT;
   165 	TRACE_ENTRY_POINT;
   163 
   166 
   164 
   167 
   165 	if ( aPrioritizedFields.Count() == 0)
   168 	if ( aPrioritizedFields.Count() == KZero)
   166 	{
   169 	{
   167 		iText = KNullDesC;
   170 		iText = KNullDesC;
   168 
   171 
   169 		TRACE_EXIT_POINT;
   172 		TRACE_EXIT_POINT;
   170 		return iText;
   173 		return iText;
   180 	subLabels.AppendL( CCalenLunarLocalizedInfo::ESolarTerm );
   183 	subLabels.AppendL( CCalenLunarLocalizedInfo::ESolarTerm );
   181 
   184 
   182 	// ASSERT that all prioritized fields can be found from subLabels
   185 	// ASSERT that all prioritized fields can be found from subLabels
   183 	for ( TInt i=0; i < aPrioritizedFields.Count(); i++)
   186 	for ( TInt i=0; i < aPrioritizedFields.Count(); i++)
   184 	{
   187 	{
   185 		ASSERT( subLabels.Find( aPrioritizedFields[i] ) >= 0 ); 
   188 		ASSERT( subLabels.Find( aPrioritizedFields[i] ) >= KZero );
   186 	}
   189 	}
   187 
   190 
   188 	// Initialize substring array 
   191 	// Initialize substring array 
   189 	CPtrCArray* subs = new (ELeave) CPtrCArray(10);
   192 	CPtrCArray* subs = new (ELeave) CPtrCArray(10);
   190 	CleanupStack::PushL( subs );
   193 	CleanupStack::PushL( subs );