1 /** @file |
|
2 * Copyright (c) 2005-2006 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: helper class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "upnpavcpenginehelper.h" |
|
20 |
|
21 namespace UpnpAVCPEngine |
|
22 { |
|
23 |
|
24 // ----------------------------------------------------------------------------- |
|
25 // UpnpAVCPEngine::StrToIntL |
|
26 // ----------------------------------------------------------------------------- |
|
27 // |
|
28 TInt StrToIntL(const TDesC8& aValue) |
|
29 { |
|
30 TLex8 returnedLex( aValue ); |
|
31 TInt value; |
|
32 User::LeaveIfError( returnedLex.Val( value )); |
|
33 return value; |
|
34 } |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // UpnpAVCPEngine::GetLastPathElementL |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 HBufC8* GetLastPathElementL(TDes8& aPath) |
|
41 { |
|
42 RemoveSlashes(aPath); |
|
43 TInt index = aPath.LocateReverse('/'); |
|
44 if (index == KErrNotFound) |
|
45 index = 0; |
|
46 |
|
47 HBufC8* result = aPath.Right(aPath.Length() - index).AllocL(); |
|
48 TPtr8 ptr = result->Des(); |
|
49 RemoveSlashes(ptr); |
|
50 aPath.Delete( index, aPath.Length() - index); |
|
51 return result; |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // UpnpAVCPEngine::ParsePathToElementsL |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 void ParsePathToElementsL(TPtr8 aPath, RPointerArray<TPtrC8>& aArray ) |
|
59 { |
|
60 TChar delimiter('/'); |
|
61 RemoveSlashes(aPath); |
|
62 |
|
63 TPtrC8 ptr(aPath); |
|
64 TInt i = 0; |
|
65 |
|
66 while(KErrNotFound != ptr.Locate(delimiter)) |
|
67 { |
|
68 aArray.Append( new (ELeave)TPtrC8() ); |
|
69 aArray[i]->Set(ptr.Left((ptr.Locate(delimiter)))); |
|
70 ptr.Set(ptr.Right(ptr.Length() - (ptr.Locate(delimiter) + 1)) ); |
|
71 i++; |
|
72 } |
|
73 |
|
74 aArray.Append( new (ELeave) TPtrC8() ); |
|
75 aArray[i]->Set(ptr); |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // UpnpAVCPEngine::RemoveSlashes |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 void RemoveSlashes(TDes8& aPath) |
|
83 { |
|
84 if (aPath.Length() > 0 && aPath[0] == '/' ) |
|
85 { |
|
86 aPath.Delete(0,1); |
|
87 } |
|
88 |
|
89 // remove ending '/' |
|
90 TInt length = aPath.Length(); |
|
91 if (length > 0 && aPath[length-1] == '/' ) |
|
92 { |
|
93 aPath.Delete(length-1,1); |
|
94 } |
|
95 } |
|
96 |
|
97 } |
|
98 |
|
99 // End of File |
|