21 #include "easydialingutils.h" |
21 #include "easydialingutils.h" |
22 |
22 |
23 const TText KNameSeparatorChar = ' '; |
23 const TText KNameSeparatorChar = ' '; |
24 const TText KListFieldSeparatorChar = '\t'; |
24 const TText KListFieldSeparatorChar = '\t'; |
25 |
25 |
26 const TText KGraphicReplaceCharacter = ' '; |
|
27 |
|
28 // Zero Widthcharacters |
|
29 const TUint KZWSCharacter = 0x200B; |
|
30 const TUint KZWNJCharacter = 0x200C; |
|
31 const TUint KZWJCharacter = 0x200D; |
|
32 |
|
33 inline TBool ZWSCharacter( const TChar aChar ); |
|
34 |
|
35 void ReplaceNonGraphicCharacters( TDes& aText, TText aChar ); |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
26 // ----------------------------------------------------------------------------- |
38 // CreateContactStringLC |
27 // CreateContactStringLC |
39 // |
28 // |
40 // ----------------------------------------------------------------------------- |
29 // ----------------------------------------------------------------------------- |
41 // |
30 // |
46 CEasyDialingContactDataManager::TNameOrder aNameOrder ) |
35 CEasyDialingContactDataManager::TNameOrder aNameOrder ) |
47 { |
36 { |
48 // first strip control chars from the names |
37 // first strip control chars from the names |
49 HBufC* firstName = aFirstName.AllocLC(); |
38 HBufC* firstName = aFirstName.AllocLC(); |
50 TPtr fPtr = firstName->Des(); |
39 TPtr fPtr = firstName->Des(); |
51 ReplaceNonGraphicCharacters( fPtr, KGraphicReplaceCharacter ); |
|
52 AknTextUtils::StripCharacters( fPtr, KAknStripListControlChars ); |
40 AknTextUtils::StripCharacters( fPtr, KAknStripListControlChars ); |
53 |
41 |
54 HBufC* lastName = aLastName.AllocLC(); |
42 HBufC* lastName = aLastName.AllocLC(); |
55 TPtr lPtr = lastName->Des(); |
43 TPtr lPtr = lastName->Des(); |
56 ReplaceNonGraphicCharacters( lPtr, KGraphicReplaceCharacter ); |
|
57 AknTextUtils::StripCharacters( lPtr, KAknStripListControlChars ); |
44 AknTextUtils::StripCharacters( lPtr, KAknStripListControlChars ); |
58 |
45 |
59 HBufC* companyName = aCompanyName.AllocLC(); |
46 HBufC* companyName = aCompanyName.AllocLC(); |
60 TPtr cPtr = companyName->Des(); |
47 TPtr cPtr = companyName->Des(); |
61 ReplaceNonGraphicCharacters( cPtr, KGraphicReplaceCharacter ); |
|
62 AknTextUtils::StripCharacters( cPtr, KAknStripListControlChars ); |
48 AknTextUtils::StripCharacters( cPtr, KAknStripListControlChars ); |
63 |
49 |
64 // Calculate string lenght. If first name and last name are missing, company name is duplicated. |
50 // Calculate string lenght. If first name and last name are missing, company name is duplicated. |
65 // Add company name lenght twice to make sure there is enough space. |
51 // Add company name lenght twice to make sure there is enough space. |
66 TInt stringLength = firstName->Length() + lastName->Length() + 2 * companyName->Length() + 2; |
52 TInt stringLength = firstName->Length() + lastName->Length() + 2 * companyName->Length() + 2; |
111 CleanupStack::Pop( string ); |
97 CleanupStack::Pop( string ); |
112 CleanupStack::PopAndDestroy( 3, firstName ); |
98 CleanupStack::PopAndDestroy( 3, firstName ); |
113 CleanupStack::PushL( string ); |
99 CleanupStack::PushL( string ); |
114 return string; |
100 return string; |
115 } |
101 } |
116 |
|
117 /* |
|
118 * ============================================================================== |
|
119 * |
|
120 * Local functions |
|
121 * |
|
122 * ============================================================================== |
|
123 */ |
|
124 |
|
125 /** |
|
126 * Checkif the given char is a zero width character: |
|
127 * ZeroWidth Space, Zero Width Non-Joiner |
|
128 * orZero Width Joiner character |
|
129 * @paramaChar Given character |
|
130 *@return ETrue if aChar is zero width character. |
|
131 * EFalse if aChar is not specified zero width character. |
|
132 */ |
|
133 |
|
134 inline TBool ZWSCharacter( const TChar aChar ) |
|
135 { |
|
136 const TChar zwsChar( KZWSCharacter ); |
|
137 const TChar zwnjChar( KZWNJCharacter ); |
|
138 const TChar zwjChar( KZWJCharacter ); |
|
139 return ( aChar == zwsChar ) || ( aChar == zwnjChar ) || |
|
140 ( aChar == zwjChar ); |
|
141 } |
|
142 |
|
143 /** |
|
144 * Replaces all non-graphic characters (!TChar::IsGraph()) in |
|
145 * a string with the specified character. |
|
146 **/ |
|
147 |
|
148 void ReplaceNonGraphicCharacters( TDes& aText, TText aChar ) |
|
149 { |
|
150 const TInt len = aText.Length(); |
|
151 for ( TInt i = 0; i <len; ++i ) |
|
152 { |
|
153 if ( !TChar( aText[i] ).IsGraph() && !ZWSCharacter( aText[i] ) ) |
|
154 { |
|
155 //If non-graphic char is specified in ZWSCharacter, |
|
156 //it will not be replaced. Otherwise replace non-graphic |
|
157 //character with aChar. |
|
158 aText[i] = aChar; |
|
159 } |
|
160 } |
|
161 } |
|