|
1 /* |
|
2 * Copyright (c) 2005-2007 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: Source file for stringutils |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // GCCE header |
|
20 //#ifdef __GCCE__ |
|
21 //#include <staticlibinit_gcce.h> |
|
22 //#endif //__GCCE__ |
|
23 |
|
24 //System headers |
|
25 #include <string.h> |
|
26 #include <stdlib.h> |
|
27 |
|
28 //User-definied headers |
|
29 #include "stringutils.h" |
|
30 |
|
31 |
|
32 EXPORT_C wchar_t* tbuf16towchar(TDes& aArg) |
|
33 { |
|
34 return (wchar_t*)aArg.PtrZ(); |
|
35 } |
|
36 |
|
37 EXPORT_C char* tbuf8tochar(TDes8& aArg) |
|
38 { |
|
39 return (char*)aArg.PtrZ(); |
|
40 } |
|
41 |
|
42 EXPORT_C int tbuf16tochar(TDes& aSrc, char* aDes) |
|
43 { |
|
44 const TUint16 *wideString = aSrc.PtrZ(); |
|
45 |
|
46 TInt ret = wcstombs(aDes, (const wchar_t*)wideString, KMaxFileName ); |
|
47 |
|
48 return ret; |
|
49 } |
|
50 |
|
51 EXPORT_C int tbuf8towchar(TDes8& aSrc ,wchar_t* aDes) |
|
52 { |
|
53 const char *charString = (const char*)aSrc.PtrZ(); |
|
54 |
|
55 TInt ret = mbstowcs(aDes, charString, KMaxFileName ); |
|
56 |
|
57 return ret; |
|
58 } |
|
59 |
|
60 |
|
61 EXPORT_C void tbufC16towchar(TDesC& aSrc ,wchar_t *aDes) |
|
62 { |
|
63 wchar_t *temp = (wchar_t*)aSrc.Ptr(); |
|
64 const TInt size = aSrc.Size(); |
|
65 *(temp + size/2 ) = L'\0'; |
|
66 wcscpy(aDes, temp); |
|
67 } |
|
68 |
|
69 EXPORT_C void tbufC8tochar(TDesC8& aSrc, char* aDes) |
|
70 { |
|
71 char *temp = (char*)aSrc.Ptr(); |
|
72 const TInt size = aSrc.Length(); |
|
73 *(temp + size) = '\0'; |
|
74 strcpy(aDes, temp); |
|
75 } |
|
76 |
|
77 EXPORT_C int tbufC16tochar(TDesC& aSrc, char* aDes) |
|
78 { |
|
79 TUint16* wideString = (TUint16*)aSrc.Ptr(); |
|
80 const TInt size = aSrc.Length(); |
|
81 *(wideString + size) = L'\0'; |
|
82 |
|
83 |
|
84 TInt ret = wcstombs(aDes, (const wchar_t*)wideString, size*2 ); |
|
85 return ret; |
|
86 } |
|
87 |
|
88 |
|
89 EXPORT_C int tbufC8towchar(TDesC8& aSrc, wchar_t* aDes) |
|
90 { |
|
91 TUint8* charString = (TUint8*)aSrc.Ptr(); |
|
92 const TInt size = aSrc.Length(); |
|
93 *(charString + size) = '\0'; |
|
94 |
|
95 TInt ret = mbstowcs(aDes, (const char*)charString, KMaxFileName ); |
|
96 return ret; |
|
97 } |
|
98 |
|
99 EXPORT_C void wchartotbuf16(const wchar_t *aSrc, TDes16 &aDes) |
|
100 { |
|
101 aDes = (const TUint16*)aSrc; |
|
102 } |
|
103 |
|
104 EXPORT_C int chartotbuf16(const char *aSrc, TDes16 &aDes) |
|
105 { |
|
106 int len = strlen(aSrc); |
|
107 wchar_t *buf = new wchar_t[len]; |
|
108 |
|
109 TInt ret = mbstowcs(buf, (const char*)aSrc, len + 1 ); |
|
110 |
|
111 if( ret != -1) |
|
112 aDes = (const TUint16*)buf; |
|
113 |
|
114 delete buf; |
|
115 return ret; |
|
116 } |
|
117 |
|
118 EXPORT_C int wchartotbuf8(const wchar_t *aSrc, TDes8 &aDes) |
|
119 { |
|
120 int len = wcslen(aSrc); |
|
121 char *buf = new char[len]; |
|
122 |
|
123 TInt ret = wcstombs(buf, (const wchar_t*)aSrc, len + 1); |
|
124 |
|
125 if( ret != -1) |
|
126 aDes = (const TUint8*)buf; |
|
127 |
|
128 delete buf; |
|
129 return ret; |
|
130 } |
|
131 |
|
132 EXPORT_C void chartotbuf8 (const char *aSrc, TDes8 &aDes) |
|
133 { |
|
134 aDes = (const TUint8*)aSrc; |
|
135 } |
|
136 |
|
137 EXPORT_C void wchartohbufc16 (const wchar_t* aSrc ,HBufC16& aDes ) |
|
138 { |
|
139 aDes = (const TUint16*)aSrc; |
|
140 } |
|
141 |
|
142 EXPORT_C int chartohbufc16(const char* aSrc, HBufC16& aDes) |
|
143 { |
|
144 int len = strlen(aSrc); |
|
145 wchar_t *buf = new wchar_t[len]; |
|
146 |
|
147 TInt ret = mbstowcs(buf, (const char*)aSrc, len + 1); |
|
148 |
|
149 if( ret != -1) |
|
150 aDes = (const TUint16*)buf; |
|
151 |
|
152 delete buf; |
|
153 return ret; |
|
154 } |
|
155 |
|
156 EXPORT_C void chartohbufc8(const char* aSrc, HBufC8& aDes) |
|
157 { |
|
158 aDes = (const TUint8*)aSrc; |
|
159 } |
|
160 |
|
161 EXPORT_C int wchartohbufc8(const wchar_t* aSrc, HBufC8& aDes) |
|
162 { |
|
163 int len = wcslen(aSrc); |
|
164 char *buf = new char[len]; |
|
165 |
|
166 TInt ret = wcstombs(buf, aSrc, len + 1 ); |
|
167 |
|
168 if( ret != -1) |
|
169 aDes = (const TUint8*)buf; |
|
170 |
|
171 delete buf; |
|
172 return ret; |
|
173 } |
|
174 |
|
175 |
|
176 |
|
177 // End of file |