|
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: Contains the source for Descriptor8 to string conversions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "libutils.h" |
|
21 |
|
22 |
|
23 |
|
24 /** |
|
25 * Converts a descriptor of type TBuf8 to string datatype |
|
26 * |
|
27 * @param aSrc is the descriptor to be converted , aDes is the |
|
28 * reference to the string to which the result of conversion |
|
29 * is stored , |
|
30 * @return Status code (0 is ESuccess, -1 is EInsufficientMemory |
|
31 * -4 is EDescriptorNoData) |
|
32 */ |
|
33 |
|
34 EXPORT_C int Tbuf8ToString(TDes8& aSrc, string& aDes) |
|
35 { |
|
36 unsigned int ilen = aSrc.Length(); |
|
37 if (ilen == 0) |
|
38 { |
|
39 return EDescriptorNoData; |
|
40 } |
|
41 |
|
42 char* charString = new char[ilen +1]; |
|
43 if (!charString) |
|
44 { |
|
45 return EInsufficientSystemMemory; |
|
46 } |
|
47 |
|
48 memcpy(charString, (char*)aSrc.Ptr(), ilen); |
|
49 charString[ilen] = '\0'; |
|
50 |
|
51 aDes.assign(charString); |
|
52 |
|
53 delete []charString; |
|
54 return ESuccess; |
|
55 } |
|
56 |
|
57 /** |
|
58 * Converts a descriptor of type TBufC8 to string datatype |
|
59 * |
|
60 * @param aSrc is the descriptor to be converted , aDes is the |
|
61 * reference to the string to which the result of conversion |
|
62 * is stored , |
|
63 * @return Status code (0 is ESuccess, -1 is EInsufficientMemory |
|
64 * -4 is EDescriptorNoData) |
|
65 */ |
|
66 |
|
67 EXPORT_C int Tbufc8ToString(TDesC8& aSrc, string& aDes) |
|
68 { |
|
69 unsigned int ilen = aSrc.Length(); |
|
70 if(0 == ilen) |
|
71 { |
|
72 return EDescriptorNoData; |
|
73 } |
|
74 |
|
75 char* charString = new char[ilen +1]; |
|
76 if (!charString) |
|
77 { |
|
78 return EInsufficientSystemMemory; |
|
79 } |
|
80 |
|
81 memcpy(charString, (char*)aSrc.Ptr(), ilen); |
|
82 charString[ilen] = '\0'; |
|
83 |
|
84 aDes.assign(charString); |
|
85 |
|
86 delete []charString; |
|
87 return ESuccess; |
|
88 } |
|
89 |
|
90 /** |
|
91 * Converts a descriptor of type TPtr8 to string datatype |
|
92 * |
|
93 * @param aSrc is the descriptor to be converted , aDes is the |
|
94 * reference to the string to which the result of conversion |
|
95 * is stored , |
|
96 * @return Status code (0 is ESuccess, -1 is EInsufficientMemory |
|
97 * -4 is EDescriptorNoData) |
|
98 */ |
|
99 |
|
100 EXPORT_C int Tptr8ToString (TDes8& aSrc, string& aDes) |
|
101 { |
|
102 unsigned int ilen = aSrc.Length(); |
|
103 if(0 == ilen ) |
|
104 { |
|
105 return EDescriptorNoData; |
|
106 } |
|
107 |
|
108 char* charString = new char[ilen +1]; |
|
109 |
|
110 if (!charString) |
|
111 { |
|
112 return EInsufficientSystemMemory; |
|
113 } |
|
114 |
|
115 memcpy(charString, (char*)aSrc.Ptr(), ilen); |
|
116 charString[ilen] = '\0'; |
|
117 |
|
118 aDes.assign (charString); |
|
119 |
|
120 delete []charString; |
|
121 |
|
122 return ESuccess; |
|
123 } |
|
124 |
|
125 /** |
|
126 * Converts a descriptor of type TPtrC8 to string datatype |
|
127 * |
|
128 * @param aSrc is the descriptor to be converted , aDes is the |
|
129 * reference to the string to which the result of conversion |
|
130 * is stored , |
|
131 * @return Status code (0 is ESuccess, -1 is EInsufficientMemory |
|
132 * -4 is EDescriptorNoData) |
|
133 */ |
|
134 |
|
135 EXPORT_C int Tptrc8ToString (const TDesC8& aSrc, string& aDes) |
|
136 { |
|
137 unsigned int ilen = aSrc.Length(); |
|
138 if (0 == ilen) |
|
139 { |
|
140 return EDescriptorNoData; |
|
141 } |
|
142 |
|
143 char* charString = new char[ilen +1]; |
|
144 if(!charString) |
|
145 { |
|
146 return EInsufficientSystemMemory; |
|
147 } |
|
148 |
|
149 memcpy(charString, (char*)aSrc.Ptr(), ilen); |
|
150 charString[ilen] = '\0'; |
|
151 |
|
152 aDes.assign(charString); |
|
153 |
|
154 delete []charString; |
|
155 return ESuccess; |
|
156 } |
|
157 |
|
158 /** |
|
159 * Converts a descriptor of type HBufC8 to string datatype |
|
160 * |
|
161 * @param aSrc is the descriptor to be converted , aDes is the |
|
162 * reference to the string to which the result of conversion |
|
163 * is stored , n_size specifies the conversion size of the string |
|
164 * @return Status code (0 is ESuccess, -2 is EInvalidSize |
|
165 * -4 is EInvalidPointer) |
|
166 */ |
|
167 |
|
168 EXPORT_C int Hbufc8ToString(HBufC8* aSrc, string& aDes) |
|
169 { |
|
170 unsigned int ilen = 0; |
|
171 if(!aSrc) |
|
172 { |
|
173 return EInvalidPointer; |
|
174 } |
|
175 else |
|
176 { |
|
177 ilen = aSrc->Length(); |
|
178 if ( 0 == ilen) |
|
179 { |
|
180 return EDescriptorNoData; |
|
181 } |
|
182 |
|
183 } |
|
184 |
|
185 char* charString = new char[ilen +1]; |
|
186 if(!charString) |
|
187 { |
|
188 return EInsufficientSystemMemory; |
|
189 } |
|
190 |
|
191 memcpy(charString, (char*)aSrc->Ptr(), ilen); |
|
192 charString[ilen] = '\0'; |
|
193 |
|
194 aDes.assign(charString); |
|
195 delete[] charString; |
|
196 return ESuccess; |
|
197 } |
|
198 |
|
199 /** |
|
200 * Converts a descriptor of type RBuf8 to string datatype |
|
201 * |
|
202 * @param aSrc is the descriptor to be converted , aDes is the |
|
203 * reference to the string to which the result of conversion |
|
204 * is stored , n_size specifies the conversion size of the string |
|
205 * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, |
|
206 * -5 is EDescriptorNoData) |
|
207 */ |
|
208 |
|
209 EXPORT_C int Rbuf8ToString(TDes8& aSrc, string& aDes) |
|
210 { |
|
211 unsigned int ilen = aSrc.Length(); |
|
212 if (0 == ilen) |
|
213 { |
|
214 return EDescriptorNoData; |
|
215 } |
|
216 |
|
217 char* buf = new char [ilen+1]; |
|
218 if (!buf) |
|
219 { |
|
220 return EInsufficientSystemMemory; |
|
221 } |
|
222 |
|
223 memcpy (buf,(char *)aSrc.Ptr(), ilen); |
|
224 buf[ilen]='\0'; |
|
225 |
|
226 aDes.assign(buf); |
|
227 |
|
228 delete []buf; |
|
229 return ESuccess; |
|
230 } |
|
231 |
|
232 /** |
|
233 * Converts a descriptor of type TLit8 to string datatype |
|
234 * |
|
235 * @param aSrc is the descriptor to be converted , aDes is the |
|
236 * reference to the string to which the result of conversion |
|
237 * is stored , n_size specifies the conversion size of the string |
|
238 * @return Status code (0 is ESuccess, -5 is EDescriptorNoData) |
|
239 */ |
|
240 |
|
241 EXPORT_C int Tlit8ToString(const TDesC8& aSrc, string& aDes) |
|
242 { |
|
243 unsigned int ilen = aSrc.Length(); |
|
244 |
|
245 if (0 == ilen) |
|
246 { |
|
247 return EDescriptorNoData; |
|
248 } |
|
249 |
|
250 char* buf = new char [ilen+1]; |
|
251 if (!buf) |
|
252 { |
|
253 return EInsufficientSystemMemory; |
|
254 } |
|
255 |
|
256 memcpy (buf,(char *)aSrc.Ptr(), ilen); |
|
257 buf[ilen]='\0'; |
|
258 |
|
259 aDes.assign(buf); |
|
260 delete [] buf; |
|
261 |
|
262 return ESuccess; |
|
263 } |