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