source: trunk/src/shlwapi/string.cpp@ 3562

Last change on this file since 3562 was 3562, checked in by sandervl, 25 years ago

added stubs, fixed export ordinals

File size: 15.9 KB
Line 
1/* $Id: string.cpp,v 1.2 2000-05-19 12:10:04 sandervl Exp $ */
2
3/*
4 * Win32 Lightweight SHELL32 for OS/2
5 *
6 * Copyright 1997 Marcus Meissner
7 * Copyright 1999 Patrick Haller (haller@zebra.fh-weingarten.de)
8 * Project Odin Software License can be found in LICENSE.TXT
9 *
10 * Path Functions
11 *
12 * Many of this functions are in SHLWAPI.DLL also
13 *
14 * Corel WINE 20000324 level (without CRTDLL_* calls)
15 */
16
17/*****************************************************************************
18 * Remark *
19 *****************************************************************************
20
21 */
22
23
24/*****************************************************************************
25 * Includes *
26 *****************************************************************************/
27
28#include <odin.h>
29#include <odinwrap.h>
30#include <os2sel.h>
31
32#include <string.h>
33#include <ctype.h>
34#include <wctype.h>
35#include <wcstr.h>
36#define HAVE_WCTYPE_H
37
38#include "debugtools.h"
39
40#include <winreg.h>
41
42#include <heapstring.h>
43#include <misc.h>
44#include <win\shell.h>
45#include <win\winerror.h>
46#include <winversion.h>
47#include <winuser.h>
48
49
50#define ICOM_CINTERFACE 1
51#define CINTERFACE 1
52
53#include "winerror.h"
54#include "winnls.h"
55#include "winversion.h"
56#include "heap.h"
57
58#include "shellapi.h"
59#include "shlobj.h"
60#include "wine/undocshell.h"
61
62#include "shlwapi.h"
63
64/*****************************************************************************
65 * Local Variables *
66 *****************************************************************************/
67
68ODINDEBUGCHANNEL(SHLWAPI-STRING)
69
70
71
72/*************************************************************************
73 * OleStrToStrN [SHELL32.78]
74 */
75BOOL WINAPI OleStrToStrNA (LPSTR lpStr, INT nStr, LPCWSTR lpOle, INT nOle)
76{
77 TRACE("%p %x %s %x\n", lpStr, nStr, debugstr_w(lpOle), nOle);
78 return WideCharToMultiByte (0, 0, lpOle, nOle, lpStr, nStr, NULL, NULL);
79}
80
81BOOL WINAPI OleStrToStrNW (LPWSTR lpwStr, INT nwStr, LPCWSTR lpOle, INT nOle)
82{
83 TRACE("%p %x %s %x\n", lpwStr, nwStr, debugstr_w(lpOle), nOle);
84
85 if (lstrcpynW ( lpwStr, lpOle, nwStr))
86 { return lstrlenW (lpwStr);
87 }
88 return 0;
89}
90
91BOOL WINAPI OleStrToStrNAW (LPVOID lpOut, INT nOut, LPCVOID lpIn, INT nIn)
92{
93 if (VERSION_OsIsUnicode())
94 return OleStrToStrNW ((LPWSTR)lpOut, nOut, (LPCWSTR)lpIn, nIn);
95 return OleStrToStrNA ((LPSTR)lpOut, nOut, (LPCWSTR)lpIn, nIn);
96}
97
98/*************************************************************************
99 * StrToOleStrN [SHELL32.79]
100 * lpMulti, nMulti, nWide [IN]
101 * lpWide [OUT]
102 */
103BOOL WINAPI StrToOleStrNA (LPWSTR lpWide, INT nWide, LPCSTR lpStrA, INT nStr)
104{
105 TRACE("%p %x %s %x\n", lpWide, nWide, lpStrA, nStr);
106 return MultiByteToWideChar (0, 0, lpStrA, nStr, lpWide, nWide);
107}
108BOOL WINAPI StrToOleStrNW (LPWSTR lpWide, INT nWide, LPCWSTR lpStrW, INT nStr)
109{
110 TRACE("%p %x %s %x\n", lpWide, nWide, debugstr_w(lpStrW), nStr);
111
112 if (lstrcpynW (lpWide, lpStrW, nWide))
113 { return lstrlenW (lpWide);
114 }
115 return 0;
116}
117
118BOOL WINAPI StrToOleStrNAW (LPWSTR lpWide, INT nWide, LPCVOID lpStr, INT nStr)
119{
120 if (VERSION_OsIsUnicode())
121 return StrToOleStrNW (lpWide, nWide, (LPWSTR)lpStr, nStr);
122 return StrToOleStrNA (lpWide, nWide, (LPSTR)lpStr, nStr);
123}
124
125
126/*************************************************************************
127 * StrRetToStrN [SHELL32.96]
128 *
129 * converts a STRRET to a normal string
130 *
131 * NOTES
132 * the pidl is for STRRET OFFSET
133 */
134HRESULT WINAPI StrRetToBufA (LPSTRRET src, LPITEMIDLIST pidl, LPSTR dest, DWORD len)
135{
136 return StrRetToStrNA(dest, len, src, pidl);
137}
138
139HRESULT WINAPI StrRetToStrNA (LPVOID dest, DWORD len, LPSTRRET src, LPITEMIDLIST pidl)
140{
141 TRACE("dest=0x%p len=0x%lx strret=0x%p pidl=%p stub\n",dest,len,src,pidl);
142
143 switch (src->uType)
144 {
145 case STRRET_WSTR:
146 WideCharToMultiByte(CP_ACP, 0, src->u.pOleStr, -1, (LPSTR)dest, len, NULL, NULL);
147 SHFree(src->u.pOleStr);
148 break;
149
150 case STRRET_CSTRA:
151 lstrcpynA((LPSTR)dest, src->u.cStr, len);
152 break;
153
154 case STRRET_OFFSETA:
155 lstrcpynA((LPSTR)dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len);
156 break;
157
158 default:
159 FIXME("unknown type!\n");
160 if (len)
161 {
162 *(LPSTR)dest = '\0';
163 }
164 return(FALSE);
165 }
166 return S_OK;
167}
168
169HRESULT WINAPI StrRetToBufW (LPSTRRET src, LPITEMIDLIST pidl, LPWSTR dest, DWORD len)
170{
171 return StrRetToStrNW(dest, len, src, pidl);
172}
173
174HRESULT WINAPI StrRetToStrNW (LPVOID dest, DWORD len, LPSTRRET src, LPITEMIDLIST pidl)
175{
176 TRACE("dest=0x%p len=0x%lx strret=0x%p pidl=%p stub\n",dest,len,src,pidl);
177
178 switch (src->uType)
179 {
180 case STRRET_WSTR:
181 lstrcpynW((LPWSTR)dest, src->u.pOleStr, len);
182 SHFree(src->u.pOleStr);
183 break;
184
185 case STRRET_CSTRA:
186 lstrcpynAtoW((LPWSTR)dest, src->u.cStr, len);
187 break;
188
189 case STRRET_OFFSETA:
190 if (pidl)
191 {
192 lstrcpynAtoW((LPWSTR)dest, ((LPSTR)&pidl->mkid)+src->u.uOffset, len);
193 }
194 break;
195
196 default:
197 FIXME("unknown type!\n");
198 if (len)
199 { *(LPSTR)dest = '\0';
200 }
201 return(FALSE);
202 }
203 return S_OK;
204}
205HRESULT WINAPI StrRetToStrNAW (LPVOID dest, DWORD len, LPSTRRET src, LPITEMIDLIST pidl)
206{
207 if(VERSION_OsIsUnicode())
208 return StrRetToStrNW (dest, len, src, pidl);
209 return StrRetToStrNA (dest, len, src, pidl);
210}
211
212/*************************************************************************
213 * StrChrA [NT 4.0:SHELL32.651]
214 *
215 */
216LPSTR WINAPI StrChrA (LPSTR str, CHAR x )
217{ LPSTR ptr=str;
218
219 do
220 { if (*ptr==x)
221 { return ptr;
222 }
223 ptr++;
224 } while (*ptr);
225 return NULL;
226}
227
228/*************************************************************************
229 * StrChrW [NT 4.0:SHELL32.651]
230 *
231 */
232LPWSTR WINAPI StrChrW (LPWSTR str, WCHAR x )
233{ LPWSTR ptr=str;
234
235 TRACE("%s 0x%04x\n",debugstr_w(str),x);
236 do
237 { if (*ptr==x)
238 { return ptr;
239 }
240 ptr++;
241 } while (*ptr);
242 return NULL;
243}
244
245/*************************************************************************
246 * StrCmpNIW [NT 4.0:SHELL32.*]
247 *
248 */
249INT WINAPI StrCmpNIW ( LPWSTR wstr1, LPWSTR wstr2, INT len)
250{ FIXME("%s %s %i stub\n", debugstr_w(wstr1),debugstr_w(wstr2),len);
251 return 0;
252}
253
254/*************************************************************************
255 * StrCmpNIA [NT 4.0:SHELL32.*]
256 *
257 */
258INT WINAPI StrCmpNIA ( LPSTR wstr1, LPSTR wstr2, INT len)
259{ FIXME("%s %s %i stub\n", wstr1,wstr2,len);
260 return 0;
261}
262
263
264/*************************************************************************
265 * StrRChrA [SHELL32.346]
266 *
267 */
268LPSTR WINAPI StrRChrA(LPCSTR lpStart, LPCSTR lpEnd, DWORD wMatch)
269{
270 if (!lpStart)
271 return NULL;
272
273 /* if the end not given, search*/
274 if (!lpEnd)
275 { lpEnd=lpStart;
276 while (*lpEnd)
277 lpEnd++;
278 }
279
280 for (--lpEnd;lpStart <= lpEnd; lpEnd--)
281 if (*lpEnd==(char)wMatch)
282 return (LPSTR)lpEnd;
283
284 return NULL;
285}
286/*************************************************************************
287 * StrRChrW [SHELL32.320]
288 *
289 */
290LPWSTR WINAPI StrRChrW(LPWSTR lpStart, LPWSTR lpEnd, DWORD wMatch)
291{ LPWSTR wptr=NULL;
292 TRACE("%s %s 0x%04x\n",debugstr_w(lpStart),debugstr_w(lpEnd), (WCHAR)wMatch );
293
294 /* if the end not given, search*/
295 if (!lpEnd)
296 { lpEnd=lpStart;
297 while (*lpEnd)
298 lpEnd++;
299 }
300
301 do
302 { if (*lpStart==(WCHAR)wMatch)
303 wptr = lpStart;
304 lpStart++;
305 } while ( lpStart<=lpEnd );
306 return wptr;
307}
308
309/************************************************************************
310 * StrToOleStr [SHELL32.163]
311 *
312 */
313int WINAPI StrToOleStrA (LPWSTR lpWideCharStr, LPCSTR lpMultiByteString)
314{
315 TRACE("%p %p(%s)\n",
316 lpWideCharStr, lpMultiByteString, lpMultiByteString);
317
318 return MultiByteToWideChar(0, 0, lpMultiByteString, -1, lpWideCharStr, MAX_PATH);
319
320}
321int WINAPI StrToOleStrW (LPWSTR lpWideCharStr, LPCWSTR lpWString)
322{
323 TRACE("%p %p(%s)\n",
324 lpWideCharStr, lpWString, debugstr_w(lpWString));
325
326 if (lstrcpyW (lpWideCharStr, lpWString ))
327 { return lstrlenW (lpWideCharStr);
328 }
329 return 0;
330}
331
332BOOL WINAPI StrToOleStrAW (LPWSTR lpWideCharStr, LPCVOID lpString)
333{
334 if (VERSION_OsIsUnicode())
335 return StrToOleStrW (lpWideCharStr, (LPCWSTR)lpString);
336 return StrToOleStrA (lpWideCharStr, (LPCSTR)lpString);
337}
338
339
340
341/*****************************************************************************
342 * Name : StrChrIA
343 * Purpose : Searches a string for the first occurrence of a character that
344 * matches the specified character. The comparison is not case sensitive.
345 * Parameters: LPCSTR lpStart Address of the string to be searched.
346 * TCHAR wMatch Character to be used for comparison.
347 * Variables :
348 * Result : Returns the address of the first occurrence of the character in
349 * the string if successful, or NULL otherwise.
350 * Remark : SHELL32.
351 * Status : UNTESTED UNKNOWN
352 *
353 * Author : Patrick Haller [Wed, 1999/12/29 09:00]
354 *****************************************************************************/
355
356ODINFUNCTION2(LPSTR, StrChrIA,
357 LPCSTR, lpStart,
358 CHAR, wMatch)
359{
360 LPSTR lpRes;
361
362 wMatch = tolower(wMatch);
363 lpRes = strchr(lpStart, wMatch); // lower case comparsion
364 if (NULL == lpRes)
365 {
366 wMatch = toupper(wMatch);
367 lpRes = strchr(lpStart, wMatch); // upper case comparsion
368 }
369
370 return lpRes;
371}
372
373
374/*****************************************************************************
375 * Name : StrChrIW
376 * Purpose : Searches a string for the first occurrence of a character that
377 * matches the specified character. The comparison is not case sensitive.
378 * Parameters: LPCSTR lpStart Address of the string to be searched.
379 * TCHAR wMatch Character to be used for comparison.
380 * Variables :
381 * Result : Returns the address of the first occurrence of the character in
382 * the string if successful, or NULL otherwise.
383 * Remark : SHELL32.
384 * Status : UNTESTED UNKNOWN
385 *
386 * Author : Patrick Haller [Wed, 1999/12/29 09:00]
387 *****************************************************************************/
388
389ODINFUNCTION2(LPWSTR, StrChrIW,
390 LPCWSTR, lpStart,
391 WCHAR, wMatch)
392{
393 LPWSTR lpRes;
394
395 wMatch = towlower(wMatch);
396 lpRes = (WCHAR*)wcschr((const wchar_t*)lpStart, wMatch); // lower case comparsion
397 if (NULL == lpRes)
398 {
399 wMatch = towupper(wMatch);
400 lpRes = (WCHAR*)wcschr((const wchar_t*)lpStart, wMatch); // upper case comparsion
401 }
402
403 return lpRes;
404}
405
406
407/*****************************************************************************
408 * Name : StrStrIA
409 * Purpose : Finds the first occurrence of a substring within a string. The
410 * comparison is not case sensitive.
411 * Parameters: LPCSTR lpFirst
412 * LPCSTR lpSrch
413 * Variables :
414 * Result : Returns the address of the first occurrence of the matching
415 * substring if successful, or NULL otherwise.
416 * Remark : SHELL32.
417 * Status : UNTESTED UNKNOWN
418 *
419 * Author : Patrick Haller [Wed, 1999/12/29 09:00]
420 *****************************************************************************/
421
422ODINFUNCTION2(LPSTR, StrStrIA,
423 LPCSTR, lpFirst,
424 LPCSTR, lpSrch)
425{
426 char ch = lpSrch[0]; // look for 1st character
427 LONG lLen = lstrlenA(lpSrch); // length of search string
428 int iRes; // comparsion result
429
430 do
431 {
432 lpFirst = StrChrIA(lpFirst, // find first matching character
433 ch);
434 if (NULL == lpFirst) // not found
435 return NULL;
436
437 iRes = StrCmpNIA((LPSTR)lpFirst, // compare search string
438 (LPSTR)lpSrch,
439 lLen);
440
441 if (0 == iRes) // Found!
442 return (LPSTR)lpFirst;
443
444 lpFirst = CharNextA(lpFirst); // skip to next character
445 }
446 while (*lpFirst != 0); // safe termination
447
448 return NULL; // default result
449}
450
451
452
453/*****************************************************************************
454 * Name : StrStrIW
455 * Purpose : Finds the first occurrence of a substring within a string. The
456 * comparison is not case sensitive.
457 * Parameters: LPCWSTR lpFirst
458 * LPCWSTR lpSrch
459 * Variables :
460 * Result : Returns the address of the first occurrence of the matching
461 * substring if successful, or NULL otherwise.
462 * Remark : SHELL32.
463 * Status : UNTESTED UNKNOWN
464 *
465 * Author : Patrick Haller [Wed, 1999/12/29 09:00]
466 *****************************************************************************/
467
468ODINFUNCTION2(LPWSTR, StrStrIW,
469 LPCWSTR, lpFirst,
470 LPCWSTR, lpSrch)
471{
472 WCHAR ch = lpSrch[0]; // look for 1st character
473 LONG lLen = lstrlenW(lpSrch); // length of search string
474 int iRes; // comparsion result
475
476 do
477 {
478 lpFirst = StrChrIW(lpFirst, // find first matching character
479 ch);
480 if (NULL == lpFirst) // not found
481 return NULL;
482
483 iRes = StrCmpNIW((LPWSTR)lpFirst, // compare search string
484 (LPWSTR)lpSrch,
485 lLen);
486
487 if (0 == iRes) // Found!
488 return (LPWSTR)lpFirst;
489
490 lpFirst = CharNextW(lpFirst); // skip to next character
491 }
492 while (*lpFirst != 0); // safe termination
493
494 return NULL; // default result
495}
496
497
498
499/*****************************************************************************
500 * Name : StrToIntA
501 * Purpose : convert string to integer (used by explorer.exe)
502 * Parameters: Unknown (wrong)
503 * Variables :
504 * Result : Unknown
505 * Remark :
506 * Status : UNTESTED STUB
507 *
508 * Author : Christoph Bratschi [Wed, 2000/03/29 19:47]
509 *****************************************************************************/
510
511ODINFUNCTION1(INT,StrToIntA,LPSTR,pszPath)
512{
513 dprintf(("not implemented"));
514
515 return NULL;
516}
517
518/*************************************************************************
519 * StrFormatByteSizeA [SHLWAPI]
520 */
521ODINFUNCTION3(LPSTR, StrFormatByteSizeA, DWORD, dw, LPSTR, pszBuf, UINT, cchBuf )
522{ char buf[64];
523 TRACE("%lx %p %i\n", dw, pszBuf, cchBuf);
524 if ( dw<1024L )
525 { sprintf (buf,"%3.1f bytes", (FLOAT)dw);
526 }
527 else if ( dw<1048576L)
528 { sprintf (buf,"%3.1f KB", (FLOAT)dw/1024);
529 }
530 else if ( dw < 1073741824L)
531 { sprintf (buf,"%3.1f MB", (FLOAT)dw/1048576L);
532 }
533 else
534 { sprintf (buf,"%3.1f GB", (FLOAT)dw/1073741824L);
535 }
536 lstrcpynA (pszBuf, buf, cchBuf);
537 return pszBuf;
538}
539
540/*************************************************************************
541 * StrFormatByteSizeW [SHLWAPI]
542 */
543ODINFUNCTION3(LPWSTR, StrFormatByteSizeW, DWORD, dw, LPWSTR, pszBuf, UINT, cchBuf)
544{ char buf[64];
545 TRACE("%lx %p %i\n", dw, pszBuf, cchBuf);
546 if ( dw<1024L )
547 { sprintf (buf,"%3.1f bytes", (FLOAT)dw);
548 }
549 else if ( dw<1048576L)
550 { sprintf (buf,"%3.1f KB", (FLOAT)dw/1024);
551 }
552 else if ( dw < 1073741824L)
553 { sprintf (buf,"%3.1f MB", (FLOAT)dw/1048576L);
554 }
555 else
556 { sprintf (buf,"%3.1f GB", (FLOAT)dw/1073741824L);
557 }
558 lstrcpynAtoW (pszBuf, buf, cchBuf);
559 return pszBuf;
560}
Note: See TracBrowser for help on using the repository browser.