diff -r fd30d51f876b -r b6db4fd4947b calendarui/regionalplugins/calenregionalutil/src/calenextrarowformatter.cpp --- a/calendarui/regionalplugins/calenregionalutil/src/calenextrarowformatter.cpp Mon May 03 12:30:32 2010 +0300 +++ b/calendarui/regionalplugins/calenregionalutil/src/calenextrarowformatter.cpp Mon Jun 28 15:22:02 2010 +0530 @@ -15,16 +15,18 @@ * */ - +#include +#include -#include #include #include -#include #include "calendarui_debug.h" #include "CalenExtraRowFormatter.h" +// Constants +const TInt KZero( 0 ); + // ----------------------------------------------------------------------------- // CollapseDuplicatesL // ----------------------------------------------------------------------------- @@ -34,7 +36,7 @@ TRACE_ENTRY_POINT; const TInt sublen = aSub.Length(); - if (aStr.Length() == 0 || sublen == 0) + if (aStr.Length() == KZero || sublen == KZero || aPos < KZero || (aPos >aStr.Length())) { return; } @@ -42,14 +44,14 @@ TPtrC remaining = aStr.Mid( aPos ); TInt fstInRemaining = remaining.Find( aSub ); - if ( fstInRemaining >= 0 ) + if ( fstInRemaining >= KZero ) { TInt restPos = fstInRemaining + sublen; TPtrC rest = remaining.Mid( restPos ); TInt sndInRest = rest.Find( aSub ); // 1) two substrings found in sequence - if (sndInRest == 0) + if (sndInRest == KZero) { // replace second substring with empty string TInt fst = aPos + fstInRemaining; @@ -59,7 +61,7 @@ CollapseDuplicatesL( aStr, fst, aSub ); } // 2) substring found later in string - else if (sndInRest > 0) + else if (sndInRest > KZero) { // continue collapsing from this second substring TInt snd = aPos + restPos + sndInRest; @@ -90,15 +92,15 @@ // Trailing const TInt sublen = aSub.Length(); - if ( aStr.Right( sublen ).Find( aSub ) == 0 ) + if ( aStr.Right( sublen ).Find( aSub ) == KZero ) { aStr.Replace( aStr.Length() - sublen, sublen, KNullDesC ); } // Leading - if ( aStr.Left( sublen ).Find( aSub ) == 0 ) + if ( aStr.Left( sublen ).Find( aSub ) == KZero ) { - aStr.Replace( 0, sublen, KNullDesC ); + aStr.Replace( KZero, sublen, KNullDesC ); } TRACE_EXIT_POINT; @@ -159,45 +161,44 @@ EXPORT_C TPtrC CCalenExtraRowFormatter::FormatExtraRowInformationL( CCalenLunarLocalizedInfo& aLocInfo, RArray& aPrioritizedFields ) - { - TRACE_ENTRY_POINT; - - - if ( aPrioritizedFields.Count() == 0) - { - iText = KNullDesC; - - TRACE_EXIT_POINT; - return iText; - } +{ + TRACE_ENTRY_POINT; + + + if ( aPrioritizedFields.Count() == KZero) + { + iText = KNullDesC; + + TRACE_EXIT_POINT; + return iText; + } - // Initialize substring labels - RArray subLabels; - CleanupClosePushL( subLabels ); - subLabels.AppendL( CCalenLunarLocalizedInfo::EAnimalYear ); - subLabels.AppendL( CCalenLunarLocalizedInfo::ELunarYear ); - subLabels.AppendL( CCalenLunarLocalizedInfo::ELunarMonthAndDay ); - subLabels.AppendL( CCalenLunarLocalizedInfo::EFestival ); - subLabels.AppendL( CCalenLunarLocalizedInfo::ESolarTerm ); - - // ASSERT that all prioritized fields can be found from subLabels - for ( TInt i=0; i < aPrioritizedFields.Count(); i++) - { - ASSERT( subLabels.Find( aPrioritizedFields[i] ) >= 0 ); - } + // Initialize substring labels + RArray subLabels; + CleanupClosePushL( subLabels ); + subLabels.AppendL( CCalenLunarLocalizedInfo::EAnimalYear ); + subLabels.AppendL( CCalenLunarLocalizedInfo::ELunarYear ); + subLabels.AppendL( CCalenLunarLocalizedInfo::ELunarMonthAndDay ); + subLabels.AppendL( CCalenLunarLocalizedInfo::EFestival ); + subLabels.AppendL( CCalenLunarLocalizedInfo::ESolarTerm ); + + // ASSERT that all prioritized fields can be found from subLabels + for ( TInt i=0; i < aPrioritizedFields.Count(); i++) + { + ASSERT( subLabels.Find( aPrioritizedFields[i] ) >= KZero ); + } // Initialize substring array CPtrCArray* subs = new (ELeave) CPtrCArray(10); CleanupStack::PushL( subs ); for ( TInt i = 0; i < subLabels.Count(); i++) - { + { subs->AppendL( TPtrC( KNullDesC ) ); - } - // subs->InsertL( 0, TPtrC( KNullDesC ), 5 ); - + } + // Set wanted fields to substring array for ( TInt i = 0; i < aPrioritizedFields.Count(); i++) - { + { CCalenLunarLocalizedInfo::TField field = aPrioritizedFields[i]; TInt subIx = subLabels.Find( field ); // Replace @@ -206,71 +207,50 @@ subs->InsertL(subIx, TPtrC( aLocInfo.GetField( field ) ) ); RDebug::Print( _L("B sub count %d"), subs->Count() ); RDebug::Print( _L("B field %S"), &(subs->At(subIx)) ); - - } - - // Format all fields to extra row - HBufC* extraRowFmt = StringLoader::LoadLC( R_CALE_EXTRA_ROW_LUNAR ); - - RDebug::RawPrint( *extraRowFmt ); - - TBuf<1000> fmt = *extraRowFmt; - for (TInt i=0; i < subLabels.Count(); i++) - { - RDebug::Print( _L("Before Format") ); - RDebug::RawPrint( fmt ); - StringLoader::Format( iText, - fmt, - i + 1, // %0U is a separator - subs->At( i ) ); - fmt = iText; - RDebug::Print( _L("After Format") ); - RDebug::RawPrint( fmt ); - } - - // Now we have something like "Year of Dog%0U%0U6/11%0U%0U" - // First We need to remove multiple occurences of %0U - _LIT(KSeparatorFmt, "%0U"); - - CollapseDuplicatesL( iText, 0, KSeparatorFmt ); - RDebug::Print( _L("After collapse") ); - RDebug::RawPrint( iText ); - // Remove leading and trailing %0U - // By now, we are sure that there is max 1 %0U in the beginning - // and in the end of string. - RemoveLeadingAndTrailingL( iText, KSeparatorFmt ); - RDebug::Print( _L("After leading and trailing removal") ); - RDebug::RawPrint( iText ); - - - // If there are now separators anymore, then do not fill them - TBool hasSeparators = iText.Find( KSeparatorFmt ) >= 0; - - if ( hasSeparators ) - { + } + TBuf<100> textBuf; + QStringList textDataStringList; + for (TInt i=0; i < subLabels.Count(); i++) { + textBuf = subs->At( i ); + textDataStringList.append( + QString((QChar*)textBuf.Ptr(),textBuf.Length())); + } + // Get the locale specific separator + QString separator = hbTrId("txt_calendar_preview_title_cale_separator"); - // fill in separators - HBufC* separator = StringLoader::LoadLC( R_CALE_LUNAR_SEPARATOR ); - fmt = iText; - StringLoader::Format( iText, - fmt, - 0, // %0U is a separator - *separator ); + // Format all fields to single row + QString textDataString; + textDataString = hbTrId( + "txt_calendar_preview_title_123242526").arg( + textDataStringList.at(0)).arg( + separator).arg( + textDataStringList.at(1)).arg( + textDataStringList.at(2)).arg( + textDataStringList.at(3)).arg( + textDataStringList.at(4)); + + iText = static_cast ( + textDataString.utf16()), textDataString.length(); + + // Now we have something like "Year of Dog%2GengYin%2%2" + // where %2 is the separator txt_calendar_preview_title_cale_separator + // First We need to remove multiple occurences of separator + textBuf = static_cast ( + separator.utf16()), separator.length(); + CollapseDuplicatesL( iText, 0, textBuf); - RDebug::Print( _L("After separator insert") ); - RDebug::RawPrint( iText ); - CleanupStack::PopAndDestroy( separator ); - } - - - CleanupStack::PopAndDestroy( extraRowFmt ); + // Remove leading and trailing separators + // Leading separator won't be there but trailing one is there for sure + RemoveLeadingAndTrailingL( iText, textBuf ); + + // CleanUp CleanupStack::PopAndDestroy( subs ); - CleanupStack::PopAndDestroy( &subLabels ); - - TRACE_EXIT_POINT; - return iText; - } + CleanupStack::PopAndDestroy( &subLabels ); + TRACE_EXIT_POINT; + + return iText; +} //EOF