author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 21:18:17 +0300 | |
branch | RCL_3 |
changeset 26 | 8baf28733c3d |
parent 25 | 5266b1f337bd |
permissions | -rw-r--r-- |
25 | 1 |
/* |
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
* All rights reserved. |
|
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Nokia Corporation - initial contribution. |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* |
|
14 |
* Description: Helper class for easydialing. |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
#include <e32std.h> |
|
19 |
#include <AknUtils.h> |
|
20 |
||
21 |
#include "easydialingutils.h" |
|
22 |
||
23 |
const TText KNameSeparatorChar = ' '; |
|
24 |
const TText KListFieldSeparatorChar = '\t'; |
|
25 |
||
26
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
26 |
const TText KGraphicReplaceCharacter = ' '; |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
27 |
|
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
28 |
// Zero Widthcharacters |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
29 |
const TUint KZWSCharacter = 0x200B; |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
30 |
const TUint KZWNJCharacter = 0x200C; |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
31 |
const TUint KZWJCharacter = 0x200D; |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
32 |
|
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
33 |
inline TBool ZWSCharacter( const TChar aChar ); |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
34 |
|
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
35 |
void ReplaceNonGraphicCharacters( TDes& aText, TText aChar ); |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
36 |
|
25 | 37 |
// ----------------------------------------------------------------------------- |
38 |
// CreateContactStringLC |
|
39 |
// |
|
40 |
// ----------------------------------------------------------------------------- |
|
41 |
// |
|
42 |
HBufC* EasyDialingUtils::CreateContactStringLC( |
|
43 |
const TDesC& aFirstName, |
|
44 |
const TDesC& aLastName, |
|
45 |
const TDesC& aCompanyName, |
|
46 |
CEasyDialingContactDataManager::TNameOrder aNameOrder ) |
|
47 |
{ |
|
48 |
// first strip control chars from the names |
|
49 |
HBufC* firstName = aFirstName.AllocLC(); |
|
50 |
TPtr fPtr = firstName->Des(); |
|
26
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
51 |
ReplaceNonGraphicCharacters( fPtr, KGraphicReplaceCharacter ); |
25 | 52 |
AknTextUtils::StripCharacters( fPtr, KAknStripListControlChars ); |
53 |
||
54 |
HBufC* lastName = aLastName.AllocLC(); |
|
55 |
TPtr lPtr = lastName->Des(); |
|
26
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
56 |
ReplaceNonGraphicCharacters( lPtr, KGraphicReplaceCharacter ); |
25 | 57 |
AknTextUtils::StripCharacters( lPtr, KAknStripListControlChars ); |
58 |
||
59 |
HBufC* companyName = aCompanyName.AllocLC(); |
|
60 |
TPtr cPtr = companyName->Des(); |
|
26
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
61 |
ReplaceNonGraphicCharacters( cPtr, KGraphicReplaceCharacter ); |
25 | 62 |
AknTextUtils::StripCharacters( cPtr, KAknStripListControlChars ); |
63 |
||
64 |
// 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. |
|
66 |
TInt stringLength = firstName->Length() + lastName->Length() + 2 * companyName->Length() + 2; |
|
67 |
HBufC* string = HBufC::NewLC( stringLength ); |
|
68 |
TPtr ptr = string->Des(); |
|
69 |
||
70 |
// If there is no first name, the last name will be used. |
|
71 |
if ( firstName->Length() == 0 ) |
|
72 |
{ |
|
73 |
ptr.Copy( *lastName ); |
|
74 |
} |
|
75 |
||
76 |
// If there is no last name, the first name will be used. |
|
77 |
else if ( lastName->Length() == 0 ) |
|
78 |
{ |
|
79 |
ptr.Copy( *firstName ); |
|
80 |
} |
|
81 |
||
82 |
// If there are both first and last name, the name string is composed of them both. |
|
83 |
else |
|
84 |
{ |
|
85 |
if( aNameOrder == CEasyDialingContactDataManager::EFirstnameLastname ) |
|
86 |
{ |
|
87 |
ptr.Copy( *firstName ); |
|
88 |
ptr.Append( KNameSeparatorChar ); |
|
89 |
ptr.Append( *lastName ); |
|
90 |
} |
|
91 |
else |
|
92 |
{ |
|
93 |
ptr.Copy( *lastName ); |
|
94 |
ptr.Append( KNameSeparatorChar ); |
|
95 |
ptr.Append( *firstName ); |
|
96 |
} |
|
97 |
} |
|
98 |
||
99 |
// If firstname and last name are missing, put company name into the first field. |
|
100 |
if ( ptr.Length() == 0 ) |
|
101 |
{ |
|
102 |
ptr.Append( *companyName ); |
|
103 |
} |
|
104 |
else |
|
105 |
{ |
|
106 |
// Otherwise add company name into the second field using tab as a separator. |
|
107 |
ptr.Append( KListFieldSeparatorChar ); |
|
108 |
ptr.Append( *companyName ); |
|
109 |
} |
|
110 |
||
111 |
CleanupStack::Pop( string ); |
|
112 |
CleanupStack::PopAndDestroy( 3, firstName ); |
|
113 |
CleanupStack::PushL( string ); |
|
114 |
return string; |
|
115 |
} |
|
26
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
116 |
|
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
117 |
/* |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
118 |
* ============================================================================== |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
119 |
* |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
120 |
* Local functions |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
121 |
* |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
122 |
* ============================================================================== |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
123 |
*/ |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
124 |
|
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
125 |
/** |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
126 |
* Checkif the given char is a zero width character: |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
127 |
* ZeroWidth Space, Zero Width Non-Joiner |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
128 |
* orZero Width Joiner character |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
129 |
* @paramaChar Given character |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
130 |
*@return ETrue if aChar is zero width character. |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
131 |
* EFalse if aChar is not specified zero width character. |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
132 |
*/ |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
133 |
|
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
134 |
inline TBool ZWSCharacter( const TChar aChar ) |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
135 |
{ |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
136 |
const TChar zwsChar( KZWSCharacter ); |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
137 |
const TChar zwnjChar( KZWNJCharacter ); |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
138 |
const TChar zwjChar( KZWJCharacter ); |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
139 |
return ( aChar == zwsChar ) || ( aChar == zwnjChar ) || |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
140 |
( aChar == zwjChar ); |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
141 |
} |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
142 |
|
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
143 |
/** |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
144 |
* Replaces all non-graphic characters (!TChar::IsGraph()) in |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
145 |
* a string with the specified character. |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
146 |
**/ |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
147 |
|
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
148 |
void ReplaceNonGraphicCharacters( TDes& aText, TText aChar ) |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
149 |
{ |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
150 |
const TInt len = aText.Length(); |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
151 |
for ( TInt i = 0; i <len; ++i ) |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
152 |
{ |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
153 |
if ( !TChar( aText[i] ).IsGraph() && !ZWSCharacter( aText[i] ) ) |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
154 |
{ |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
155 |
//If non-graphic char is specified in ZWSCharacter, |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
156 |
//it will not be replaced. Otherwise replace non-graphic |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
157 |
//character with aChar. |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
158 |
aText[i] = aChar; |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
159 |
} |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
160 |
} |
8baf28733c3d
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
161 |
} |