source: trunk/src/shlwapi/string_odin.cpp

Last change on this file was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

File size: 8.9 KB
RevLine 
[8584]1 /* $Id: string_odin.cpp,v 1.8 2002-06-07 08:02:20 sandervl Exp $ */
[7820]2
[4081]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>
[21916]35#ifndef __GNUC__
[4081]36#include <wcstr.h>
[21916]37#else
38#include <wchar.h>
39#endif
[4081]40#define HAVE_WCTYPE_H
41
42#include "debugtools.h"
43
44#include <winreg.h>
45
46#include <heapstring.h>
47#include <misc.h>
[21916]48#include <win/shell.h>
49#include <win/winerror.h>
[4081]50#include <winversion.h>
51#include <winuser.h>
52
[21494]53#define CINTERFACE
[4081]54
55#include "winerror.h"
56#include "winnls.h"
57#include "winversion.h"
58#include "heap.h"
59
60#include "shellapi.h"
61#include "shlobj.h"
62
63#include "shlwapi_odin.h"
64#include "shlwapi.h"
65
66/*****************************************************************************
67 * Local Variables *
68 *****************************************************************************/
69
70ODINDEBUGCHANNEL(SHLWAPI-STRING)
71
72
73
74
75/*****************************************************************************
76 * Name : StrChrIA
77 * Purpose : Searches a string for the first occurrence of a character that
78 * matches the specified character. The comparison is not case sensitive.
79 * Parameters: LPCSTR lpStart Address of the string to be searched.
80 * TCHAR wMatch Character to be used for comparison.
81 * Variables :
82 * Result : Returns the address of the first occurrence of the character in
83 * the string if successful, or NULL otherwise.
84 * Remark : SHELL32.
85 * Status : COMPLETELY IMPLEMENTED UNTESTED UNKNOWN
86 *
87 * Author : Patrick Haller [Wed, 1999/12/29 09:00]
88 *****************************************************************************/
89
90ODINFUNCTION2(LPSTR, StrChrIA,
91 LPCSTR, lpStart,
[7820]92 char, cMatch)
[4081]93{
94 LPSTR lpRes;
95
[7820]96 cMatch = tolower(cMatch);
97 lpRes = strchr(lpStart, cMatch); // lower case comparsion
[4081]98 if (NULL == lpRes)
99 {
[7820]100 cMatch = toupper(cMatch);
101 lpRes = strchr(lpStart, cMatch); // upper case comparsion
[4081]102 }
103
104 return lpRes;
105}
106
107
108/*****************************************************************************
109 * Name : StrChrIW
110 * Purpose : Searches a string for the first occurrence of a character that
111 * matches the specified character. The comparison is not case sensitive.
112 * Parameters: LPCSTR lpStart Address of the string to be searched.
113 * TCHAR wMatch Character to be used for comparison.
114 * Variables :
115 * Result : Returns the address of the first occurrence of the character in
116 * the string if successful, or NULL otherwise.
117 * Remark : SHELL32.
118 * Status : COMPLETELY IMPLEMENTED UNTESTED UNKNOWN
119 *
120 * Author : Patrick Haller [Wed, 1999/12/29 09:00]
121 *****************************************************************************/
122
123ODINFUNCTION2(LPWSTR, StrChrIW,
124 LPCWSTR, lpStart,
125 WCHAR, wMatch)
126{
127 LPWSTR lpRes;
128
129 wMatch = towlower(wMatch);
130 lpRes = (WCHAR*)wcschr((const wchar_t*)lpStart, wMatch); // lower case comparsion
131 if (NULL == lpRes)
132 {
133 wMatch = towupper(wMatch);
134 lpRes = (WCHAR*)wcschr((const wchar_t*)lpStart, wMatch); // upper case comparsion
135 }
136
137 return lpRes;
138}
139
[7838]140#if 0
[4081]141/*****************************************************************************
142 * Name : StrCpyA
143 * Purpose : copy a string
144 * Parameters:
145 * Variables :
146 * Result :
147 * Remark : not exported ?
148 * Status : UNTESTED
149 *
150 * Author :
151 *****************************************************************************/
152
153ODINFUNCTIONNODBG2(LPSTR, StrCpyA,
154 LPSTR, lpDest,
155 LPCSTR, lpSource)
156{
157 return lstrcpyA(lpDest,
158 lpSource);
159}
[7838]160#endif
[4081]161
[6608]162/*****************************************************************************
163 * Name : StrSpnA
164 * Purpose : find the first occurence of a character in string1
165 * that is not contained in the set of characters specified by
166 * string2.
167 * Parameters:
168 * Variables :
169 * Result :
170 * Remark : COMCTL32undoc.StrSpnW, CRTDLL.strspn
171 * Status : UNTESTED
172 *
173 * Author :
174 *****************************************************************************/
[4081]175
[6608]176ODINFUNCTION2(INT, StrSpnA,
177 LPCSTR, lpString1,
178 LPCSTR, lpString2)
179{
180 // 2001-08-30 PH
181 // copied from implementation in COMCTL32
182 if ( (lpString1 == NULL) ||
183 (lpString2 == NULL) )
184 return 0;
[21916]185
[6608]186 LPSTR lpLoop = (LPSTR)lpString1;
[21916]187
[6608]188 for (; (*lpLoop != 0); lpLoop++ )
189 if ( StrChrA( lpString2, *lpLoop ) )
190 return (INT) (lpLoop - lpString1);
[21916]191
[6608]192 return (INT) (lpLoop - lpString1);
193}
[4081]194
[6608]195
196/*****************************************************************************
197 * Name : StrSpnW
198 * Purpose : find the first occurence of a character in string1
199 * that is not contained in the set of characters specified by
200 * string2.
201 * Parameters:
202 * Variables :
203 * Result :
204 * Remark : COMCTL32undoc.StrSpnW, CRTDLL.strspn
205 * Status : UNTESTED
206 *
207 * Author :
208 *****************************************************************************/
209
210ODINFUNCTION2(INT, StrSpnW,
211 LPCWSTR, lpString1,
212 LPCWSTR, lpString2)
213{
214 // 2001-08-30 PH
215 // copied from implementation in COMCTL32
216 if ( (lpString1 == NULL) ||
217 (lpString2 == NULL) )
218 return 0;
[21916]219
[6608]220 LPWSTR lpLoop = (LPWSTR)lpString1;
[21916]221
[6608]222 for (; (*lpLoop != 0); lpLoop++ )
223 if ( StrChrW( lpString2, *lpLoop ) )
224 return (INT) (lpLoop - lpString1);
[21916]225
[6608]226 return (INT) (lpLoop - lpString1);
227}
228
229
230/*****************************************************************************
231 * Name : StrPBrkA
232 * Purpose : find the first occurence in string1 of any character from string2
233 * Parameters:
234 * Variables :
235 * Result :
[21916]236 * Remark :
[6608]237 * Status : UNTESTED
238 *
239 * Author :
240 *****************************************************************************/
241
242ODINFUNCTION2(LPSTR, StrPBrkA,
243 LPCSTR, lpString1,
244 LPCSTR, lpString2)
245{
246 register LPSTR s1;
[21916]247
[6608]248 while (*lpString1)
249 {
250 for (s1 = (LPSTR)lpString2;
251 *s1 && *s1 != *lpString1;
252 s1++)
253 /* empty */
254 ;
255
256 if (*s1)
257 return (LPSTR)lpString1;
258
259 lpString1++;
260 }
[21916]261
[6608]262 return (LPSTR)NULL;
263}
264
265
266/*****************************************************************************
267 * Name : StrPBrkW
268 * Purpose : find the first occurence in string1 of any character from string2
269 * Parameters:
270 * Variables :
271 * Result :
[21916]272 * Remark :
[6608]273 * Status : UNTESTED
274 *
275 * Author :
276 *****************************************************************************/
277
278ODINFUNCTION2(LPWSTR, StrPBrkW,
279 LPCWSTR, lpString1,
280 LPCWSTR, lpString2)
281{
282 register LPWSTR s1;
[21916]283
[6608]284 while (*lpString1)
285 {
286 for (s1 = (LPWSTR)lpString2;
287 *s1 && *s1 != *lpString1;
288 s1++)
289 /* empty */
290 ;
291
292 if (*s1)
293 return (LPWSTR)lpString1;
294
295 lpString1++;
296 }
[21916]297
[6608]298 return (LPWSTR)NULL;
299}
300
301
302/*************************************************************************
[7820]303 * StrRStrIA [SHLWAPI]
[6608]304 */
[7820]305LPSTR WINAPI StrRStrIA(LPCSTR lpFirst, LPCSTR lpSrch, LPCSTR unknown)
[6608]306{
307 INT iLen = lstrlenA(lpFirst) - lstrlenA(lpSrch);
[6650]308
[7820]309 dprintf(("StrRStrIA %x %x %x NOT IMPLEMENTED correctly", lpFirst, lpSrch, unknown));
[21916]310
[6608]311 // lpSrch cannot fit into lpFirst
312 if (iLen < 0)
313 return (LPSTR)NULL;
[21916]314
[6608]315 LPSTR lpThis = (LPSTR)lpFirst + iLen;
[21916]316
[6608]317 while (lpThis >= lpFirst)
318 {
319 LPCSTR p1 = lpThis, p2 = lpSrch;
320 while (*p1 && *p2 && toupper(*p1) == toupper(*p2)) { p1++; p2++; }
321 if (!*p2) return (LPSTR)lpThis;
322 lpThis--;
323 }
[21916]324
[6608]325 return NULL;
326}
327
328
329/*************************************************************************
[7820]330 * StrRStrIW [SHLWAPI]
[6608]331 */
[7820]332LPWSTR WINAPI StrRStrIW(LPCWSTR lpFirst, LPCWSTR lpSrch, LPCWSTR unknown)
[6608]333{
334 INT iLen = lstrlenW(lpFirst) - lstrlenW(lpSrch);
[6650]335
[7820]336 dprintf(("StrRStrIA %x %x %x NOT IMPLEMENTED correctly", lpFirst, lpSrch, unknown));
[21916]337
[6608]338 // lpSrch cannot fit into lpFirst
339 if (iLen < 0)
340 return (LPWSTR)NULL;
[21916]341
[6608]342 LPWSTR lpThis = (LPWSTR)lpFirst + iLen;
[21916]343
[6608]344 while (lpThis >= lpFirst)
345 {
346 LPCWSTR p1 = lpThis, p2 = lpSrch;
347 while (*p1 && *p2 && toupperW(*p1) == toupperW(*p2)) { p1++; p2++; }
348 if (!*p2) return (LPWSTR)lpThis;
349 lpThis--;
350 }
[21916]351
[6608]352 return NULL;
353}
Note: See TracBrowser for help on using the repository browser.