1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "stringconverter.hxx"
29 
30 #ifdef _MSC_VER
31 #pragma warning(push, 1) /* disable warnings within system headers */
32 #endif
33 #include <windows.h>
34 #ifdef _MSC_VER
35 #pragma warning(pop)
36 #endif
37 
38 #include <malloc.h>
39 
40 /** Convert a Unicode string to an ANSI string based on CP_ACP
41 */
42 std::string UnicodeToAnsiString(const std::wstring& UniString)
43 {
44     int len = WideCharToMultiByte(
45 		CP_ACP, 0, UniString.c_str(), -1, 0, 0, 0, 0);
46 
47 	char* buff = reinterpret_cast<char*>(_alloca(len));
48 
49 	WideCharToMultiByte(
50 		CP_ACP, 0, UniString.c_str(), -1, buff, len, 0, 0);
51 
52 	return std::string(buff);
53 }
54 
55 /** Convert an ANSI string to unicode based on CP_ACP
56 */
57 std::wstring AnsiToUnicodeString(const std::string& AnsiString)
58 {
59     int len = MultiByteToWideChar(
60 		CP_ACP, 0, AnsiString.c_str(), -1, 0, 0);
61 
62 	wchar_t* buff = reinterpret_cast<wchar_t*>(_alloca(len * sizeof(wchar_t)));
63 
64 	MultiByteToWideChar(
65 		CP_ACP, 0, AnsiString.c_str(), -1, buff, len);
66 
67 	return std::wstring(buff);
68 }
69 
70 
71