|
1 /* |
|
2 * Copyright (c) 2005 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: DM Utilities |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "nsmldmuri.h" |
|
20 |
|
21 // =========================================================================== |
|
22 // NSmlDmURI |
|
23 // =========================================================================== |
|
24 |
|
25 // ------------------------------------------------------------------------------------------------ |
|
26 // TPtrC8 NSmlDmURI::ParentURI(const TDesC8& aURI) |
|
27 // returns parent uri, i.e. removes last uri segment |
|
28 // ------------------------------------------------------------------------------------------------ |
|
29 EXPORT_C TPtrC8 NSmlDmURI::ParentURI(const TDesC8& aURI) |
|
30 { |
|
31 TBool onlyOneSeg = ETrue; |
|
32 TInt i; |
|
33 for(i=aURI.Length()-1;i>=0;i--) |
|
34 { |
|
35 if(aURI[i]==KNSmlDMUriSeparator) |
|
36 { |
|
37 onlyOneSeg = EFalse; |
|
38 break; |
|
39 } |
|
40 } |
|
41 if(onlyOneSeg) |
|
42 { |
|
43 return KNSmlDmRootUri(); |
|
44 } |
|
45 else |
|
46 { |
|
47 return aURI.Left(i); |
|
48 } |
|
49 } |
|
50 |
|
51 // ------------------------------------------------------------------------------------------------ |
|
52 // TPtrC8 NSmlDmURI::LastURISeg(const TDesC8& aURI) |
|
53 // Returns only the last uri segemnt |
|
54 // ------------------------------------------------------------------------------------------------ |
|
55 EXPORT_C TPtrC8 NSmlDmURI::LastURISeg(const TDesC8& aURI) |
|
56 { |
|
57 TInt i; |
|
58 for(i=aURI.Length()-1;i>=0;i--) |
|
59 { |
|
60 if(aURI[i]==KNSmlDMUriSeparator) |
|
61 { |
|
62 break; |
|
63 } |
|
64 } |
|
65 if(i==0) |
|
66 { |
|
67 return aURI; |
|
68 } |
|
69 else |
|
70 { |
|
71 return aURI.Mid(i+1); |
|
72 } |
|
73 } |
|
74 |
|
75 // ------------------------------------------------------------------------------------------------ |
|
76 // TPtrC8 NSmlDmURI::RemoveDotSlash(const TDesC8& aURI) |
|
77 // return uri without dot and slash in start |
|
78 // ------------------------------------------------------------------------------------------------ |
|
79 EXPORT_C TPtrC8 NSmlDmURI::RemoveDotSlash(const TDesC8& aURI) |
|
80 { |
|
81 |
|
82 TInt offset = 0; |
|
83 TInt endSlash = 0; |
|
84 |
|
85 if(aURI.Find(KNSmlDmUriDotSlash)==0) |
|
86 { |
|
87 offset = 2; |
|
88 } |
|
89 else |
|
90 { |
|
91 return aURI; |
|
92 } |
|
93 |
|
94 if(aURI.Length()>2&&aURI[aURI.Length()-1]==KNSmlDMUriSeparator) |
|
95 { |
|
96 endSlash = 1; |
|
97 } |
|
98 |
|
99 return aURI.Mid(offset,aURI.Length()-endSlash-offset); |
|
100 } |
|
101 |
|
102 // ------------------------------------------------------------------------------------------------ |
|
103 // TPtrC8 NSmlDmURI::RemoveProp(const TDesC8& aURI) |
|
104 // removes property from the uri |
|
105 // ------------------------------------------------------------------------------------------------ |
|
106 EXPORT_C TPtrC8 NSmlDmURI::RemoveProp(const TDesC8& aURI) |
|
107 { |
|
108 TInt offset = aURI.Find(KNSmlDmQuestionMark); |
|
109 if(offset!=KErrNotFound) |
|
110 { |
|
111 return aURI.Left(offset); |
|
112 } |
|
113 return aURI; |
|
114 } |
|
115 |
|
116 // ------------------------------------------------------------------------------------------------ |
|
117 // TPtrC8 NSmlDmURI::RemoveLastSeg(const TDesC8& aURI) |
|
118 // Removes last uri segment |
|
119 // ------------------------------------------------------------------------------------------------ |
|
120 EXPORT_C TPtrC8 NSmlDmURI::RemoveLastSeg(const TDesC8& aURI) |
|
121 { |
|
122 TInt i; |
|
123 for(i=aURI.Length()-1;i>=0;i--) |
|
124 { |
|
125 if(aURI[i]==KNSmlDMUriSeparator) |
|
126 { |
|
127 break; |
|
128 } |
|
129 } |
|
130 |
|
131 if(i>0) |
|
132 { |
|
133 return aURI.Left(i); |
|
134 } |
|
135 else |
|
136 { |
|
137 return KNullDesC8(); |
|
138 } |
|
139 } |
|
140 |
|
141 |
|
142 // ------------------------------------------------------------------------------------------------ |
|
143 // TPtrC8 NSmlDmURI::URISeg(const TDesC8& aURI,TInt aLocation) |
|
144 // Returns the aLocation:th URI segment |
|
145 // ------------------------------------------------------------------------------------------------ |
|
146 EXPORT_C TPtrC8 NSmlDmURI::URISeg(const TDesC8& aURI,TInt aLocation) |
|
147 { |
|
148 TInt begin=0; |
|
149 TInt end; |
|
150 TInt num=0; |
|
151 |
|
152 for(end=0;end<aURI.Length();end++) |
|
153 { |
|
154 if(aURI[end]==KNSmlDMUriSeparator||end==aURI.Length()-1) |
|
155 { |
|
156 num++; |
|
157 if(num==aLocation) |
|
158 { |
|
159 break; |
|
160 } |
|
161 else |
|
162 { |
|
163 begin = end; |
|
164 } |
|
165 } |
|
166 } |
|
167 if(begin==0) |
|
168 { |
|
169 if(end==aURI.Length()-1) |
|
170 { |
|
171 return aURI; |
|
172 } |
|
173 else |
|
174 { |
|
175 return aURI.Left(end); |
|
176 } |
|
177 } |
|
178 else |
|
179 { |
|
180 if(end==aURI.Length()-1) |
|
181 { |
|
182 return aURI.Mid(begin+1,end-begin); |
|
183 } |
|
184 else |
|
185 { |
|
186 return aURI.Mid(begin+1,end-begin-1); |
|
187 } |
|
188 } |
|
189 } |
|
190 |
|
191 |
|
192 // ------------------------------------------------------------------------------------------------ |
|
193 // TInt NSmlDmURI::NumOfURISegs(const TDesC8& aURI) |
|
194 // Returns the num of uri segs |
|
195 // ------------------------------------------------------------------------------------------------ |
|
196 EXPORT_C TInt NSmlDmURI::NumOfURISegs(const TDesC8& aURI) |
|
197 { |
|
198 TInt numOfURISegs = 1; |
|
199 for(TInt i=0;i<aURI.Length();i++) |
|
200 { |
|
201 if(aURI[i]==KNSmlDMUriSeparator) |
|
202 { |
|
203 numOfURISegs++; |
|
204 } |
|
205 } |
|
206 return numOfURISegs; |
|
207 } |
|
208 |