|
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 the License "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: Config descriptor parser for ROP specific settings.* |
|
15 */ |
|
16 |
|
17 |
|
18 // Version : %version: 4 % |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 // INCLUDE FILES |
|
24 #include <utf.h> |
|
25 #include "MPSettingsRopConfigParser.h" |
|
26 #include "mpxlog.h" |
|
27 |
|
28 // CONSTANTS |
|
29 const TInt KMPRopEntryArrayGranularity = 16; |
|
30 |
|
31 _LIT8(KMPRopTypeInteger, "Integer"); |
|
32 _LIT8(KMPRopTypeString, "String"); |
|
33 _LIT8(KMPRopEntrySeparator, ";"); |
|
34 _LIT8(KMPRopKeySeparator, ":"); |
|
35 _LIT8(KMPRopValueSeparator, "="); |
|
36 _LIT8(KMPRopStringConstrainer, "\""); |
|
37 _LIT8(KMPRopArrayOpeningMarker, "{"); |
|
38 _LIT8(KMPRopArrayClosingMarker, "}"); |
|
39 _LIT8(KMPRopArraySeparator, ","); |
|
40 _LIT8(KMPRopIntegerEntryPrototype, "%S:Integer = %d;"); |
|
41 _LIT8(KMPRopStringEntryPrototype, "%S:String = \"%S\";"); |
|
42 |
|
43 const TInt KMPRopIntegerEntryPrototypeStaticLength = 23; // static length + 11 chars for the (32bit) TInt |
|
44 const TInt KMPRopStringEntryPrototypeStaticLength = 13; |
|
45 |
|
46 |
|
47 // ============================ MEMBER FUNCTIONS =============================== |
|
48 |
|
49 // ******************************* |
|
50 // *** class CMPRopSettingItem *** |
|
51 // ******************************* |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CMPRopSettingItem::CMPRopSettingItem |
|
55 // C++ default constructor can NOT contain any code, that |
|
56 // might leave. |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 CMPRopSettingItem::CMPRopSettingItem(TInt aId) : iId(aId), |
|
60 iValueChanged(EFalse) |
|
61 { |
|
62 MPX_DEBUG1(_L("#MS# CMPRopSettingItem::CMPRopSettingItem()")); |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CMPRopSettingItem::ConstructL |
|
67 // Symbian 2nd phase constructor can leave. |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 void CMPRopSettingItem::ConstructL(const TDesC& aKey) |
|
71 { |
|
72 MPX_DEBUG2(_L("#MS# CMPRopSettingItem::ConstructL(%S)"),&aKey); |
|
73 iKey = HBufC8::NewL(aKey.Length()); |
|
74 TPtr8 ptr = iKey->Des(); |
|
75 CnvUtfConverter::ConvertFromUnicodeToUtf8(ptr, aKey); |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CMPRopSettingItem::NewLC |
|
80 // Two-phased constructor. |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 CMPRopSettingItem* CMPRopSettingItem::NewLC(TInt aId, const TDesC& aKey) |
|
84 { |
|
85 MPX_DEBUG3(_L("#MS# CMPRopSettingItem::NewLC(%d,%S)"),aId,&aKey); |
|
86 CMPRopSettingItem* self = new(ELeave) CMPRopSettingItem(aId); |
|
87 |
|
88 CleanupStack::PushL(self); |
|
89 self->ConstructL(aKey); |
|
90 |
|
91 return self; |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CMPRopSettingItem::~CMPRopSettingItem |
|
96 // Destructor |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 CMPRopSettingItem::~CMPRopSettingItem() |
|
100 { |
|
101 MPX_DEBUG1(_L("#MS# CMPRopSettingItem::~CMPRopSettingItem()")); |
|
102 if (iKey) |
|
103 { |
|
104 delete iKey; |
|
105 } |
|
106 delete iStringValue; |
|
107 iIntArray.Close(); |
|
108 } |
|
109 |
|
110 |
|
111 // **************************************** |
|
112 // *** class CMPSettingsRopConfigParser *** |
|
113 // **************************************** |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CMPSettingsRopConfigParser::CMPSettingsRopConfigParser |
|
117 // C++ default constructor can NOT contain any code, that |
|
118 // might leave. |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 CMPSettingsRopConfigParser::CMPSettingsRopConfigParser() |
|
122 { |
|
123 MPX_DEBUG1(_L("#MS# CMPSettingsRopConfigParser::CMPSettingsRopConfigParser()")); |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CMPSettingsRopConfigParser::~CMPSettingsRopConfigParser |
|
128 // Destructor |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 CMPSettingsRopConfigParser::~CMPSettingsRopConfigParser() |
|
132 { |
|
133 MPX_DEBUG1(_L("#MS# CMPSettingsRopConfigParser::~CMPSettingsRopConfigParser()")); |
|
134 if (iEntries) |
|
135 iEntries->ResetAndDestroy(); |
|
136 delete iEntries; |
|
137 delete iTmpBuf; |
|
138 delete iConfigHeader; |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CMPSettingsRopConfigParser::ConstructL |
|
143 // Symbian 2nd phase constructor can leave. |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 void CMPSettingsRopConfigParser::ConstructL() |
|
147 { |
|
148 MPX_DEBUG1(_L("#MS# CMPSettingsRopConfigParser::ConstructL()")); |
|
149 iEntries = new(ELeave) CArrayPtrFlat<HBufC8>(KMPRopEntryArrayGranularity); |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CMPSettingsRopConfigParser::NewL |
|
154 // Two-phased constructor. |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 CMPSettingsRopConfigParser* CMPSettingsRopConfigParser::NewL() |
|
158 { |
|
159 MPX_DEBUG1(_L("#MS# CMPSettingsRopConfigParser::NewL()")); |
|
160 CMPSettingsRopConfigParser* self = new(ELeave) CMPSettingsRopConfigParser; |
|
161 |
|
162 CleanupStack::PushL(self); |
|
163 self->ConstructL(); |
|
164 CleanupStack::Pop(); |
|
165 |
|
166 return self; |
|
167 } |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // CMPSettingsRopConfigParser::ParseConfigStringL |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 HBufC8* CMPSettingsRopConfigParser::ParseConfigStringL(const TDesC8& aConfigString, const CArrayPtr<CMPRopSettingItem>* aItemArray) |
|
174 { |
|
175 MPX_DEBUG1(_L("#MS# CMPSettingsRopConfigParser::ParseConfigStringL()")); |
|
176 iBufferPtr.Set(aConfigString); |
|
177 iItemArray = aItemArray; |
|
178 |
|
179 // Parse header |
|
180 HBufC8* header = ParseConfigHeaderL(); |
|
181 CleanupStack::PushL(header); |
|
182 |
|
183 // Read all config entries to an array |
|
184 PopulateEntryArrayFromConfigStringL(); |
|
185 |
|
186 // Parse config entries from the array, delete items from the entry array |
|
187 ParseSettingsBufferL(); |
|
188 iEntries->ResetAndDestroy(); |
|
189 |
|
190 CleanupStack::Pop(); // header |
|
191 |
|
192 return header; |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // CMPSettingsRopConfigParser::CreateConfigStringL |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 HBufC8* CMPSettingsRopConfigParser::CreateConfigStringL(const CArrayPtr<CMPRopSettingItem>* aItemArray, const TDesC8& aConfigHeader) |
|
200 { |
|
201 MPX_DEBUG1(_L("#MS# CMPSettingsRopConfigParser::CreateConfigStringL()")); |
|
202 HBufC8* configString = NULL; |
|
203 iItemArray = aItemArray; |
|
204 |
|
205 delete iConfigHeader; |
|
206 iConfigHeader = NULL; |
|
207 iConfigHeader = HBufC8::NewL(aConfigHeader.Length() + 1); // magic, leave room for line separator (';') |
|
208 TPtr8 tmp = iConfigHeader->Des(); |
|
209 |
|
210 tmp.Append(aConfigHeader); |
|
211 tmp.Append(KMPRopEntrySeparator); |
|
212 |
|
213 PopulateEntryArrayFromItemArrayL(); |
|
214 |
|
215 // If iEntries->Count() == 1 -> iEntries contains only config header -> |
|
216 // none of the setting values has change => no need to create config string |
|
217 if (iEntries->Count() > 1) |
|
218 { |
|
219 configString = CreateConfigStringFromEntryArrayL(); |
|
220 } |
|
221 |
|
222 iEntries->ResetAndDestroy(); |
|
223 |
|
224 return configString; |
|
225 } |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CMPSettingsRopConfigParser::ParseConfigHeaderL |
|
229 // ----------------------------------------------------------------------------- |
|
230 // |
|
231 HBufC8* CMPSettingsRopConfigParser::ParseConfigHeaderL() |
|
232 { |
|
233 MPX_DEBUG1(_L("#MS# CMPSettingsRopConfigParser::ParseConfigHeaderL()")); |
|
234 HBufC8* buf = NULL; |
|
235 TPtrC8 ptr; |
|
236 TInt error = GetNextEntry(ptr); |
|
237 if (error) |
|
238 { |
|
239 // If header line cannot be found, the string is corrupted => Leave |
|
240 User::Leave(KErrCorrupt); |
|
241 } |
|
242 |
|
243 buf = ptr.AllocL(); |
|
244 return buf; |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // CMPSettingsRopConfigParser::NextConfigEntryL |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 HBufC8* CMPSettingsRopConfigParser::NextConfigEntryL(TInt& aError) |
|
252 { |
|
253 MPX_DEBUG1(_L("#MS# CMPSettingsRopConfigParser::NextConfigEntryL()")); |
|
254 HBufC8* buf = NULL; |
|
255 |
|
256 TPtrC8 ptr; |
|
257 aError = GetNextEntry(ptr); |
|
258 |
|
259 if (!aError) |
|
260 { |
|
261 buf = ptr.AllocL(); |
|
262 buf->Des().Trim(); |
|
263 } |
|
264 |
|
265 return buf; |
|
266 } |
|
267 |
|
268 // ----------------------------------------------------------------------------- |
|
269 // CMPSettingsRopConfigParser::PopulateEntryArrayFromConfigStringL |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 void CMPSettingsRopConfigParser::PopulateEntryArrayFromConfigStringL() |
|
273 { |
|
274 MPX_DEBUG1(_L("#MS# CMPSettingsRopConfigParser::PopulateEntryArrayFromConfigStringL()")); |
|
275 TInt error(KErrNone); |
|
276 iEntries->ResetAndDestroy(); |
|
277 |
|
278 do |
|
279 { |
|
280 HBufC8* buf = NextConfigEntryL(error); |
|
281 |
|
282 if (!error) |
|
283 { |
|
284 iEntries->AppendL(buf); |
|
285 } |
|
286 } |
|
287 while (!error); |
|
288 |
|
289 if (error != KErrNotFound) |
|
290 { |
|
291 User::Leave(error); |
|
292 } |
|
293 } |
|
294 |
|
295 // ----------------------------------------------------------------------------- |
|
296 // CMPSettingsRopConfigParser::PopulateEntryArrayFromItemArrayL |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 void CMPSettingsRopConfigParser::PopulateEntryArrayFromItemArrayL() |
|
300 { |
|
301 MPX_DEBUG1(_L("#MS# CMPSettingsRopConfigParser::PopulateEntryArrayFromItemArrayL()")); |
|
302 CMPRopSettingItem* item = NULL; |
|
303 HBufC8* buf = NULL; |
|
304 iEntries->ResetAndDestroy(); |
|
305 |
|
306 // Append config string header to array |
|
307 iEntries->AppendL(iConfigHeader); |
|
308 iConfigHeader = NULL; |
|
309 |
|
310 TInt count = iItemArray->Count(); |
|
311 for (TInt i = 0; i < count; ++i) |
|
312 { |
|
313 item = iItemArray->At(i); |
|
314 |
|
315 if (item->iValueChanged) |
|
316 { |
|
317 buf = CreateConfigEntryL(item); |
|
318 |
|
319 if (buf) |
|
320 { |
|
321 CleanupStack::PushL(buf); |
|
322 iEntries->AppendL(buf); |
|
323 CleanupStack::Pop(); // buf |
|
324 } |
|
325 } |
|
326 } |
|
327 } |
|
328 |
|
329 // ----------------------------------------------------------------------------- |
|
330 // CMPSettingsRopConfigParser::CreateConfigEntryL |
|
331 // ----------------------------------------------------------------------------- |
|
332 // |
|
333 HBufC8* CMPSettingsRopConfigParser::CreateConfigEntryL(CMPRopSettingItem* aItem) |
|
334 { |
|
335 MPX_DEBUG1(_L("#MS# CMPSettingsRopConfigParser::CreateConfigEntryL()")); |
|
336 HBufC8* buf = NULL; |
|
337 |
|
338 switch (aItem->iType) |
|
339 { |
|
340 case EMPRopConfTypeInteger: |
|
341 { |
|
342 buf = HBufC8::NewL(aItem->iKey->Length() + KMPRopIntegerEntryPrototypeStaticLength); |
|
343 TPtr8 ptr = buf->Des(); |
|
344 ptr.Format(KMPRopIntegerEntryPrototype, aItem->iKey, aItem->iIntValue); |
|
345 break; |
|
346 } |
|
347 case EMPRopConfTypeString: |
|
348 { |
|
349 HBufC* str = aItem->iStringValue; |
|
350 HBufC8* str8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *str ); |
|
351 CleanupStack::PushL( str8 ); |
|
352 TInt str8Length = str8->Length(); |
|
353 buf = HBufC8::NewL(aItem->iKey->Length() + str8Length + KMPRopStringEntryPrototypeStaticLength); |
|
354 TPtr8 ptr = buf->Des(); |
|
355 ptr.Format(KMPRopStringEntryPrototype, aItem->iKey, &(*str8)); |
|
356 CleanupStack::PopAndDestroy( str8 ); |
|
357 break; |
|
358 } |
|
359 default: |
|
360 break; |
|
361 } |
|
362 |
|
363 return buf; |
|
364 } |
|
365 |
|
366 |
|
367 // ----------------------------------------------------------------------------- |
|
368 // CMPSettingsRopConfigParser::GetNextEntry |
|
369 // ----------------------------------------------------------------------------- |
|
370 // |
|
371 TInt CMPSettingsRopConfigParser::GetNextEntry(TPtrC8& aEntry) |
|
372 { |
|
373 MPX_DEBUG1(_L("#MS# CMPSettingsRopConfigParser::GetNextEntry()")); |
|
374 TInt error(KErrNone); |
|
375 |
|
376 TInt offset = iBufferPtr.Find(KMPRopEntrySeparator); |
|
377 if (offset != KErrNotFound) |
|
378 { |
|
379 aEntry.Set(iBufferPtr.Left(offset)); |
|
380 iBufferPtr.Set(iBufferPtr.Mid(++offset)); // don't include ';' |
|
381 } |
|
382 else |
|
383 { |
|
384 error = KErrNotFound; |
|
385 } |
|
386 |
|
387 return error; |
|
388 } |
|
389 |
|
390 // ----------------------------------------------------------------------------- |
|
391 // CMPSettingsRopConfigParser::ParseSettingsBufferL |
|
392 // ----------------------------------------------------------------------------- |
|
393 // |
|
394 void CMPSettingsRopConfigParser::ParseSettingsBufferL() |
|
395 { |
|
396 MPX_DEBUG1(_L("#MS# CMPSettingsRopConfigParser::ParseSettingsBufferL()")); |
|
397 CMPRopSettingItem* item; |
|
398 TPtrC8 value; |
|
399 |
|
400 TInt count = iItemArray->Count(); |
|
401 for (TInt i = 0; i < count; ++i) |
|
402 { |
|
403 item = iItemArray->At(i); |
|
404 |
|
405 item->iError = GetConfigDataL(*item->iKey, value, item->iType); |
|
406 |
|
407 if (!item->iError) |
|
408 { |
|
409 switch (item->iType) |
|
410 { |
|
411 case EMPRopConfTypeInteger: |
|
412 { |
|
413 // Parse integer value |
|
414 TLex8 lex(value); |
|
415 item->iError = lex.Val(item->iIntValue); |
|
416 break; |
|
417 } |
|
418 case EMPRopConfTypeIntArray: |
|
419 { |
|
420 HBufC8* tmp = NULL; |
|
421 TInt offset = 0; // Magic: should not be KErrNotFound initially |
|
422 TInt error = KErrNone; |
|
423 TInt intVal = 0; |
|
424 item->iIntArray.Reset(); |
|
425 |
|
426 while (offset != KErrNotFound && !error) |
|
427 { |
|
428 offset = value.Find(KMPRopArraySeparator); |
|
429 |
|
430 if (offset != KErrNotFound) |
|
431 { |
|
432 tmp = value.Left(offset).AllocLC(); |
|
433 } |
|
434 else |
|
435 { |
|
436 tmp = value.AllocLC(); |
|
437 } |
|
438 |
|
439 tmp->Des().Trim(); |
|
440 TLex8 lex(*tmp); |
|
441 error = lex.Val(intVal); |
|
442 |
|
443 if (!error) |
|
444 { |
|
445 User::LeaveIfError(item->iIntArray.Append(intVal)); |
|
446 |
|
447 if (offset != KErrNotFound) |
|
448 { |
|
449 value.Set(value.Mid(offset + 1)); |
|
450 } |
|
451 } |
|
452 |
|
453 CleanupStack::PopAndDestroy(); // tmp |
|
454 tmp = NULL; |
|
455 } |
|
456 |
|
457 item->iError = error; |
|
458 break; |
|
459 } |
|
460 case EMPRopConfTypeString: |
|
461 // Parse string value |
|
462 value.Set(ValueStringPtr(value, item->iError)); |
|
463 |
|
464 if (!item->iError) |
|
465 { |
|
466 delete item->iStringValue; |
|
467 item->iStringValue = NULL; |
|
468 item->iStringValue = HBufC::NewL(value.Length()); |
|
469 |
|
470 TPtr tmp = item->iStringValue->Des(); |
|
471 CnvUtfConverter::ConvertToUnicodeFromUtf8(tmp, value); |
|
472 } |
|
473 break; |
|
474 default: |
|
475 item->iError = KErrNotSupported; |
|
476 break; |
|
477 } |
|
478 } |
|
479 } |
|
480 } |
|
481 |
|
482 // ----------------------------------------------------------------------------- |
|
483 // CMPSettingsRopConfigParser::GetConfigDataL |
|
484 // ----------------------------------------------------------------------------- |
|
485 // |
|
486 TInt CMPSettingsRopConfigParser::GetConfigDataL(const TDesC8& aKey, TPtrC8& aValue, TMPRopConfType& aType) |
|
487 { |
|
488 MPX_DEBUG1(_L("#MS# CMPSettingsRopConfigParser::GetConfigDataL()")); |
|
489 TInt ret = KErrNotFound; |
|
490 TInt offset = KErrNotFound; |
|
491 HBufC8* buf = NULL; |
|
492 |
|
493 // Try to find aConfigKey from the beginning of each entry untill one is found |
|
494 // (offset has to be 0, as there can be several different config keys that |
|
495 // include some other config key, e.g. "Timeout" vs. "ConnTimeout"). |
|
496 for (TInt i = 0; offset != 0 && i < iEntries->Count(); i++) |
|
497 { |
|
498 buf = iEntries->At(i); |
|
499 offset = buf->Find(aKey); |
|
500 } |
|
501 |
|
502 // Parse type and value if correct key was found |
|
503 if (offset == 0) |
|
504 { |
|
505 offset = buf->Find(KMPRopKeySeparator); |
|
506 TInt offset2 = buf->Find(KMPRopValueSeparator); |
|
507 TInt arrayOffset = buf->Find(KMPRopArrayOpeningMarker); |
|
508 |
|
509 if (offset != KErrNotFound && offset2 != KErrNotFound && offset < offset2) |
|
510 { |
|
511 ++offset; // Move past the key separator |
|
512 |
|
513 delete iTmpBuf; |
|
514 iTmpBuf = NULL; |
|
515 iTmpBuf = buf->Mid(offset, offset2 - offset).AllocL(); |
|
516 iTmpBuf->Des().Trim(); |
|
517 |
|
518 // Parse type |
|
519 if (*iTmpBuf == TPtrC8(KMPRopTypeInteger)) |
|
520 { |
|
521 if (arrayOffset == KErrNotFound) |
|
522 { |
|
523 aType = EMPRopConfTypeInteger; |
|
524 } |
|
525 else |
|
526 { |
|
527 aType = EMPRopConfTypeIntArray; |
|
528 } |
|
529 } |
|
530 else if (*iTmpBuf == TPtrC8(KMPRopTypeString)) |
|
531 { |
|
532 aType = EMPRopConfTypeString; |
|
533 } |
|
534 else |
|
535 { |
|
536 ret = KErrNotSupported; |
|
537 } |
|
538 |
|
539 if (ret != KErrNotSupported) |
|
540 { |
|
541 // Parse value |
|
542 delete iTmpBuf; |
|
543 iTmpBuf = NULL; |
|
544 |
|
545 if (aType == EMPRopConfTypeIntArray) |
|
546 { |
|
547 TInt arrayOffset2 = buf->Find(KMPRopArrayClosingMarker); |
|
548 |
|
549 if (arrayOffset2 != KErrNotFound && arrayOffset < arrayOffset2) |
|
550 { |
|
551 // Copy, but do not include markers |
|
552 iTmpBuf = buf->Mid(arrayOffset + 1, arrayOffset2 - arrayOffset - 1).AllocL(); |
|
553 ret = KErrNone; |
|
554 } |
|
555 else |
|
556 { |
|
557 return KErrCorrupt; |
|
558 } |
|
559 } |
|
560 else |
|
561 { |
|
562 iTmpBuf = buf->Mid(++offset2).AllocL(); // Move past the value separator |
|
563 ret = KErrNone; |
|
564 } |
|
565 |
|
566 iTmpBuf->Des().Trim(); |
|
567 |
|
568 aValue.Set(*iTmpBuf); |
|
569 } |
|
570 } |
|
571 } |
|
572 |
|
573 return ret; |
|
574 } |
|
575 |
|
576 // ----------------------------------------------------------------------------- |
|
577 // CMPSettingsRopConfigParser::ValueStringPtr |
|
578 // ----------------------------------------------------------------------------- |
|
579 // |
|
580 TPtrC8 CMPSettingsRopConfigParser::ValueStringPtr(const TDesC8& aValue, TInt& aError) |
|
581 { |
|
582 MPX_DEBUG1(_L("#MS# CMPSettingsRopConfigParser::ValueStringPtr()")); |
|
583 TPtrC8 ptr; |
|
584 aError = KErrNotFound; |
|
585 // Find first string constrainer |
|
586 TInt offset = aValue.Find(KMPRopStringConstrainer); |
|
587 |
|
588 if (offset != KErrNotFound) |
|
589 { |
|
590 TPtrC8 tmp; |
|
591 // 1.) Set offset1 to point the first character of the config string |
|
592 // 2.) Set characters after the first string constrainer to tmp |
|
593 tmp.Set(aValue.Mid(++offset)); |
|
594 // Find second string constrainer |
|
595 offset = tmp.Find(KMPRopStringConstrainer); |
|
596 |
|
597 if (offset != KErrNotFound) |
|
598 { |
|
599 // Set characters between the string constrainers to aString |
|
600 ptr.Set(tmp.Left(offset)); |
|
601 aError = KErrNone; |
|
602 } |
|
603 } |
|
604 |
|
605 return ptr; |
|
606 } |
|
607 |
|
608 // ----------------------------------------------------------------------------- |
|
609 // CMPSettingsRopConfigParser::CreateConfigStringFromEntryArrayL |
|
610 // ----------------------------------------------------------------------------- |
|
611 // |
|
612 HBufC8* CMPSettingsRopConfigParser::CreateConfigStringFromEntryArrayL() |
|
613 { |
|
614 MPX_DEBUG1(_L("#MS# CMPSettingsRopConfigParser::CreateConfigStringFromEntryArrayL()")); |
|
615 TInt length(0); |
|
616 TInt count = iEntries->Count(); |
|
617 for (TInt i = 0; i < count; ++i) |
|
618 { |
|
619 length += iEntries->At(i)->Length(); |
|
620 } |
|
621 |
|
622 HBufC8* configString = HBufC8::NewL(length); |
|
623 TPtr8 ptr = configString->Des(); |
|
624 |
|
625 for (TInt j = 0; j < count; ++j) |
|
626 { |
|
627 ptr.Append(*iEntries->At(j)); |
|
628 } |
|
629 |
|
630 return configString; |
|
631 } |
|
632 |
|
633 // End of File |