|
1 /* |
|
2 * Copyright (c) 2008 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 emergency numbers. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPhoneVoipNumberParser.h" |
|
21 #include "CPhoneGsmParserResult.h" |
|
22 #include "CPhoneGsmOptionContainer.h" |
|
23 #include "phoneParserCommon.h" |
|
24 |
|
25 // CONSTANTS |
|
26 |
|
27 // ============================ MEMBER FUNCTIONS =============================== |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CPhoneVoipNumberParser::CPhoneVoipNumberParser |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 CPhoneVoipNumberParser::CPhoneVoipNumberParser() |
|
34 { |
|
35 } |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CPhoneVoipNumberParser::NewLC |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CPhoneVoipNumberParser* CPhoneVoipNumberParser::NewLC() |
|
42 { |
|
43 CPhoneVoipNumberParser* self = |
|
44 new ( ELeave ) CPhoneVoipNumberParser; |
|
45 |
|
46 CleanupStack::PushL( self ); |
|
47 |
|
48 return self; |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CPhoneVoipNumberParser::ParseL |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 TBool CPhoneVoipNumberParser::ParseL( |
|
56 const TDesC& aString, |
|
57 CPhoneGsmParserResult& aResult, |
|
58 CPhoneGsmOptionContainerBase& aOptions ) |
|
59 { |
|
60 aResult.ClearL(); |
|
61 |
|
62 TBool result = DoParseL( |
|
63 aString, |
|
64 aResult, |
|
65 static_cast<CPhoneGsmOptionContainer&>( aOptions ) ); |
|
66 |
|
67 if ( !result ) |
|
68 { |
|
69 aResult.ClearL(); |
|
70 } |
|
71 |
|
72 return result; |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CPhoneVoipNumberParser::DoParseL |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 TBool CPhoneVoipNumberParser::DoParseL( |
|
80 const TDesC& aString, |
|
81 CPhoneGsmParserResult& aResult, |
|
82 CPhoneGsmOptionContainer& aOptions ) |
|
83 { |
|
84 TBool result( EFalse ); |
|
85 |
|
86 if ( aOptions.FindOptionStatus( KPhoneOptionSend ) ) |
|
87 { |
|
88 if ( aOptions.FindOptionStatus( KPhoneOptionVoipCall ) && |
|
89 aString.Length() ) |
|
90 { |
|
91 TLex input( aString ); |
|
92 |
|
93 // Take number part and put it to first parameter of the aResult. |
|
94 TakeNumberPartL( input, aResult ); |
|
95 // Take rest of string( postfix part ) to next parameter of the result. |
|
96 TakeDtmfPostfixL( input, aResult ); |
|
97 |
|
98 aResult.SetUid( KPhoneUidVoipNumber ); |
|
99 result = ETrue; |
|
100 } |
|
101 } |
|
102 |
|
103 return result; |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CPhoneVoipNumberParser::TakeNumberPartL |
|
108 // |
|
109 // Take the main part of the phone number and add it to result. |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 void CPhoneVoipNumberParser::TakeNumberPartL( |
|
113 TLex& aLex, |
|
114 CPhoneGsmParserResult& aResult ) |
|
115 { |
|
116 TLexMark start; |
|
117 aLex.Mark( start ); |
|
118 TBool allDigits = ETrue; |
|
119 TBool dtmfFound = EFalse; |
|
120 |
|
121 while ( !aLex.Eos() && |
|
122 !dtmfFound ) |
|
123 { |
|
124 TChar nextChar = aLex.Peek().GetLowerCase(); |
|
125 if ( allDigits && |
|
126 ( KPhoneDtmfPause == nextChar || |
|
127 KPhoneDtmfWait == nextChar || |
|
128 KPhonePlus == nextChar ) ) |
|
129 { |
|
130 // Dtmf string is always postfixed if present |
|
131 if ( aLex.Offset() > 0 ) |
|
132 { |
|
133 // Check if rest of the string is valid dtmf string |
|
134 TPtrC remainder( aLex.Remainder() ); |
|
135 if ( IsValidDtmfString( remainder ) ) |
|
136 { |
|
137 dtmfFound = ETrue; |
|
138 } |
|
139 } |
|
140 } |
|
141 |
|
142 if ( !dtmfFound ) |
|
143 { |
|
144 if ( !nextChar.IsDigit() && |
|
145 nextChar != KPhonePlus ) |
|
146 { |
|
147 allDigits = EFalse; |
|
148 } |
|
149 aLex.Inc(); |
|
150 } |
|
151 } |
|
152 |
|
153 // Add main part of the number to the parsing result |
|
154 TPtrC mainpart( aLex.MarkedToken( start ) ); |
|
155 aResult.AddParameterL( mainpart ); |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // CPhoneVoipNumberParser::TakeDtmfPostfixL |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void CPhoneVoipNumberParser::TakeDtmfPostfixL( |
|
163 TLex& aLex, |
|
164 CPhoneGsmParserResult& aResult ) |
|
165 { |
|
166 // Add rest of string( after TLex16::iNext ) to result. |
|
167 aResult.AddParameterL( aLex.Remainder() ); |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CPhoneVoipNumberParser::IsValidDtmfString |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 TBool CPhoneVoipNumberParser::IsValidDtmfString( TPtrC& aString ) |
|
175 { |
|
176 TBool validDtmf = ETrue; |
|
177 // Check that string contains only valid dtmf characters |
|
178 for( TInt i = 0; i < aString.Length(); i++ ) |
|
179 { |
|
180 if ( KErrNotFound == KValidDtmfChars().Locate( aString[i] ) ) |
|
181 { |
|
182 validDtmf = EFalse; |
|
183 break; |
|
184 } |
|
185 } |
|
186 return validDtmf; |
|
187 } |
|
188 // End of File |