gdiplus: In GdipImageSelectActiveFrame rely on codec->select_func() to fail.
[wine.git] / dlls / comctl32 / string.c
blob9a6257dafe163a94605f6034201004fa50faf876
1 /*
2 * String manipulation functions
4 * Copyright 1998 Eric Kohl
5 * 1998 Juergen Schmied <j.schmied@metronet.de>
6 * 2000 Eric Kohl for CodeWeavers
7 * Copyright 2002 Jon Griffiths
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.
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.
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
25 #include <stdarg.h>
26 #include <string.h>
27 #include <stdlib.h> /* atoi */
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "winnls.h"
34 #include "comctl32.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(commctrl);
39 /**************************************************************************
40 * Str_GetPtrA [COMCTL32.233]
42 * Copies a string into a destination buffer.
44 * PARAMS
45 * lpSrc [I] Source string
46 * lpDest [O] Destination buffer
47 * nMaxLen [I] Size of buffer in characters
49 * RETURNS
50 * The number of characters copied.
52 INT WINAPI Str_GetPtrA (LPCSTR lpSrc, LPSTR lpDest, INT nMaxLen)
54 INT len;
56 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
58 if ((!lpDest || nMaxLen == 0) && lpSrc)
59 return (strlen(lpSrc) + 1);
61 if (nMaxLen == 0)
62 return 0;
64 if (lpSrc == NULL) {
65 lpDest[0] = '\0';
66 return 0;
69 len = strlen(lpSrc) + 1;
70 if (len >= nMaxLen)
71 len = nMaxLen;
73 RtlMoveMemory (lpDest, lpSrc, len - 1);
74 lpDest[len - 1] = '\0';
76 return len;
79 /**************************************************************************
80 * Str_SetPtrA [COMCTL32.234]
82 * Makes a copy of a string, allocating memory if necessary.
84 * PARAMS
85 * lppDest [O] Pointer to destination string
86 * lpSrc [I] Source string
88 * RETURNS
89 * Success: TRUE
90 * Failure: FALSE
92 * NOTES
93 * Set lpSrc to NULL to free the memory allocated by a previous call
94 * to this function.
96 BOOL WINAPI Str_SetPtrA (LPSTR *lppDest, LPCSTR lpSrc)
98 TRACE("(%p %p)\n", lppDest, lpSrc);
100 if (lpSrc) {
101 LPSTR ptr = ReAlloc (*lppDest, strlen (lpSrc) + 1);
102 if (!ptr)
103 return FALSE;
104 strcpy (ptr, lpSrc);
105 *lppDest = ptr;
107 else {
108 Free (*lppDest);
109 *lppDest = NULL;
112 return TRUE;
115 /**************************************************************************
116 * Str_GetPtrW [COMCTL32.235]
118 * See Str_GetPtrA.
120 INT WINAPI Str_GetPtrW (LPCWSTR lpSrc, LPWSTR lpDest, INT nMaxLen)
122 INT len;
124 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
126 if (!lpDest && lpSrc)
127 return lstrlenW (lpSrc);
129 if (nMaxLen == 0)
130 return 0;
132 if (lpSrc == NULL) {
133 lpDest[0] = '\0';
134 return 0;
137 len = lstrlenW (lpSrc);
138 if (len >= nMaxLen)
139 len = nMaxLen - 1;
141 RtlMoveMemory (lpDest, lpSrc, len*sizeof(WCHAR));
142 lpDest[len] = '\0';
144 return len;
147 /**************************************************************************
148 * Str_SetPtrW [COMCTL32.236]
150 * See Str_SetPtrA.
152 BOOL WINAPI Str_SetPtrW (LPWSTR *lppDest, LPCWSTR lpSrc)
154 TRACE("(%p %s)\n", lppDest, debugstr_w(lpSrc));
156 if (lpSrc) {
157 INT len = lstrlenW (lpSrc) + 1;
158 LPWSTR ptr = ReAlloc (*lppDest, len * sizeof(WCHAR));
159 if (!ptr)
160 return FALSE;
161 lstrcpyW (ptr, lpSrc);
162 *lppDest = ptr;
164 else {
165 Free (*lppDest);
166 *lppDest = NULL;
169 return TRUE;
172 /*************************************************************************
173 * IntlStrEqWorkerA [COMCTL32.376]
175 * Compare two strings.
177 * PARAMS
178 * bCase [I] Whether to compare case sensitively
179 * lpszStr [I] First string to compare
180 * lpszComp [I] Second string to compare
181 * iLen [I] Length to compare
183 * RETURNS
184 * TRUE If the strings are equal.
185 * FALSE Otherwise.
187 BOOL WINAPI IntlStrEqWorkerA(BOOL bCase, LPCSTR lpszStr, LPCSTR lpszComp,
188 int iLen)
190 DWORD dwFlags;
191 int iRet;
193 TRACE("(%d,%s,%s,%d)\n", bCase,
194 debugstr_a(lpszStr), debugstr_a(lpszComp), iLen);
196 /* FIXME: This flag is undocumented and unknown by our CompareString.
198 dwFlags = LOCALE_RETURN_GENITIVE_NAMES;
199 if (!bCase) dwFlags |= NORM_IGNORECASE;
201 iRet = CompareStringA(GetThreadLocale(),
202 dwFlags, lpszStr, iLen, lpszComp, iLen);
204 if (!iRet)
205 iRet = CompareStringA(2048, dwFlags, lpszStr, iLen, lpszComp, iLen);
207 return iRet == CSTR_EQUAL;
210 /*************************************************************************
211 * IntlStrEqWorkerW [COMCTL32.377]
213 * See IntlStrEqWorkerA.
215 BOOL WINAPI IntlStrEqWorkerW(BOOL bCase, LPCWSTR lpszStr, LPCWSTR lpszComp,
216 int iLen)
218 DWORD dwFlags;
219 int iRet;
221 TRACE("(%d,%s,%s,%d)\n", bCase,
222 debugstr_w(lpszStr),debugstr_w(lpszComp), iLen);
224 /* FIXME: This flag is undocumented and unknown by our CompareString.
226 dwFlags = LOCALE_RETURN_GENITIVE_NAMES;
227 if (!bCase) dwFlags |= NORM_IGNORECASE;
229 iRet = CompareStringW(GetThreadLocale(),
230 dwFlags, lpszStr, iLen, lpszComp, iLen);
232 if (!iRet)
233 iRet = CompareStringW(2048, dwFlags, lpszStr, iLen, lpszComp, iLen);
235 return iRet == CSTR_EQUAL;