|
1 /* |
|
2 * Copyright (c) 2002 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 tree etc. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "nsmldmuri.h" |
|
19 |
|
20 // ------------------------------------------------------------------------------------------------ |
|
21 // NSmlDmURI |
|
22 // ------------------------------------------------------------------------------------------------ |
|
23 |
|
24 |
|
25 // ------------------------------------------------------------------------------------------------ |
|
26 // TPtrC8 NSmlDmURI::ParentURI(const TDesC8& aURI) |
|
27 // returns parent uri, i.e. removes last uri segment |
|
28 // ------------------------------------------------------------------------------------------------ |
|
29 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 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 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 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 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 // TPtrC8 NSmlDmURI::URISeg(const TDesC8& aURI,TInt aLocation,TInt aSegCount=1) |
|
143 // Returns the aLocation:th URI segment |
|
144 // ------------------------------------------------------------------------------------------------ |
|
145 TPtrC8 NSmlDmURI::URISeg(const TDesC8& aURI, TInt aLocation, TInt aSegCount/*=1*/) |
|
146 { |
|
147 TInt i, start; |
|
148 if (aLocation < 0) |
|
149 { |
|
150 return aURI.Mid(0, 0); |
|
151 } |
|
152 if (aLocation > 0) |
|
153 { |
|
154 for (start=0, i=0; (start<aURI.Length()) && (i<aLocation); start++) |
|
155 { |
|
156 if (aURI[start]=='/') |
|
157 { |
|
158 i++; |
|
159 } |
|
160 if (i==aLocation) |
|
161 { |
|
162 break; |
|
163 } |
|
164 } |
|
165 } |
|
166 else |
|
167 { |
|
168 start=-1; |
|
169 } |
|
170 // empty segment |
|
171 if (start+1 >= aURI.Length()) |
|
172 { |
|
173 return aURI.Mid(0, 0); |
|
174 } |
|
175 // start points to beginning of segment |
|
176 for (i=start+1; i<aURI.Length(); i++) |
|
177 { |
|
178 if (aURI[i]=='/') |
|
179 { |
|
180 aSegCount--; |
|
181 if (aSegCount == 0) |
|
182 { |
|
183 break; |
|
184 } |
|
185 } |
|
186 } |
|
187 // i points to end of segment |
|
188 return aURI.Mid(start+1, i-start-1); |
|
189 } |
|
190 |
|
191 // ------------------------------------------------------------------------------------------------ |
|
192 // TInt NSmlDmURI::NumOfURISegs(const TDesC8& aURI) |
|
193 // Returns the num of uri segs |
|
194 // ------------------------------------------------------------------------------------------------ |
|
195 TInt NSmlDmURI::NumOfURISegs(const TDesC8& aURI) |
|
196 { |
|
197 TInt numOfURISegs = 1; |
|
198 for (TInt i=0; i<aURI.Length(); i++) |
|
199 { |
|
200 if (aURI[i]==KNSmlDMUriSeparator) |
|
201 { |
|
202 numOfURISegs++; |
|
203 } |
|
204 } |
|
205 return numOfURISegs; |
|
206 } |
|
207 |