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
27 #include <stdlib.h> /* atoi */
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.
45 * lpSrc [I] Source string
46 * lpDest [O] Destination buffer
47 * nMaxLen [I] Size of buffer in characters
50 * The number of characters copied.
52 INT WINAPI
Str_GetPtrA (LPCSTR lpSrc
, LPSTR lpDest
, INT nMaxLen
)
56 TRACE("(%p %p %d)\n", lpSrc
, lpDest
, nMaxLen
);
58 if ((!lpDest
|| nMaxLen
== 0) && lpSrc
)
59 return (strlen(lpSrc
) + 1);
69 len
= strlen(lpSrc
) + 1;
73 RtlMoveMemory (lpDest
, lpSrc
, len
- 1);
74 lpDest
[len
- 1] = '\0';
79 /**************************************************************************
80 * Str_SetPtrA [COMCTL32.234]
82 * Makes a copy of a string, allocating memory if necessary.
85 * lppDest [O] Pointer to destination string
86 * lpSrc [I] Source string
93 * Set lpSrc to NULL to free the memory allocated by a previous call
96 BOOL WINAPI
Str_SetPtrA (LPSTR
*lppDest
, LPCSTR lpSrc
)
98 TRACE("(%p %p)\n", lppDest
, lpSrc
);
101 LPSTR ptr
= ReAlloc (*lppDest
, strlen (lpSrc
) + 1);
115 /**************************************************************************
116 * Str_GetPtrW [COMCTL32.235]
120 INT WINAPI
Str_GetPtrW (LPCWSTR lpSrc
, LPWSTR lpDest
, INT nMaxLen
)
124 TRACE("(%p %p %d)\n", lpSrc
, lpDest
, nMaxLen
);
126 if (!lpDest
&& lpSrc
)
127 return lstrlenW (lpSrc
);
137 len
= lstrlenW (lpSrc
);
141 RtlMoveMemory (lpDest
, lpSrc
, len
*sizeof(WCHAR
));
147 /**************************************************************************
148 * Str_SetPtrW [COMCTL32.236]
152 BOOL WINAPI
Str_SetPtrW (LPWSTR
*lppDest
, LPCWSTR lpSrc
)
154 TRACE("(%p %s)\n", lppDest
, debugstr_w(lpSrc
));
157 INT len
= lstrlenW (lpSrc
) + 1;
158 LPWSTR ptr
= ReAlloc (*lppDest
, len
* sizeof(WCHAR
));
161 lstrcpyW (ptr
, lpSrc
);
172 /*************************************************************************
173 * IntlStrEqWorkerA [COMCTL32.376]
175 * Compare two strings.
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
184 * TRUE If the strings are equal.
187 BOOL WINAPI
IntlStrEqWorkerA(BOOL bCase
, LPCSTR lpszStr
, LPCSTR lpszComp
,
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
);
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
,
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
);
233 iRet
= CompareStringW(2048, dwFlags
, lpszStr
, iLen
, lpszComp
, iLen
);
235 return iRet
== CSTR_EQUAL
;