98 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, |
101 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, |
99 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, |
102 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, |
100 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, |
103 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, |
101 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d |
104 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d |
102 }; |
105 }; |
|
106 |
|
107 namespace Util |
|
108 { |
|
109 /** |
|
110 * Converts wide char (unicode) string to multibyte string |
|
111 * This interface is provided so that we can have different implementation |
|
112 * in windows and linux machine. |
|
113 * @param aSource string to be converted |
|
114 * @param aSourceLen Source len. If this is -1 then it will calculate the length of the source. |
|
115 * @param aTarget target location. |
|
116 * @param aTargetLen Space in the target location. |
|
117 * @param aCodePage Code page number (currently supported in windows only) |
|
118 * @return Number of bytes that make up the converted part of multibyte sequence. |
|
119 * If aTarget is NULL then the function will return the size needed to store |
|
120 * the complete conversion of the source string. |
|
121 */ |
|
122 int ConvertWideCharToMultiByte(const wchar_t* aSource, int aSourceLen, char* aTarget, int aTargetLen, TUint32 aCodePage = 0); |
|
123 /** |
|
124 * Converts multibyte string to wide char (unicode) |
|
125 * This interface is provided so that we can have different implementation |
|
126 * in windows and linux machine. |
|
127 * @param aSource string to be converted |
|
128 * @param aSourceLen Source len. If this is -1 then it will calculate the length of the source. |
|
129 * @param aTarget target location. |
|
130 * @param aTargetLen Space in the target location. |
|
131 * @param aCodePage Code page number (currently supported in windows only) |
|
132 * @return Number of bytes that make up the converted part of widechar sequence. |
|
133 * If aTarget is NULL then the function will return the size needed to store |
|
134 * the complete conversion of the source string. |
|
135 */ |
|
136 int ConvertMultiByteToWideChar(const char* aSource, int aSourceLen, wchar_t* aTarget, int aTargetLen, TUint32 aCodePage = 0); |
|
137 }; // namespace Util |
103 |
138 |
104 |
139 |
105 DllExport std::string Util::wstring2string (const std::wstring& aWide) |
140 #ifdef __linux__ |
106 { |
141 int Util::ConvertWideCharToMultiByte(const wchar_t* aSource, int /*aSourceLen*/, char* aTarget, int aTargetLen, TUint32 /*aCodePage*/) |
107 int max = WideCharToMultiByte(CP_OEMCP,0,aWide.c_str(),aWide.length(),0,0,0,0); |
142 { |
108 std::string reply; |
143 int retValue = wcstombs(aTarget, aSource, aTargetLen); |
109 if (max > 0 ) |
144 if (-1 == retValue) |
110 { |
145 { |
111 char* buffer = new char [max]; |
146 return 0; |
112 try |
147 } |
113 { |
148 return retValue; |
114 WideCharToMultiByte(CP_OEMCP,0,aWide.c_str(),aWide.length(),buffer,max,0,0); |
149 } |
115 reply = std::string (buffer, max); |
150 |
116 } |
151 int Util::ConvertMultiByteToWideChar(const char* aSource, int /*aSourceLen*/, wchar_t* aTarget, int aTargetLen, TUint32 /*aCodePage*/) |
117 catch (...) |
152 { |
118 { |
153 int retValue = mbstowcs(aTarget, aSource, aTargetLen); |
119 } |
154 if (-1 == retValue) |
120 delete [] buffer; |
155 { |
121 } |
156 return 0; |
122 return reply; |
157 } |
123 } |
158 return retValue; |
124 |
159 } |
125 std::wstring Util::string2wstring (const std::string& aNarrow) |
160 |
126 { |
161 #else |
127 int max = MultiByteToWideChar(CP_OEMCP,0,aNarrow.c_str(),aNarrow.length(),0,0); |
162 |
|
163 int Util::ConvertWideCharToMultiByte(const wchar_t* aSource, int aSourceLen, char* aTarget, int aTargetLen, TUint32 aCodePage) |
|
164 { |
|
165 if(0 == aCodePage) |
|
166 { |
|
167 aCodePage = CP_OEMCP; |
|
168 } |
|
169 return WideCharToMultiByte( aCodePage, 0, aSource, aSourceLen, aTarget, aTargetLen, NULL, NULL); |
|
170 } |
|
171 |
|
172 int Util::ConvertMultiByteToWideChar(const char* aSource, int aSourceLen, wchar_t* aTarget, int aTargetLen, TUint32 aCodePage) |
|
173 { |
|
174 if(0 == aCodePage) |
|
175 { |
|
176 aCodePage = CP_OEMCP; |
|
177 } |
|
178 return MultiByteToWideChar( aCodePage, 0, aSource, aSourceLen, aTarget, aTargetLen); |
|
179 } |
|
180 |
|
181 #endif // __linux__ |
|
182 |
|
183 std::wstring Util::string2wstring (const char* aNarrow) |
|
184 { |
|
185 std::string narrowStr(aNarrow); |
|
186 int max = ConvertMultiByteToWideChar(aNarrow, strlen(aNarrow),0,0); |
128 std::wstring reply; |
187 std::wstring reply; |
129 if (max > 0 ) |
188 if (max > 0 ) |
130 { |
189 { |
131 wchar_t* buffer = new wchar_t [max]; |
190 wchar_t* buffer = new wchar_t [max]; |
132 try |
191 try |
133 { |
192 { |
134 MultiByteToWideChar(CP_OEMCP,0,aNarrow.c_str(),aNarrow.length(),buffer,max); |
193 ConvertMultiByteToWideChar(aNarrow, strlen(aNarrow),buffer,max); |
135 reply = std::wstring (buffer, max); |
194 reply = std::wstring (buffer, max); |
136 } |
195 } |
137 catch (...) |
196 catch (...) |
138 { |
197 { |
139 } |
198 } |
140 delete [] buffer; |
199 delete [] buffer; |
141 } |
200 } |
142 return reply; |
201 return reply; |
143 } |
202 } |
144 |
203 |
145 std::wstring Util::string2wstring (const char* aNarrow) |
|
146 { |
|
147 std::string narrowStr(aNarrow); |
|
148 int max = MultiByteToWideChar(CP_OEMCP,0,narrowStr.c_str(),narrowStr.length(),0,0); |
|
149 std::wstring reply; |
|
150 if (max > 0 ) |
|
151 { |
|
152 wchar_t* buffer = new wchar_t [max]; |
|
153 try |
|
154 { |
|
155 MultiByteToWideChar(CP_OEMCP,0,narrowStr.c_str(),narrowStr.length(),buffer,max); |
|
156 reply = std::wstring (buffer, max); |
|
157 } |
|
158 catch (...) |
|
159 { |
|
160 } |
|
161 delete [] buffer; |
|
162 } |
|
163 return reply; |
|
164 } |
|
165 |
204 |
166 DllExport int Util::WideCharToInteger(const wchar_t* aWideChar) |
205 DllExport int Util::WideCharToInteger(const wchar_t* aWideChar) |
167 { |
206 { |
168 unsigned long int value=0; |
207 unsigned long int value=0; |
169 std::wstringstream str(aWideChar); |
208 std::wstringstream str(aWideChar); |