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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "obexutilsopaquedata.h" |
|
21 |
|
22 // ================= MEMBER FUNCTIONS ======================= |
|
23 EXPORT_C CObexUtilsOpaqueData::CObexUtilsOpaqueData(const TDesC8& aDes):iData(aDes) |
|
24 { |
|
25 } |
|
26 |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // GetString |
|
30 // Get string from current location. Return error code if invalid string format. |
|
31 // ----------------------------------------------------------------------------- |
|
32 EXPORT_C TInt CObexUtilsOpaqueData::GetString(TBuf8<KObexUtilsMaxOpaqueDataStringLen> &aString) |
|
33 { |
|
34 // reset the output string |
|
35 aString.Zero(); |
|
36 |
|
37 if (iData.Eos()) |
|
38 return KErrNotFound ; |
|
39 TChar c; |
|
40 TInt ret; |
|
41 while(c=iData.Get()) |
|
42 { |
|
43 if(c=='\\') |
|
44 { |
|
45 switch(iData.Peek()) |
|
46 { |
|
47 case 'x': |
|
48 case 'X': |
|
49 // parse hex number |
|
50 TUint8 val; |
|
51 iData.Inc(); |
|
52 ret=iData.Val(val,EHex); |
|
53 if(ret == KErrNone) |
|
54 aString.Append(val); |
|
55 else |
|
56 return ret; |
|
57 break; |
|
58 case '|': |
|
59 iData.Inc(); |
|
60 aString.Append('|'); |
|
61 break; |
|
62 case '\\': |
|
63 iData.Inc(); |
|
64 aString.Append('\\'); |
|
65 break; |
|
66 default: |
|
67 // if not a decimal number, then bad format |
|
68 TInt8 dval; |
|
69 ret=iData.Val(dval); |
|
70 if(ret == KErrNone) |
|
71 aString.Append(dval); |
|
72 else |
|
73 return ret; |
|
74 } |
|
75 } |
|
76 else if(c=='|') |
|
77 { |
|
78 if(iData.Peek()=='|') |
|
79 { |
|
80 // delimiter "||" found, end of the string |
|
81 iData.Inc(); |
|
82 break; |
|
83 } |
|
84 else |
|
85 aString.Append(c); |
|
86 } |
|
87 else |
|
88 aString.Append(c); |
|
89 } |
|
90 |
|
91 return KErrNone; |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // GetNumber |
|
96 // Get number from current location. Return error code if invalid number format. |
|
97 // ----------------------------------------------------------------------------- |
|
98 EXPORT_C TInt CObexUtilsOpaqueData::GetNumber(TUint &aNumber) |
|
99 { |
|
100 if (iData.Eos()) |
|
101 return KErrNotFound ; |
|
102 |
|
103 // skip dilimiter |
|
104 if(iData.Peek()=='|') |
|
105 { |
|
106 iData.Inc(); |
|
107 if(iData.Peek()=='|') |
|
108 iData.Inc(); |
|
109 else |
|
110 return KErrNotFound ; |
|
111 } |
|
112 |
|
113 if(iData.Peek()=='0') |
|
114 { |
|
115 iData.Inc(); |
|
116 if(iData.Peek()=='x' || iData.Peek()=='X') |
|
117 { |
|
118 iData.Inc(); |
|
119 return iData.Val(aNumber,EHex); |
|
120 } |
|
121 else |
|
122 { |
|
123 iData.UnGet(); |
|
124 return iData.Val(aNumber,EOctal); |
|
125 } |
|
126 } |
|
127 else |
|
128 { |
|
129 return iData.Val(aNumber); |
|
130 } |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // IsString |
|
135 // Peek if next entry is string by looking for a '\'. |
|
136 // ----------------------------------------------------------------------------- |
|
137 EXPORT_C TBool CObexUtilsOpaqueData::IsString() |
|
138 { |
|
139 return iData.Peek()=='\\'; |
|
140 } |
|
141 |
|