|
1 /* |
|
2 * Copyright (c) 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: Implementation of view utility helper |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "mpxviewutilityhelper.h" |
|
22 |
|
23 // CONSTANTS |
|
24 _LIT8( KMPXDelimiter8, ";" ); |
|
25 _LIT8( KMPXHexMarker8, "0x" ); |
|
26 |
|
27 _LIT( KMPXDelimiter, ";" ); |
|
28 _LIT( KMPXHexMarker, "0x" ); |
|
29 |
|
30 // ======== MEMBER FUNCTIONS ======== |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // Extracts number from data. ( 8 bit ) |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 TInt CMPXViewUtilityHelper::ExtractNum( |
|
37 const TDesC8& aData, |
|
38 TInt& aNextPos, |
|
39 TInt& aResult ) |
|
40 { |
|
41 if ( aNextPos < 0 || aNextPos > aData.Length() ) |
|
42 { |
|
43 aNextPos = KErrNotFound; |
|
44 return KErrArgument; |
|
45 } |
|
46 |
|
47 TInt err( KErrNone ); |
|
48 TPtrC8 string( aData.Mid( aNextPos ) ); |
|
49 |
|
50 if ( string.Length() ) |
|
51 { |
|
52 TInt delimiterPos = string.Find( KMPXDelimiter8 ); |
|
53 if ( KErrNotFound != delimiterPos ) |
|
54 { |
|
55 string.Set( aData.Mid( aNextPos, delimiterPos ) ); |
|
56 aNextPos += delimiterPos + KMPXDelimiter8().Length(); |
|
57 if ( aNextPos >= aData.Length() ) |
|
58 { |
|
59 // Reach the end of string |
|
60 aNextPos = KErrNotFound; |
|
61 } |
|
62 } |
|
63 else |
|
64 { |
|
65 // Reach the end of string |
|
66 aNextPos = KErrNotFound; |
|
67 } |
|
68 |
|
69 // Convert string to integer |
|
70 TInt hexMarkerPos = string.Find( KMPXHexMarker8 ); |
|
71 if ( KErrNotFound != hexMarkerPos ) |
|
72 { |
|
73 TUint numHex( 0 ); |
|
74 TLex8 lexHex( string.Mid( KMPXHexMarker8().Length() ) ); |
|
75 err = lexHex.Val( numHex, EHex ); |
|
76 aResult = numHex; |
|
77 } |
|
78 else |
|
79 { |
|
80 TLex8 lexDec( string ); |
|
81 err = lexDec.Val( aResult ); |
|
82 } |
|
83 } |
|
84 else |
|
85 { |
|
86 aNextPos = KErrNotFound; |
|
87 err = KErrNotFound; |
|
88 } |
|
89 |
|
90 return err; |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // Extracts number from data. ( generic ) |
|
95 // --------------------------------------------------------------------------- |
|
96 // |
|
97 TInt CMPXViewUtilityHelper::ExtractNum( |
|
98 const TDesC& aData, |
|
99 TInt& aNextPos, |
|
100 TInt& aResult ) |
|
101 { |
|
102 if ( aNextPos < 0 || aNextPos > aData.Length() ) |
|
103 { |
|
104 aNextPos = KErrNotFound; |
|
105 return KErrGeneral; |
|
106 } |
|
107 |
|
108 TInt err( KErrNone ); |
|
109 TPtrC string( aData.Mid( aNextPos ) ); |
|
110 |
|
111 if ( string.Length() ) |
|
112 { |
|
113 TInt delimiterPos = string.Find( KMPXDelimiter ); |
|
114 if ( KErrNotFound != delimiterPos ) |
|
115 { |
|
116 string.Set( aData.Mid( aNextPos, delimiterPos ) ); |
|
117 aNextPos += delimiterPos + KMPXDelimiter().Length(); |
|
118 if ( aNextPos >= aData.Length() ) |
|
119 { |
|
120 // Reach the end of string |
|
121 aNextPos = KErrNotFound; |
|
122 } |
|
123 } |
|
124 else |
|
125 { |
|
126 // Reach the end of string |
|
127 aNextPos = KErrNotFound; |
|
128 } |
|
129 |
|
130 // Convert string to integer |
|
131 TInt hexMarkerPos = string.Find( KMPXHexMarker ); |
|
132 if ( KErrNotFound != hexMarkerPos ) |
|
133 { |
|
134 TUint numHex( 0 ); |
|
135 TLex lexHex( string.Mid( KMPXHexMarker().Length() ) ); |
|
136 err = lexHex.Val( numHex, EHex ); |
|
137 aResult = numHex; |
|
138 } |
|
139 else |
|
140 { |
|
141 TLex lexDec( string ); |
|
142 err = lexDec.Val( aResult ); |
|
143 } |
|
144 } |
|
145 else |
|
146 { |
|
147 aNextPos = KErrNotFound; |
|
148 err = KErrNotFound; |
|
149 } |
|
150 |
|
151 return err; |
|
152 } |
|
153 |
|
154 // End of File |