|
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 "vimpstdebugtrace.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 // points to user part of id |
|
51 TPtrC ptrId1( aId1 ); |
|
52 TPtrC ptrId2( aId2 ); |
|
53 |
|
54 // Reduce looking for protocol part only to beginning of the WVID and |
|
55 // skip protocol part ("anything:") in the beginning of the WVID |
|
56 TInt colonPos1 = aId1.Left( KMaxLengthSearchProtPart ).Locate( KColonUInt ); |
|
57 |
|
58 // first id |
|
59 if ( ( KErrNotFound != colonPos1 ) && ( aId1.Length() -1 != colonPos1 ) ) |
|
60 { |
|
61 // contains ":", and it is not the last char |
|
62 ptrId1.Set( aId1.Mid( colonPos1 + 1 ) ); |
|
63 } |
|
64 |
|
65 TInt colonPos2 = aId2.Left( KMaxLengthSearchProtPart ).Locate( KColonUInt ); |
|
66 |
|
67 // second id |
|
68 if ( ( KErrNotFound != colonPos2 ) && ( aId2.Length() -1 != colonPos2 ) ) |
|
69 { |
|
70 // contains ":", and it is not the last char |
|
71 ptrId2.Set( aId2.Mid( colonPos2 + 1 ) ); |
|
72 } |
|
73 |
|
74 // find out if we have domains in the ids |
|
75 TInt domainPos1( ptrId1.Locate( KAtUInt ) ); |
|
76 TInt domainPos2( ptrId2.Locate( KAtUInt ) ); |
|
77 |
|
78 TBool domainIn1( KErrNotFound != domainPos1 ); |
|
79 TBool domainIn2( KErrNotFound != domainPos2 ); |
|
80 |
|
81 // points to domains in the neutral id |
|
82 TPtrC ptrDom1( KNullDesC ); |
|
83 TPtrC ptrDom2( KNullDesC ); |
|
84 |
|
85 // points to user parts in the neutral id |
|
86 TPtrC ptrUid1( ptrId1 ); |
|
87 TPtrC ptrUid2( ptrId2 ); |
|
88 |
|
89 // separate user id parts and domain parts |
|
90 if ( domainIn1 ) |
|
91 { |
|
92 ptrDom1.Set( ptrId1.Mid( domainPos1 + 1) ); |
|
93 ptrUid1.Set( ptrId1.Mid( 0, domainPos1 ) ); |
|
94 } |
|
95 |
|
96 if ( domainIn2 ) |
|
97 { |
|
98 ptrDom2.Set( ptrId2.Mid( domainPos2 + 1) ); |
|
99 ptrUid2.Set( ptrId2.Mid( 0, domainPos2 ) ); |
|
100 } |
|
101 |
|
102 // Create custom collation method to ignore punctuations |
|
103 // index 0 gets the default method |
|
104 TCollationMethod collation = |
|
105 *Mem::CollationMethodByIndex( 0 ); |
|
106 collation.iFlags |= TCollationMethod::EIgnoreNone; |
|
107 |
|
108 // domains are compared only when it is really needed |
|
109 // check if userid part is the same in both ids |
|
110 |
|
111 TInt idResult = ptrUid1.Compare( ptrUid2); |
|
112 |
|
113 if( idResult != 0 ) |
|
114 { |
|
115 return idResult; |
|
116 } |
|
117 |
|
118 // id part is same, we have to compare domain |
|
119 |
|
120 // If domain comparison is neutral and one id is without domain |
|
121 // -> Domains are same. Other situation domainResult stays valid. |
|
122 if( aDomainNeutral && ( domainIn1 ^ domainIn2 ) ) |
|
123 { |
|
124 return 0; |
|
125 } |
|
126 else |
|
127 { |
|
128 return ptrDom1.CompareC( ptrDom2, KCollationLevel, &collation ); |
|
129 } |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // VIMPSTStorageUtils::DisplayId |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 TPtrC VIMPSTStorageUtils::DisplayId( const TDesC& aId, TBool /*aListHiding*/ ) |
|
137 { |
|
138 TPtrC ret( aId ); |
|
139 |
|
140 return ret; |
|
141 } |
|
142 |
|
143 |
|
144 // End of file |