|
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: |
|
15 * parsing command lines could be used in view activation |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "BrowserCommandLineParser.h" |
|
23 #include "Logger.h" |
|
24 |
|
25 LOCAL_D const TInt KParamsArrayGranularity = 8; |
|
26 |
|
27 // ========================= MEMBER FUNCTIONS ================================ |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // CBrowserCommandLineParser8::CBrowserCommandLineParser8() |
|
31 // --------------------------------------------------------------------------- |
|
32 CBrowserCommandLineParser8::CBrowserCommandLineParser8() |
|
33 { |
|
34 } |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // CBrowserCommandLineParser8::~CBrowserCommandLineParser8 |
|
38 // --------------------------------------------------------------------------- |
|
39 CBrowserCommandLineParser8::~CBrowserCommandLineParser8() |
|
40 { |
|
41 LOG_ENTERFN("CBrowserCommandLineParser8::~CBrowserCommandLineParser8"); |
|
42 delete ( iParamString ); |
|
43 delete ( iParams ); |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // CBrowserCommandLineParser8::NewL |
|
48 // --------------------------------------------------------------------------- |
|
49 CBrowserCommandLineParser8* CBrowserCommandLineParser8::NewL( |
|
50 const TDesC8& aParamString ) |
|
51 { |
|
52 CBrowserCommandLineParser8* self = |
|
53 CBrowserCommandLineParser8::NewLC( aParamString ); |
|
54 CleanupStack::Pop(); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // CBrowserCommandLineParser8::NewLC |
|
60 // --------------------------------------------------------------------------- |
|
61 CBrowserCommandLineParser8* CBrowserCommandLineParser8::NewLC( |
|
62 const TDesC8& aParamString ) |
|
63 { |
|
64 LOG_ENTERFN("CBrowserCommandLineParser8::NewLC"); |
|
65 CBrowserCommandLineParser8* self = |
|
66 new ( ELeave ) CBrowserCommandLineParser8 ( ); |
|
67 CleanupStack::PushL( self ); |
|
68 self->ConstructL( aParamString ); |
|
69 return self; |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // CBrowserCommandLineParser8::ConstructL |
|
74 // --------------------------------------------------------------------------- |
|
75 void CBrowserCommandLineParser8::ConstructL( const TDesC8& aParamString ) |
|
76 { |
|
77 LOG_ENTERFN("CBrowserCommandLineParser8::ConstructL"); |
|
78 TInt length = aParamString.Length(); |
|
79 iParamString = HBufC8::NewL( length );//the maxlength of buf = the length of the param |
|
80 *iParamString = aParamString; |
|
81 iParams = new( ELeave ) CArrayFixFlat<TPtrC8>( KParamsArrayGranularity ); |
|
82 FillUpParamsL(); |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // CBrowserCommandLineParser8::Count |
|
87 // --------------------------------------------------------------------------- |
|
88 TUint CBrowserCommandLineParser8::Count() const |
|
89 { |
|
90 LOG_ENTERFN("CBrowserCommandLineParser8::Count"); |
|
91 return iParams->Count(); |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // CBrowserCommandLineParser8::SetL |
|
96 // --------------------------------------------------------------------------- |
|
97 void CBrowserCommandLineParser8::SetL( const TDesC8& aParamString ) |
|
98 { |
|
99 LOG_ENTERFN("CBrowserCommandLineParser8::SetL"); |
|
100 iParamString->ReAllocL( aParamString.Length() ); |
|
101 *iParamString = aParamString; |
|
102 iParams->Reset(); |
|
103 FillUpParamsL(); |
|
104 } |
|
105 |
|
106 // --------------------------------------------------------------------------- |
|
107 // CBrowserCommandLineParser8::Param |
|
108 // --------------------------------------------------------------------------- |
|
109 TPtrC8 CBrowserCommandLineParser8::Param( TUint aIndex ) |
|
110 { |
|
111 LOG_ENTERFN("CBrowserCommandLineParser8::Param"); |
|
112 TPtrC8 retVal; |
|
113 ( aIndex < Count( ) )? ( retVal.Set( iParams->At( aIndex ) ) ) : |
|
114 ( retVal.Set( KNullDesC8 ) ); |
|
115 return retVal; |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // CBrowserCommandLineParser8::IntegerParam |
|
120 // --------------------------------------------------------------------------- |
|
121 TBool CBrowserCommandLineParser8::IntegerParam( TUint aIndex ) |
|
122 { |
|
123 LOG_ENTERFN("CBrowserCommandLineParser8::IntegerParam"); |
|
124 if ( aIndex >= Count () ) |
|
125 { |
|
126 return EFalse; |
|
127 } |
|
128 TLex8 lex( iParams->At ( aIndex ) ); |
|
129 TInt a; |
|
130 if ( lex.Val( a ) == KErrNone ) |
|
131 { |
|
132 return ETrue; |
|
133 } |
|
134 else |
|
135 { |
|
136 return EFalse; |
|
137 } |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // CBrowserCommandLineParser8::ParamToInteger |
|
142 // --------------------------------------------------------------------------- |
|
143 TInt CBrowserCommandLineParser8::ParamToInteger( TUint aIndex ) |
|
144 { |
|
145 LOG_ENTERFN("CBrowserCommandLineParser8::ParamToInteger"); |
|
146 TInt retInt = KMaxTInt; |
|
147 if ( aIndex < Count () ) |
|
148 { |
|
149 TLex8 lex ( iParams -> At( aIndex )); |
|
150 lex.Val( retInt ); |
|
151 } |
|
152 return retInt; |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // CBrowserCommandLineParser8::FillUpParamsL |
|
157 // --------------------------------------------------------------------------- |
|
158 void CBrowserCommandLineParser8::FillUpParamsL() |
|
159 { |
|
160 LOG_ENTERFN("CBrowserCommandLineParser8::FillUpParamsL"); |
|
161 TLex8 lex( *iParamString ); |
|
162 while ( !lex.Eos() ) |
|
163 { |
|
164 TPtrC8 token = lex.NextToken(); |
|
165 iParams->AppendL( token ); |
|
166 } |
|
167 } |
|
168 |
|
169 //End of File |