|
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: Parser for phone numbers. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPhoneGsmPhoneNumberParser.h" |
|
21 #include "CPhoneGsmParserResult.h" |
|
22 #include "CPhoneGsmOptionContainer.h" |
|
23 #include "CPhoneVoipNumberParser.h" |
|
24 #include "CPhoneParserFeatures.h" |
|
25 #include "phoneParserCommon.h" |
|
26 // CONSTANTS |
|
27 _LIT( KPhoneClirSuppress, "*31#" ); |
|
28 _LIT( KPhoneClirInvoke, "#31#" ); |
|
29 |
|
30 const TInt KPhoneNumberOne = '1'; |
|
31 |
|
32 const TInt KPhoneNumberMaxLength = 80; |
|
33 |
|
34 const TInt KPhoneShortStringMinLength = 1; // Must be positive. |
|
35 const TInt KPhoneShortStringMaxLength = 2; // Must be positive. |
|
36 const TInt KPhoneHashStringMinLength = 2; |
|
37 const TInt KPhoneTwoDigitStringLength = 2; |
|
38 |
|
39 // If there is one of the characters in the string, then the string |
|
40 // is considered as phone number. |
|
41 _LIT( KPhoneMustPhoneNumberChars, "pw" ); |
|
42 _LIT( KPhoneHashChar, "#" ); |
|
43 _LIT( KPhoneNumberZero, "0" ); |
|
44 |
|
45 |
|
46 // ============================ MEMBER FUNCTIONS =============================== |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CPhoneGsmPhoneNumberParser::CPhoneGsmPhoneNumberParser |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CPhoneGsmPhoneNumberParser::CPhoneGsmPhoneNumberParser() |
|
53 { |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CPhoneGsmPhoneNumberParser::NewLC |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CPhoneGsmPhoneNumberParser* CPhoneGsmPhoneNumberParser::NewLC() |
|
61 { |
|
62 CPhoneGsmPhoneNumberParser* self = |
|
63 new ( ELeave ) CPhoneGsmPhoneNumberParser; |
|
64 |
|
65 CleanupStack::PushL( self ); |
|
66 |
|
67 return self; |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CPhoneGsmPhoneNumberParser::ParseL |
|
72 // |
|
73 // Phone number can contain following parts: supplementary |
|
74 // service prefix, main part and dtmf postfix. |
|
75 // |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 TBool CPhoneGsmPhoneNumberParser::ParseL( |
|
79 const TDesC& aString, |
|
80 CPhoneGsmParserResult& aResult, |
|
81 CPhoneGsmOptionContainerBase& aOptions ) |
|
82 { |
|
83 aResult.ClearL(); |
|
84 |
|
85 TBool result = DoParseL( |
|
86 aString, |
|
87 aResult, |
|
88 static_cast<CPhoneGsmOptionContainer&>( aOptions ) ); |
|
89 |
|
90 if ( !result ) |
|
91 { |
|
92 aResult.ClearL(); |
|
93 } |
|
94 |
|
95 return result; |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CPhoneGsmPhoneNumberParser::DoParseL |
|
100 // |
|
101 // Phone number can contain following parts: supplementary |
|
102 // service prefix, main part and dtmf postfix. |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 TBool CPhoneGsmPhoneNumberParser::DoParseL( |
|
106 const TDesC& aString, |
|
107 CPhoneGsmParserResult& aResult, |
|
108 CPhoneGsmOptionContainer& aOptions ) |
|
109 { |
|
110 TBool result = EFalse; |
|
111 |
|
112 if ( !aOptions.FindOptionStatus( KPhoneOptionSend )) |
|
113 { |
|
114 return EFalse; |
|
115 } |
|
116 if ( !ContainsPauseOrWaitChars( aString )) // p or w --> always phone number |
|
117 { |
|
118 if ( IsHashString( aString )) |
|
119 { |
|
120 return EFalse; |
|
121 } |
|
122 if ( aString.Length() >= KPhoneShortStringMinLength && |
|
123 aString.Length() <= KPhoneShortStringMaxLength ) |
|
124 { |
|
125 if ( !IsZeroDialling( aString, aOptions ) && |
|
126 !IsTwoDigitDialling( aString ) && !Is1xDialling( aString, aOptions )) |
|
127 { |
|
128 return EFalse; |
|
129 } |
|
130 } |
|
131 } |
|
132 TLex input( aString ); |
|
133 |
|
134 if ( !HandleServicePrefix( input, aResult ) ) |
|
135 { |
|
136 aResult.SetAuxInformation( KPhoneDialDefaultClir ); |
|
137 } |
|
138 |
|
139 // Take number part and add it to result. |
|
140 result = TakeNumberPartL( input, aResult ); |
|
141 |
|
142 if ( result ) |
|
143 { |
|
144 if ( !aOptions.FindOptionStatus( KPhoneOptionVoipCall ) ) |
|
145 { |
|
146 aResult.SetUid( KPhoneUidPhoneNumber ); |
|
147 } |
|
148 |
|
149 // Add rest of string( dtmf postfix ) to result. |
|
150 if ( !TakeDtmfPostfixL( input, aResult ) ) |
|
151 { |
|
152 aResult.AddParameterL( KNullDesC ); |
|
153 } |
|
154 } |
|
155 |
|
156 return result; |
|
157 } |
|
158 |
|
159 // ----------------------------------------------------------------------------- |
|
160 // CPhoneGsmPhoneNumberParser::HandleServicePrefix |
|
161 // |
|
162 // Checks if there is clir suppress/invoke prefix in the |
|
163 // string. |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 TBool CPhoneGsmPhoneNumberParser::HandleServicePrefix( |
|
167 TLex& aLex, |
|
168 CPhoneGsmParserResult& aResult ) |
|
169 { |
|
170 TBool result = EFalse; |
|
171 TPtrC remainder( aLex.Remainder() ); |
|
172 |
|
173 if ( EqualsLeft( remainder, KPhoneClirSuppress ) ) |
|
174 { |
|
175 aLex.Inc( KPhoneClirSuppress().Length() ); |
|
176 aResult.SetAuxInformation( KPhoneDialSuppressClir ); |
|
177 result = ETrue; |
|
178 } |
|
179 else if ( EqualsLeft( remainder, KPhoneClirInvoke ) ) |
|
180 { |
|
181 aLex.Inc( KPhoneClirSuppress().Length() ); |
|
182 aResult.SetAuxInformation( KPhoneDialInvokeClir ); |
|
183 result = ETrue; |
|
184 } |
|
185 |
|
186 return result; |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CPhoneGsmPhoneNumberParser::TakeNumberPartL |
|
191 // |
|
192 // Takes a main part of the phone number. And add |
|
193 // it to the aReturn parameter with or without optional international prefix. |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 TBool CPhoneGsmPhoneNumberParser::TakeNumberPartL( |
|
197 TLex& aLex, |
|
198 CPhoneGsmParserResult& aResult ) |
|
199 { |
|
200 TBool result = EFalse; |
|
201 |
|
202 TLexMark start; |
|
203 aLex.Mark( start ); |
|
204 |
|
205 TInt maxLength = KPhoneNumberMaxLength; |
|
206 |
|
207 // Checks is first char optional international prefix |
|
208 // and if its increments to the next char position. |
|
209 if ( aLex.Peek() == KPhonePlus ) |
|
210 { |
|
211 aLex.Inc(); |
|
212 maxLength++; |
|
213 } |
|
214 |
|
215 // Check possible 'p','w' or '+' marks. |
|
216 while ( ( aLex.Peek().IsDigit() ) || |
|
217 ( aLex.Peek() == KPhoneNumberAsterisk ) || |
|
218 ( aLex.Peek() == KPhoneNumberHash ) ) |
|
219 { |
|
220 aLex.Inc(); |
|
221 } |
|
222 |
|
223 // Add parsing string to result parameter |
|
224 TPtrC mainpart( aLex.MarkedToken( start ) ); |
|
225 const TInt length = mainpart.Length(); |
|
226 if ( length <= maxLength ) |
|
227 { |
|
228 result = ETrue; |
|
229 aResult.AddParameterL( mainpart ); |
|
230 } |
|
231 |
|
232 return result; |
|
233 } |
|
234 |
|
235 // ----------------------------------------------------------------------------- |
|
236 // CPhoneGsmPhoneNumberParser::TakeDtmfPostfixL |
|
237 // ----------------------------------------------------------------------------- |
|
238 // |
|
239 TBool CPhoneGsmPhoneNumberParser::TakeDtmfPostfixL( |
|
240 TLex& aLex, |
|
241 CPhoneGsmParserResult& aResult ) |
|
242 { |
|
243 // Add rest of string( after TLex16::iNext ) to result. |
|
244 aResult.AddParameterL( aLex.Remainder() ); |
|
245 return ETrue; |
|
246 } |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // CPhoneGsmPhoneNumberParser::EqualsLeft |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 TBool CPhoneGsmPhoneNumberParser::EqualsLeft( |
|
253 const TDesC& aDesc, |
|
254 const TDesC& aLeft ) |
|
255 { |
|
256 return IsPrefixOf( aDesc, aLeft ); |
|
257 } |
|
258 |
|
259 // ----------------------------------------------------------------------------- |
|
260 // CPhoneGsmPhoneNumberParser::ContainsPauseOrWaitChars |
|
261 // ----------------------------------------------------------------------------- |
|
262 // |
|
263 TBool CPhoneGsmPhoneNumberParser::ContainsPauseOrWaitChars( |
|
264 const TDesC& aString ) const |
|
265 { |
|
266 |
|
267 TBool result = EFalse; |
|
268 TPtrC chs( KPhoneMustPhoneNumberChars ); |
|
269 for ( TInt index = 0; index < chs.Length(); index++ ) |
|
270 { |
|
271 if ( aString.Locate( chs[ index ] ) != KErrNotFound ) |
|
272 { |
|
273 result = ETrue; |
|
274 break; |
|
275 } |
|
276 } |
|
277 |
|
278 return result; |
|
279 } |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // CPhoneGsmPhoneNumberParser::IsHashString |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 TBool CPhoneGsmPhoneNumberParser::IsHashString( |
|
286 const TDesC& aString ) const |
|
287 { |
|
288 return aString.Length() >= KPhoneHashStringMinLength && |
|
289 // Rightmost character must be # |
|
290 aString.Right( 1 ) == KPhoneHashChar; |
|
291 } |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // CPhoneGsmPhoneNumberParser::IsZeroDialling |
|
295 // ----------------------------------------------------------------------------- |
|
296 // |
|
297 TBool CPhoneGsmPhoneNumberParser::IsZeroDialling( |
|
298 const TDesC& aString, CPhoneGsmOptionContainer& aOptions ) const |
|
299 { |
|
300 return !aOptions.FindOptionStatus( KPhoneOptionInCall ) && |
|
301 !aString.Compare( KPhoneNumberZero ) && |
|
302 CPhoneParserFeatures::IsZeroDialEnabled(); |
|
303 } |
|
304 |
|
305 // ----------------------------------------------------------------------------- |
|
306 // CPhoneGsmPhoneNumberParser::IsTwoDigitDialling |
|
307 // ----------------------------------------------------------------------------- |
|
308 // |
|
309 TBool CPhoneGsmPhoneNumberParser::IsTwoDigitDialling( |
|
310 const TDesC& aString ) const |
|
311 { |
|
312 return CPhoneParserFeatures::TwoDigitCallingEnabled() && |
|
313 aString.Length()== KPhoneTwoDigitStringLength; |
|
314 } |
|
315 |
|
316 // ----------------------------------------------------------------------------- |
|
317 // CPhoneGsmPhoneNumberParser::Is1xDialling |
|
318 // ----------------------------------------------------------------------------- |
|
319 // |
|
320 TBool CPhoneGsmPhoneNumberParser::Is1xDialling( |
|
321 const TDesC& aString, CPhoneGsmOptionContainer& aOptions ) const |
|
322 { |
|
323 return !aOptions.FindOptionStatus( KPhoneOptionInCall ) && |
|
324 aString.Length()== KPhoneShortStringMaxLength && |
|
325 aString[0] == KPhoneNumberOne && |
|
326 TChar( aString[1] ).IsDigit(); |
|
327 } |
|
328 |
|
329 // End of File |