1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: StrConvert.h,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _STRCONVERT_H_
31 #define _STRCONVERT_H_
36 #define STRCONVERT_H_HAD_NDEBUG
39 #if OSL_DEBUG_LEVEL == 0
48 int AllocNecessarySpaceAndCopyWStr2Str( LPCWSTR lpcwstrString
, LPSTR
* lppStr
);
49 int AllocSpaceAndCopyWStr2Str( LPCWSTR lpcwstrString
, DWORD nWCharsToCopy
, LPSTR
* lppStr
);
50 int CalcLenDblNullTerminatedWStr( LPCWSTR lpcwstrString
);
51 int CalcLenDblNullTerminatedStr( LPCSTR lpcstrString
);
52 void FreeSpaceStr( LPSTR lpszString
);
54 /* WC2MB allocates a sufficient amount of memory on stack and converts
55 the wide char parameter to multi byte string using the actual code
58 @Param: wcStr - a wide char string
59 mbStr - the corresponding multi byte string
61 NOTE: due to the use of _alloca, this must be a macro and no function
64 #define WC2MB( wcStr, mbStr ) \
67 int needed = WideCharToMultiByte( CP_ACP, 0, wcStr, -1, NULL, 0, NULL, NULL ); \
71 mbStr = _alloca( needed * sizeof( CHAR ) ); \
72 copied = WideCharToMultiByte( CP_ACP, 0, wcStr, -1, mbStr, needed, NULL, NULL ); \
73 assert( copied == needed ); \
78 /* WideCharListGetMultiByteLength
79 calculates the needed length of a corresponding the multi byte string
80 list for a wide char string list.
82 @Param: cp - the code page to use for convertion.
83 wcList - a double '\0' terminated wide char string list.
86 int WideCharListGetMultiByteLength( UINT codepage
, LPCWSTR wcList
);
88 /* WideCharListToMultiByteList
89 converts a double '\0' terminated list of wide char strings to a
90 multi byte string list.
92 @Param: cp - the code page to use for convertion.
93 wcList - a double '\0' terminated wide char string list.
94 mbList - a double '\0' terminated multi byte string list.
95 dwSize - size of buffer for multi byte string list.
98 int WideCharListToMultiByteList( UINT codepage
, LPCWSTR wcList
, LPSTR mbList
, DWORD dwSize
);
101 /* WCL2MBL allocates a sufficient amount of memory on stack and converts
102 the wide char list parameter to multi byte string list using the actual
105 @Param: wcList - a wide char string list
106 mbList - the corresponding multi byte string list
108 NOTE: due to the use of _alloca, this must be a macro and no function
111 #define WCL2MBL( wcList, mbList ) \
114 int needed = WideCharListGetMultiByteLength( CP_ACP, wcList ); \
118 mbList = _alloca( needed * sizeof( CHAR ) ); \
119 copied = WideCharListToMultiByteList( CP_ACP, wcList, mbList, needed ); \
120 assert( copied == needed ); \
128 // Restore NDEBUG state
129 #ifdef STRCONVERT_H_HAD_NDEBUG