source: trunk/src/shlwapi/string_odin.cpp@ 6650

Last change on this file since 6650 was 6650, checked in by bird, 24 years ago

Added $Id:$ keyword.

File size: 12.0 KB
Line 
1/* $Id: string_odin.cpp,v 1.5 2001-09-05 13:48:39 bird Exp $ */
2/*
3 * Win32 Lightweight SHELL32 for OS/2
4 *
5 * Copyright 1997 Marcus Meissner
6 * Copyright 1999 Patrick Haller (haller@zebra.fh-weingarten.de)
7 * Project Odin Software License can be found in LICENSE.TXT
8 *
9 * Path Functions
10 *
11 * Many of this functions are in SHLWAPI.DLL also
12 *
13 * Corel WINE 20000324 level (without CRTDLL_* calls)
14 */
15
16/*****************************************************************************
17 * Remark *
18 *****************************************************************************
19
20 */
21
22
23/*****************************************************************************
24 * Includes *
25 *****************************************************************************/
26
27#include <odin.h>
28#include <odinwrap.h>
29#include <os2sel.h>
30
31#include <string.h>
32#include <ctype.h>
33#include <wctype.h>
34#include <wcstr.h>
35#define HAVE_WCTYPE_H
36
37#include "debugtools.h"
38
39#include <winreg.h>
40
41#include <heapstring.h>
42#include <misc.h>
43#include <win\shell.h>
44#include <win\winerror.h>
45#include <winversion.h>
46#include <winuser.h>
47
48
49#define ICOM_CINTERFACE 1
50#define CINTERFACE 1
51
52#include "winerror.h"
53#include "winnls.h"
54#include "winversion.h"
55#include "heap.h"
56
57#include "shellapi.h"
58#include "shlobj.h"
59#include "wine/undocshell.h"
60
61#include "shlwapi_odin.h"
62#include "shlwapi.h"
63
64/*****************************************************************************
65 * Local Variables *
66 *****************************************************************************/
67
68ODINDEBUGCHANNEL(SHLWAPI-STRING)
69
70
71/*****************************************************************************
72 * Name : ChrCmpIA
73 * Purpose :
74 * Parameters:
75 * Variables :
76 * Result :
77 * Remark :
78 * Status : PARTIALLY IMPLEMENTED UNTESTED
79 *
80 * Author : Patrick Haller [Wed, 1999/12/29 09:00]
81 *****************************************************************************/
82
83ODINFUNCTION2(INT, ChrCmpIA,
84 INT, ch1,
85 INT, ch2)
86{
87 // Note: IsDBCSLeadByte ignored !
88
89 if ( (ch1 >= 'A') && (ch1 <= 'Z') ) ch1 |= 0x20;
90 if ( (ch2 >= 'A') && (ch2 <= 'Z') ) ch2 |= 0x20;
91
92 return ch1 - ch2;
93}
94
95
96#if 0
97/*************************************************************************
98 * OleStrToStrN [SHELL32.78]
99 */
100BOOL WINAPI OleStrToStrNA (LPSTR lpStr, INT nStr, LPCWSTR lpOle, INT nOle)
101{
102 TRACE("%p %x %s %x\n", lpStr, nStr, debugstr_w(lpOle), nOle);
103 return WideCharToMultiByte (0, 0, lpOle, nOle, lpStr, nStr, NULL, NULL);
104}
105
106BOOL WINAPI OleStrToStrNW (LPWSTR lpwStr, INT nwStr, LPCWSTR lpOle, INT nOle)
107{
108 TRACE("%p %x %s %x\n", lpwStr, nwStr, debugstr_w(lpOle), nOle);
109
110 if (lstrcpynW ( lpwStr, lpOle, nwStr))
111 { return lstrlenW (lpwStr);
112 }
113 return 0;
114}
115
116BOOL WINAPI OleStrToStrNAW (LPVOID lpOut, INT nOut, LPCVOID lpIn, INT nIn)
117{
118 if (VERSION_OsIsUnicode())
119 return OleStrToStrNW ((LPWSTR)lpOut, nOut, (LPCWSTR)lpIn, nIn);
120 return OleStrToStrNA ((LPSTR)lpOut, nOut, (LPCWSTR)lpIn, nIn);
121}
122
123/*************************************************************************
124 * StrToOleStrN [SHELL32.79]
125 * lpMulti, nMulti, nWide [IN]
126 * lpWide [OUT]
127 */
128BOOL WINAPI StrToOleStrNA (LPWSTR lpWide, INT nWide, LPCSTR lpStrA, INT nStr)
129{
130 TRACE("%p %x %s %x\n", lpWide, nWide, lpStrA, nStr);
131 return MultiByteToWideChar (0, 0, lpStrA, nStr, lpWide, nWide);
132}
133BOOL WINAPI StrToOleStrNW (LPWSTR lpWide, INT nWide, LPCWSTR lpStrW, INT nStr)
134{
135 TRACE("%p %x %s %x\n", lpWide, nWide, debugstr_w(lpStrW), nStr);
136
137 if (lstrcpynW (lpWide, lpStrW, nWide))
138 { return lstrlenW (lpWide);
139 }
140 return 0;
141}
142
143BOOL WINAPI StrToOleStrNAW (LPWSTR lpWide, INT nWide, LPCVOID lpStr, INT nStr)
144{
145 if (VERSION_OsIsUnicode())
146 return StrToOleStrNW (lpWide, nWide, (LPWSTR)lpStr, nStr);
147 return StrToOleStrNA (lpWide, nWide, (LPSTR)lpStr, nStr);
148}
149
150
151
152
153/************************************************************************
154 * StrToOleStr [SHELL32.163]
155 *
156 */
157int WINAPI StrToOleStrA (LPWSTR lpWideCharStr, LPCSTR lpMultiByteString)
158{
159 TRACE("%p %p(%s)\n",
160 lpWideCharStr, lpMultiByteString, lpMultiByteString);
161
162 return MultiByteToWideChar(0, 0, lpMultiByteString, -1, lpWideCharStr, MAX_PATH);
163
164}
165int WINAPI StrToOleStrW (LPWSTR lpWideCharStr, LPCWSTR lpWString)
166{
167 TRACE("%p %p(%s)\n",
168 lpWideCharStr, lpWString, debugstr_w(lpWString));
169
170 if (lstrcpyW (lpWideCharStr, lpWString ))
171 { return lstrlenW (lpWideCharStr);
172 }
173 return 0;
174}
175
176BOOL WINAPI StrToOleStrAW (LPWSTR lpWideCharStr, LPCVOID lpString)
177{
178 if (VERSION_OsIsUnicode())
179 return StrToOleStrW (lpWideCharStr, (LPCWSTR)lpString);
180 return StrToOleStrA (lpWideCharStr, (LPCSTR)lpString);
181}
182#endif
183
184
185/*****************************************************************************
186 * Name : StrChrIA
187 * Purpose : Searches a string for the first occurrence of a character that
188 * matches the specified character. The comparison is not case sensitive.
189 * Parameters: LPCSTR lpStart Address of the string to be searched.
190 * TCHAR wMatch Character to be used for comparison.
191 * Variables :
192 * Result : Returns the address of the first occurrence of the character in
193 * the string if successful, or NULL otherwise.
194 * Remark : SHELL32.
195 * Status : COMPLETELY IMPLEMENTED UNTESTED UNKNOWN
196 *
197 * Author : Patrick Haller [Wed, 1999/12/29 09:00]
198 *****************************************************************************/
199
200ODINFUNCTION2(LPSTR, StrChrIA,
201 LPCSTR, lpStart,
202 WORD, wMatch)
203{
204 LPSTR lpRes;
205
206 wMatch = tolower(wMatch);
207 lpRes = strchr(lpStart, wMatch); // lower case comparsion
208 if (NULL == lpRes)
209 {
210 wMatch = toupper(wMatch);
211 lpRes = strchr(lpStart, wMatch); // upper case comparsion
212 }
213
214 return lpRes;
215}
216
217
218/*****************************************************************************
219 * Name : StrChrIW
220 * Purpose : Searches a string for the first occurrence of a character that
221 * matches the specified character. The comparison is not case sensitive.
222 * Parameters: LPCSTR lpStart Address of the string to be searched.
223 * TCHAR wMatch Character to be used for comparison.
224 * Variables :
225 * Result : Returns the address of the first occurrence of the character in
226 * the string if successful, or NULL otherwise.
227 * Remark : SHELL32.
228 * Status : COMPLETELY IMPLEMENTED UNTESTED UNKNOWN
229 *
230 * Author : Patrick Haller [Wed, 1999/12/29 09:00]
231 *****************************************************************************/
232
233ODINFUNCTION2(LPWSTR, StrChrIW,
234 LPCWSTR, lpStart,
235 WCHAR, wMatch)
236{
237 LPWSTR lpRes;
238
239 wMatch = towlower(wMatch);
240 lpRes = (WCHAR*)wcschr((const wchar_t*)lpStart, wMatch); // lower case comparsion
241 if (NULL == lpRes)
242 {
243 wMatch = towupper(wMatch);
244 lpRes = (WCHAR*)wcschr((const wchar_t*)lpStart, wMatch); // upper case comparsion
245 }
246
247 return lpRes;
248}
249
250
251/*****************************************************************************
252 * Name : StrCpyA
253 * Purpose : copy a string
254 * Parameters:
255 * Variables :
256 * Result :
257 * Remark : not exported ?
258 * Status : UNTESTED
259 *
260 * Author :
261 *****************************************************************************/
262
263ODINFUNCTIONNODBG2(LPSTR, StrCpyA,
264 LPSTR, lpDest,
265 LPCSTR, lpSource)
266{
267 return lstrcpyA(lpDest,
268 lpSource);
269}
270
271
272/*****************************************************************************
273 * Name : StrSpnA
274 * Purpose : find the first occurence of a character in string1
275 * that is not contained in the set of characters specified by
276 * string2.
277 * Parameters:
278 * Variables :
279 * Result :
280 * Remark : COMCTL32undoc.StrSpnW, CRTDLL.strspn
281 * Status : UNTESTED
282 *
283 * Author :
284 *****************************************************************************/
285
286ODINFUNCTION2(INT, StrSpnA,
287 LPCSTR, lpString1,
288 LPCSTR, lpString2)
289{
290 // 2001-08-30 PH
291 // copied from implementation in COMCTL32
292 if ( (lpString1 == NULL) ||
293 (lpString2 == NULL) )
294 return 0;
295
296 LPSTR lpLoop = (LPSTR)lpString1;
297
298 for (; (*lpLoop != 0); lpLoop++ )
299 if ( StrChrA( lpString2, *lpLoop ) )
300 return (INT) (lpLoop - lpString1);
301
302 return (INT) (lpLoop - lpString1);
303}
304
305
306/*****************************************************************************
307 * Name : StrSpnW
308 * Purpose : find the first occurence of a character in string1
309 * that is not contained in the set of characters specified by
310 * string2.
311 * Parameters:
312 * Variables :
313 * Result :
314 * Remark : COMCTL32undoc.StrSpnW, CRTDLL.strspn
315 * Status : UNTESTED
316 *
317 * Author :
318 *****************************************************************************/
319
320ODINFUNCTION2(INT, StrSpnW,
321 LPCWSTR, lpString1,
322 LPCWSTR, lpString2)
323{
324 // 2001-08-30 PH
325 // copied from implementation in COMCTL32
326 if ( (lpString1 == NULL) ||
327 (lpString2 == NULL) )
328 return 0;
329
330 LPWSTR lpLoop = (LPWSTR)lpString1;
331
332 for (; (*lpLoop != 0); lpLoop++ )
333 if ( StrChrW( lpString2, *lpLoop ) )
334 return (INT) (lpLoop - lpString1);
335
336 return (INT) (lpLoop - lpString1);
337}
338
339
340/*****************************************************************************
341 * Name : StrPBrkA
342 * Purpose : find the first occurence in string1 of any character from string2
343 * Parameters:
344 * Variables :
345 * Result :
346 * Remark :
347 * Status : UNTESTED
348 *
349 * Author :
350 *****************************************************************************/
351
352ODINFUNCTION2(LPSTR, StrPBrkA,
353 LPCSTR, lpString1,
354 LPCSTR, lpString2)
355{
356 register LPSTR s1;
357
358 while (*lpString1)
359 {
360 for (s1 = (LPSTR)lpString2;
361 *s1 && *s1 != *lpString1;
362 s1++)
363 /* empty */
364 ;
365
366 if (*s1)
367 return (LPSTR)lpString1;
368
369 lpString1++;
370 }
371
372 return (LPSTR)NULL;
373}
374
375
376/*****************************************************************************
377 * Name : StrPBrkW
378 * Purpose : find the first occurence in string1 of any character from string2
379 * Parameters:
380 * Variables :
381 * Result :
382 * Remark :
383 * Status : UNTESTED
384 *
385 * Author :
386 *****************************************************************************/
387
388ODINFUNCTION2(LPWSTR, StrPBrkW,
389 LPCWSTR, lpString1,
390 LPCWSTR, lpString2)
391{
392 register LPWSTR s1;
393
394 while (*lpString1)
395 {
396 for (s1 = (LPWSTR)lpString2;
397 *s1 && *s1 != *lpString1;
398 s1++)
399 /* empty */
400 ;
401
402 if (*s1)
403 return (LPWSTR)lpString1;
404
405 lpString1++;
406 }
407
408 return (LPWSTR)NULL;
409}
410
411
412/*************************************************************************
413 * StrRStrIA [SHLWAPI]
414 */
415LPSTR WINAPI StrRStrIA(LPCSTR lpFirst, LPCSTR lpSrch)
416{
417 INT iLen = lstrlenA(lpFirst) - lstrlenA(lpSrch);
418
419 // lpSrch cannot fit into lpFirst
420 if (iLen < 0)
421 return (LPSTR)NULL;
422
423 LPSTR lpThis = (LPSTR)lpFirst + iLen;
424
425 while (lpThis >= lpFirst)
426 {
427 LPCSTR p1 = lpThis, p2 = lpSrch;
428 while (*p1 && *p2 && toupper(*p1) == toupper(*p2)) { p1++; p2++; }
429 if (!*p2) return (LPSTR)lpThis;
430 lpThis--;
431 }
432
433 return NULL;
434}
435
436
437/*************************************************************************
438 * StrRStrIW [SHLWAPI]
439 */
440LPWSTR WINAPI StrRStrIW(LPCWSTR lpFirst, LPCWSTR lpSrch)
441{
442 INT iLen = lstrlenW(lpFirst) - lstrlenW(lpSrch);
443
444 // lpSrch cannot fit into lpFirst
445 if (iLen < 0)
446 return (LPWSTR)NULL;
447
448 LPWSTR lpThis = (LPWSTR)lpFirst + iLen;
449
450 while (lpThis >= lpFirst)
451 {
452 LPCWSTR p1 = lpThis, p2 = lpSrch;
453 while (*p1 && *p2 && toupperW(*p1) == toupperW(*p2)) { p1++; p2++; }
454 if (!*p2) return (LPWSTR)lpThis;
455 lpThis--;
456 }
457
458 return NULL;
459}
Note: See TracBrowser for help on using the repository browser.