ReactOS 0.4.16-dev-2279-gc890759
localeansi.c
Go to the documentation of this file.
1/*
2 * Locale support
3 *
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 David Lee Lambert
6 * Copyright 2000 Julio Cesar Gazquez
7 * Copyright 2002 Alexandre Julliard for CodeWeavers
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <k32.h>
25
26/*************************************************************************
27 * FoldStringA (KERNEL32.@)
28 *
29 * Map characters in a string.
30 *
31 * PARAMS
32 * dwFlags [I] Flags controlling chars to map (MAP_ constants from "winnls.h")
33 * src [I] String to map
34 * srclen [I] Length of src, or -1 if src is NUL terminated
35 * dst [O] Destination for mapped string
36 * dstlen [I] Length of dst, or 0 to find the required length for the mapped string
37 *
38 * RETURNS
39 * Success: The length of the string written to dst, including the terminating NUL. If
40 * dstlen is 0, the value returned is the same, but nothing is written to dst,
41 * and dst may be NULL.
42 * Failure: 0. Use GetLastError() to determine the cause.
43 */
46{
47 INT ret = 0, srclenW = 0;
48 WCHAR *srcW = NULL, *dstW = NULL;
49
50 if (!src || !srclen || dstlen < 0 || (dstlen && !dst) || src == dst)
51 {
53 return 0;
54 }
55
57 src, srclen, NULL, 0);
58 srcW = HeapAlloc(GetProcessHeap(), 0, srclenW * sizeof(WCHAR));
59
60 if (!srcW)
61 {
63 goto FoldStringA_exit;
64 }
65
67 src, srclen, srcW, srclenW);
68
69 dwFlags = (dwFlags & ~MAP_PRECOMPOSED) | MAP_FOLDCZONE;
70
71 ret = FoldStringW(dwFlags, srcW, srclenW, NULL, 0);
72 if (ret && dstlen)
73 {
74 dstW = HeapAlloc(GetProcessHeap(), 0, ret * sizeof(WCHAR));
75
76 if (!dstW)
77 {
79 goto FoldStringA_exit;
80 }
81
82 ret = FoldStringW(dwFlags, srcW, srclenW, dstW, ret);
83 if (!WideCharToMultiByte(CP_ACP, 0, dstW, ret, dst, dstlen, NULL, NULL))
84 {
85 ret = 0;
87 }
88 }
89
90 HeapFree(GetProcessHeap(), 0, dstW);
91
92FoldStringA_exit:
93 HeapFree(GetProcessHeap(), 0, srcW);
94 return ret;
95}
96
97/* EOF */
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:109
#define SetLastError(x)
Definition: compat.h:752
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define WideCharToMultiByte
Definition: compat.h:111
#define MultiByteToWideChar
Definition: compat.h:110
INT WINAPI FoldStringW(DWORD dwFlags, LPCWSTR src, INT srclen, LPWSTR dst, INT dstlen)
Definition: locale.c:3911
return ret
Definition: mutex.c:146
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
#define MB_COMPOSITE
Definition: unicode.h:40
INT WINAPI FoldStringA(DWORD dwFlags, LPCSTR src, INT srclen, LPSTR dst, INT dstlen)
Definition: localeansi.c:44
static DWORD LPDWORD LPCSTR DWORD srclen
Definition: directory.c:52
static DWORD dstlen
Definition: directory.c:51
_In_ LPWSTR _In_ DWORD _In_ DWORD _In_ DWORD dwFlags
Definition: netsh.h:141
int32_t INT
Definition: typedefs.h:58
#define WINAPI
Definition: msvc.h:6
#define MAP_COMPOSITE
Definition: winnls.h:234
#define MAP_FOLDCZONE
Definition: winnls.h:231
const char * LPCSTR
Definition: xmlstorage.h:183
__wchar_t WCHAR
Definition: xmlstorage.h:180
char * LPSTR
Definition: xmlstorage.h:182