|
1 /* |
|
2 * Copyright (c) 2008 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: Utils for storage modules. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "vimpststorageutils.h" |
|
20 #include "cvimpststoragemanagerfactory.h" |
|
21 #include "mvimpststorageserviceview.h" |
|
22 |
|
23 #include "uiservicetabtracer.h" |
|
24 #include "vimpstbuilddefinitions.h" |
|
25 |
|
26 #include <escapeutils.h> |
|
27 #include <collate.h> |
|
28 |
|
29 // needed to skip prefixes in domain-neutral comparison (TUint version) |
|
30 const TUint KColonUInt( ':' ); |
|
31 |
|
32 // needed to skip domains in domain-neutral comparison (TUint version) |
|
33 const TUint KAtUInt( '@' ); |
|
34 |
|
35 // "test character identity and accents, ignore case" |
|
36 const TInt KCollationLevel = 1; |
|
37 |
|
38 |
|
39 |
|
40 // defines how far we are going to search for the protocol part in user id |
|
41 const TInt KMaxLengthSearchProtPart = 4; |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // VIMPSTStorageUtils::NeutralCompare |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 TInt VIMPSTStorageUtils::NeutralCompare( const TDesC& aId1, |
|
48 const TDesC& aId2, TBool aDomainNeutral ) |
|
49 { |
|
50 TRACER_AUTO; |
|
51 // points to user part of id |
|
52 TPtrC ptrId1( aId1 ); |
|
53 TPtrC ptrId2( aId2 ); |
|
54 |
|
55 // Reduce looking for protocol part only to beginning of the WVID and |
|
56 // skip protocol part ("anything:") in the beginning of the WVID |
|
57 TInt colonPos1 = aId1.Left( KMaxLengthSearchProtPart ).Locate( KColonUInt ); |
|
58 |
|
59 // first id |
|
60 if ( ( KErrNotFound != colonPos1 ) && ( aId1.Length() -1 != colonPos1 ) ) |
|
61 { |
|
62 // contains ":", and it is not the last char |
|
63 ptrId1.Set( aId1.Mid( colonPos1 + 1 ) ); |
|
64 } |
|
65 |
|
66 TInt colonPos2 = aId2.Left( KMaxLengthSearchProtPart ).Locate( KColonUInt ); |
|
67 |
|
68 // second id |
|
69 if ( ( KErrNotFound != colonPos2 ) && ( aId2.Length() -1 != colonPos2 ) ) |
|
70 { |
|
71 // contains ":", and it is not the last char |
|
72 ptrId2.Set( aId2.Mid( colonPos2 + 1 ) ); |
|
73 } |
|
74 |
|
75 // find out if we have domains in the ids |
|
76 TInt domainPos1( ptrId1.Locate( KAtUInt ) ); |
|
77 TInt domainPos2( ptrId2.Locate( KAtUInt ) ); |
|
78 |
|
79 TBool domainIn1( KErrNotFound != domainPos1 ); |
|
80 TBool domainIn2( KErrNotFound != domainPos2 ); |
|
81 |
|
82 // points to domains in the neutral id |
|
83 TPtrC ptrDom1( KNullDesC ); |
|
84 TPtrC ptrDom2( KNullDesC ); |
|
85 |
|
86 // points to user parts in the neutral id |
|
87 TPtrC ptrUid1( ptrId1 ); |
|
88 TPtrC ptrUid2( ptrId2 ); |
|
89 |
|
90 // separate user id parts and domain parts |
|
91 if ( domainIn1 ) |
|
92 { |
|
93 ptrDom1.Set( ptrId1.Mid( domainPos1 + 1) ); |
|
94 ptrUid1.Set( ptrId1.Mid( 0, domainPos1 ) ); |
|
95 } |
|
96 |
|
97 if ( domainIn2 ) |
|
98 { |
|
99 ptrDom2.Set( ptrId2.Mid( domainPos2 + 1) ); |
|
100 ptrUid2.Set( ptrId2.Mid( 0, domainPos2 ) ); |
|
101 } |
|
102 |
|
103 // Create custom collation method to ignore punctuations |
|
104 // index 0 gets the default method |
|
105 TCollationMethod collation = |
|
106 *Mem::CollationMethodByIndex( 0 ); |
|
107 collation.iFlags |= TCollationMethod::EIgnoreNone; |
|
108 |
|
109 // domains are compared only when it is really needed |
|
110 // check if userid part is the same in both ids |
|
111 |
|
112 TInt idResult = ptrUid1.Compare( ptrUid2); |
|
113 |
|
114 if( idResult != 0 ) |
|
115 { |
|
116 return idResult; |
|
117 } |
|
118 |
|
119 // id part is same, we have to compare domain |
|
120 |
|
121 // If domain comparison is neutral and one id is without domain |
|
122 // -> Domains are same. Other situation domainResult stays valid. |
|
123 if( aDomainNeutral && ( domainIn1 ^ domainIn2 ) ) |
|
124 { |
|
125 return 0; |
|
126 } |
|
127 else |
|
128 { |
|
129 return ptrDom1.CompareC( ptrDom2, KCollationLevel, &collation ); |
|
130 } |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // VIMPSTStorageUtils::DisplayId |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 TPtrC VIMPSTStorageUtils::DisplayId( const TDesC& aId, TBool /*aListHiding*/ ) |
|
138 { |
|
139 TRACER_AUTO; |
|
140 TPtrC ret( aId ); |
|
141 |
|
142 return ret; |
|
143 } |
|
144 |
|
145 |
|
146 // End of file |