|
1 // Copyright (c) 2009 - 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 // |
|
16 // |
|
17 /** |
|
18 * @file parse.cpp |
|
19 * |
|
20 * @internalComponent |
|
21 * @released |
|
22 */ |
|
23 #include "parse.h" |
|
24 #include "barsc2.h" |
|
25 |
|
26 std::string FullNameWithoutDrive(std::string& Buf ) |
|
27 { |
|
28 std::string iName; |
|
29 std::string::size_type index = Buf.find( ':' ); |
|
30 if( index != std::string::npos ) |
|
31 iName.assign(Buf, index+1, Buf.size()); |
|
32 |
|
33 return iName; |
|
34 } |
|
35 |
|
36 /** |
|
37 * Converts from Ptr8* datatype to wstring |
|
38 */ |
|
39 std::wstring Ptr8ToWstring(const Ptr8* aBuf) |
|
40 { |
|
41 std::wstring str2(aBuf->GetLength(), L'\0'); // Make room for characters |
|
42 |
|
43 TUint8* temp = aBuf->GetPtr(); |
|
44 memcpy(str2.begin(),temp,aBuf->GetLength()); |
|
45 |
|
46 return str2; |
|
47 } |
|
48 |
|
49 /** |
|
50 * Converts from Ptr16* datatype to wstring |
|
51 */ |
|
52 std::wstring Ptr16ToWstring(const Ptr16* aBuf) |
|
53 { |
|
54 std::wstring str2(aBuf->GetLength(), L'\0'); // Make room for characters |
|
55 |
|
56 TUint16* temp = aBuf->GetPtr(); |
|
57 std::copy(temp,temp+aBuf->GetLength(),str2.begin()); |
|
58 |
|
59 return str2; |
|
60 } |
|
61 |
|
62 /** |
|
63 * Converts from Ptr16* datatype to string |
|
64 */ |
|
65 std::string Ptr16ToString(Ptr16* aBuf) |
|
66 { |
|
67 std::string str2(aBuf->GetLength(), '\0'); // Make room for characters |
|
68 |
|
69 TUint16* temp = aBuf->GetPtr(); |
|
70 for(int i =0; i<aBuf->GetLength(); i++) |
|
71 { |
|
72 str2[i] = *temp++; |
|
73 } |
|
74 str2[aBuf->GetLength()] = '\0'; |
|
75 return str2; |
|
76 } |
|
77 |
|
78 //Local function to Copy TUint16 |
|
79 void BufCpy(TUint16* aTemp1,TUint16* aTemp2, TInt aLength) |
|
80 { |
|
81 for(TInt i =0 ; i< aLength; i++) |
|
82 { |
|
83 *aTemp1++ = *aTemp2++; |
|
84 } |
|
85 } |
|
86 |
|
87 //Local function to Copy TUint8 |
|
88 void BufCpy8(TUint8* aTemp1, const TUint8* aTemp2, TInt aLength) |
|
89 { |
|
90 for(TInt i =0 ; i< aLength; i++) |
|
91 { |
|
92 *aTemp1++ = *aTemp2++; |
|
93 } |
|
94 } |
|
95 |
|
96 //Search for either wild character in the input string. |
|
97 //return 1 if found else return 0 |
|
98 TInt FindWild(PtrC16 *aPtr) |
|
99 { |
|
100 TUint32 i = 0; |
|
101 const TUint16* Pt = aPtr->iPtr; |
|
102 for( i=0; i < aPtr->iMaxLength; i++) |
|
103 { |
|
104 if((*Pt=='*') || (*Pt=='?')) |
|
105 return 1; |
|
106 else |
|
107 Pt++; |
|
108 } |
|
109 return 0; |
|
110 } |
|
111 |
|
112 //Find if wild character present in the input string |
|
113 //return 1 if found else return 0 |
|
114 TInt FindWild(std::string& aRegistrationFileDrive, std::string& aAppFilePath, std::string& aAppFileNameAndExt) |
|
115 { |
|
116 |
|
117 string::size_type index1 = aRegistrationFileDrive.find_last_of("*?"); |
|
118 if( index1 != string::npos ) |
|
119 return 1; |
|
120 |
|
121 string::size_type index2 = aAppFilePath.find_last_of("*?"); |
|
122 if( index2 != string::npos ) |
|
123 return 1; |
|
124 |
|
125 string::size_type index3 = aAppFileNameAndExt.find_last_of("*?"); |
|
126 if( index3 != string::npos ) |
|
127 return 1; |
|
128 return 0; |
|
129 } |
|
130 |
|
131 //Default Constructor for class ParsePtrC |
|
132 ParsePtrC::ParsePtrC() |
|
133 : iNamePresent(0),iPathPresent(0),iExtPresent(0),iDrivePresent(0) |
|
134 { |
|
135 } |
|
136 |
|
137 //Destructor for class ParsePtrC |
|
138 ParsePtrC::~ParsePtrC() |
|
139 { |
|
140 delete iNameBuf; |
|
141 delete Buf; |
|
142 iNameBuf = NULL; |
|
143 Buf = NULL; |
|
144 } |
|
145 |
|
146 //To Avoid double Delete in destructor. |
|
147 void ParsePtrC::SetToNull() |
|
148 { |
|
149 iNameBuf = NULL; |
|
150 } |
|
151 |
|
152 //Constructor for class ParsePtrC |
|
153 ParsePtrC::ParsePtrC(const PtrC16* aName) |
|
154 : iNamePresent(0),iPathPresent(0),iExtPresent(0),iDrivePresent(0) |
|
155 { |
|
156 iNameBuf = new PtrC16; |
|
157 TUint16* temp = (TUint16*)aName->iPtr; |
|
158 if(NULL==iNameBuf) |
|
159 { |
|
160 std::string errMsg= "Error in Reading File. Memory Allocation Failed"; |
|
161 throw CResourceFileException(errMsg); |
|
162 } |
|
163 iNameBuf->iPtr = aName->iPtr; |
|
164 iNameBuf->iMaxLength = aName->iMaxLength; |
|
165 |
|
166 Buf = new string(aName->iMaxLength,'\0'); |
|
167 |
|
168 if(NULL==Buf) |
|
169 { |
|
170 std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed"; |
|
171 throw CResourceFileException(errMsg); |
|
172 } |
|
173 |
|
174 for(TInt i = 0; i<aName->iMaxLength; i++ ) |
|
175 { |
|
176 (*Buf)[i] = *temp; |
|
177 temp++; |
|
178 } |
|
179 } |
|
180 |
|
181 PtrC16* ParsePtrC::FullName() |
|
182 { |
|
183 return iNameBuf; |
|
184 } |
|
185 |
|
186 std::string ParsePtrC::StrName() |
|
187 { |
|
188 return *Buf; |
|
189 } |
|
190 |
|
191 //Constructor for class ParsePtrC |
|
192 ParsePtrC::ParsePtrC(std::string aStr) |
|
193 : iNamePresent(0),iPathPresent(0),iExtPresent(0),iDrivePresent(0) |
|
194 { |
|
195 Buf = new string; |
|
196 if(NULL==Buf) |
|
197 { |
|
198 std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed"; |
|
199 throw CResourceFileException(errMsg); |
|
200 } |
|
201 *Buf = aStr; |
|
202 } |
|
203 |
|
204 std::string ParsePtrC::Name() |
|
205 { |
|
206 string iName; |
|
207 |
|
208 #ifdef __LINUX__ |
|
209 TInt i = Buf->rfind("/"); |
|
210 #else |
|
211 TInt i = Buf->rfind("\\"); |
|
212 #endif |
|
213 |
|
214 if(i!=string::npos) |
|
215 iName.assign(*Buf, i, Buf->size()-4); |
|
216 else |
|
217 { |
|
218 if(ExtPresent()) |
|
219 iName.assign(*Buf, i, Buf->size()-4); |
|
220 else |
|
221 iName.assign(*Buf, 0, Buf->size()); |
|
222 } |
|
223 |
|
224 return iName; |
|
225 } |
|
226 |
|
227 std::string ParsePtrC::NameAndExt() |
|
228 { |
|
229 string iName; |
|
230 |
|
231 #ifdef __LINUX__ |
|
232 TInt i = Buf->rfind("/"); |
|
233 #else |
|
234 TInt i = Buf->rfind("\\"); |
|
235 #endif |
|
236 |
|
237 if(i!=string::npos) |
|
238 iName.assign(*Buf, i, Buf->size()); |
|
239 |
|
240 return iName; |
|
241 } |
|
242 |
|
243 std::string ParsePtrC::FullPath() |
|
244 { |
|
245 string iName; |
|
246 |
|
247 #ifdef __LINUX__ |
|
248 TInt i = Buf->rfind("/"); |
|
249 #else |
|
250 TInt i = Buf->rfind("\\"); |
|
251 #endif |
|
252 |
|
253 if(i!=string::npos) |
|
254 iName.assign(*Buf, 0, i); |
|
255 |
|
256 return iName; |
|
257 } |
|
258 |
|
259 std::string ParsePtrC::Path() |
|
260 { |
|
261 string iName; |
|
262 |
|
263 #ifdef __LINUX__ |
|
264 TInt j = Buf->rfind("/"); |
|
265 TInt i = Buf->find("/"); |
|
266 #else |
|
267 TInt j = Buf->rfind("\\"); |
|
268 TInt i = Buf->find("\\"); |
|
269 #endif |
|
270 |
|
271 if(i!=string::npos) |
|
272 iName.assign(*Buf, i, Buf->size()-j); |
|
273 |
|
274 return iName; |
|
275 } |
|
276 |
|
277 std::string ParsePtrC::Drive() |
|
278 { |
|
279 string iName; |
|
280 |
|
281 string::size_type index = Buf->find( ':' ); |
|
282 if( index != string::npos ) |
|
283 iName.assign(*Buf, index-1, 2); |
|
284 |
|
285 return iName; |
|
286 } |
|
287 |
|
288 std::string ParsePtrC::FullNameWithoutDrive() |
|
289 { |
|
290 string iName; |
|
291 |
|
292 string::size_type index = Buf->find( ':' ); |
|
293 if( index != string::npos ) |
|
294 iName.assign(*Buf, index+1, Buf->size()); |
|
295 |
|
296 return iName; |
|
297 } |
|
298 |
|
299 TInt ParsePtrC::NamePresent() |
|
300 { |
|
301 #ifdef __LINUX__ |
|
302 TInt i = Buf->rfind("/"); |
|
303 #else |
|
304 TInt i = Buf->rfind("\\"); |
|
305 #endif |
|
306 |
|
307 if(i!=string::npos) |
|
308 iNamePresent = 1; |
|
309 else |
|
310 { |
|
311 if(Buf!= NULL) |
|
312 iNamePresent = 1; |
|
313 else |
|
314 iNamePresent = 0; |
|
315 } |
|
316 return iNamePresent; |
|
317 } |
|
318 |
|
319 TInt ParsePtrC::PathPresent() |
|
320 { |
|
321 #ifdef __LINUX__ |
|
322 TInt i = Buf->find("/"); |
|
323 #else |
|
324 TInt i = Buf->find("\\"); |
|
325 #endif |
|
326 |
|
327 if(i!=string::npos) |
|
328 iPathPresent = 1; |
|
329 else |
|
330 iPathPresent = 0; |
|
331 return iPathPresent; |
|
332 } |
|
333 |
|
334 TInt ParsePtrC::ExtPresent() |
|
335 { |
|
336 TInt i = Buf->find("."); |
|
337 if(i!=string::npos) |
|
338 iExtPresent = 1; |
|
339 else |
|
340 iExtPresent = 0; |
|
341 return iExtPresent; |
|
342 } |
|
343 |
|
344 TInt ParsePtrC::DrivePresent() |
|
345 { |
|
346 TInt i = Buf->find(":"); |
|
347 if(i!=string::npos) |
|
348 iDrivePresent = 1; |
|
349 else |
|
350 iDrivePresent = 0; |
|
351 return iDrivePresent; |
|
352 } |
|
353 |
|
354 TInt ParsePtrC::IsWild() |
|
355 { |
|
356 string::size_type index = Buf->find_last_of("*?"); |
|
357 if( index != string::npos ) |
|
358 return 1; |
|
359 return 0; |
|
360 } |
|
361 |
|
362 TInt ParsePtrC::IsValidName() |
|
363 { |
|
364 #ifdef __LINUX__ |
|
365 string::size_type index = Buf->find_last_of("*?< > : \" \\ |"); |
|
366 #else |
|
367 string::size_type index = Buf->find_last_of("*?< > : \" |"); |
|
368 #endif |
|
369 |
|
370 if( index != string::npos ) |
|
371 return 1; |
|
372 return 0; |
|
373 } |