2 * Shlwapi string functions
4 * Copyright 1998 Juergen Schmied
5 * Copyright 2002 Jon Griffiths
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
30 #define NONAMELESSUNION
31 #define NONAMELESSSTRUCT
34 #define NO_SHLWAPI_REG
35 #define NO_SHLWAPI_STREAM
42 #include "wine/unicode.h"
43 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
49 extern HINSTANCE shlwapi_hInstance
;
51 static HRESULT
_SHStrDupAA(LPCSTR
,LPSTR
*);
52 static HRESULT
_SHStrDupAW(LPCWSTR
,LPSTR
*);
55 static void FillNumberFmt(NUMBERFMTW
*fmt
, LPWSTR decimal_buffer
, int decimal_bufwlen
,
56 LPWSTR thousand_buffer
, int thousand_bufwlen
)
61 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_ILZERO
|LOCALE_RETURN_NUMBER
, (LPWSTR
)&fmt
->LeadingZero
, sizeof(fmt
->LeadingZero
)/sizeof(WCHAR
));
62 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_INEGNUMBER
|LOCALE_RETURN_NUMBER
, (LPWSTR
)&fmt
->LeadingZero
, sizeof(fmt
->NegativeOrder
)/sizeof(WCHAR
));
64 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDECIMAL
, decimal_buffer
, decimal_bufwlen
);
65 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_STHOUSAND
, thousand_buffer
, thousand_bufwlen
);
66 fmt
->lpThousandSep
= thousand_buffer
;
67 fmt
->lpDecimalSep
= decimal_buffer
;
70 * Converting grouping string to number as described on
71 * http://blogs.msdn.com/oldnewthing/archive/2006/04/18/578251.aspx
74 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SGROUPING
, grouping
, sizeof(grouping
)/sizeof(WCHAR
));
75 for (c
= grouping
; *c
; c
++)
76 if (*c
>= '0' && *c
< '9')
79 fmt
->Grouping
+= *c
- '0';
82 if (fmt
->Grouping
% 10 == 0)
88 /*************************************************************************
89 * FormatInt [internal]
91 * Format an integer according to the current locale
94 * The number of bytes written on success or 0 on failure
96 static int FormatInt(LONGLONG qdwValue
, LPWSTR pszBuf
, int cchBuf
)
99 WCHAR decimal
[8], thousand
[8];
102 BOOL neg
= (qdwValue
< 0);
104 FillNumberFmt(&fmt
, decimal
, sizeof decimal
/ sizeof (WCHAR
),
105 thousand
, sizeof thousand
/ sizeof (WCHAR
));
111 *(--c
) = '0' + (qdwValue
%10);
113 } while (qdwValue
> 0);
117 return GetNumberFormatW(LOCALE_USER_DEFAULT
, 0, c
, &fmt
, pszBuf
, cchBuf
);
120 /*************************************************************************
121 * FormatDouble [internal]
123 * Format an integer according to the current locale. Prints the specified number of digits
124 * after the decimal point
127 * The number of bytes written on success or 0 on failure
129 static int FormatDouble(double value
, int decimals
, LPWSTR pszBuf
, int cchBuf
)
131 static const WCHAR flfmt
[] = {'%','f',0};
134 WCHAR decimal
[8], thousand
[8];
136 snprintfW(buf
, 64, flfmt
, value
);
138 FillNumberFmt(&fmt
, decimal
, sizeof decimal
/ sizeof (WCHAR
),
139 thousand
, sizeof thousand
/ sizeof (WCHAR
));
140 fmt
.NumDigits
= decimals
;
141 return GetNumberFormatW(LOCALE_USER_DEFAULT
, 0, buf
, &fmt
, pszBuf
, cchBuf
);
144 /*************************************************************************
145 * SHLWAPI_ChrCmpHelperA
147 * Internal helper for SHLWAPI_ChrCmpA/ChrCMPIA.
150 * Both this function and its Unicode counterpart are very inefficient. To
151 * fix this, CompareString must be completely implemented and optimised
152 * first. Then the core character test can be taken out of that function and
153 * placed here, so that it need never be called at all. Until then, do not
154 * attempt to optimise this code unless you are willing to test that it
155 * still performs correctly.
157 static BOOL
SHLWAPI_ChrCmpHelperA(WORD ch1
, WORD ch2
, DWORD dwFlags
)
159 char str1
[3], str2
[3];
161 str1
[0] = LOBYTE(ch1
);
162 if (IsDBCSLeadByte(str1
[0]))
164 str1
[1] = HIBYTE(ch1
);
170 str2
[0] = LOBYTE(ch2
);
171 if (IsDBCSLeadByte(str2
[0]))
173 str2
[1] = HIBYTE(ch2
);
179 return CompareStringA(GetThreadLocale(), dwFlags
, str1
, -1, str2
, -1) - 2;
182 /*************************************************************************
185 * Internal helper function.
187 static BOOL WINAPI
SHLWAPI_ChrCmpA(WORD ch1
, WORD ch2
)
189 return SHLWAPI_ChrCmpHelperA(ch1
, ch2
, 0);
192 /*************************************************************************
193 * ChrCmpIA (SHLWAPI.385)
195 * Compare two characters, ignoring case.
198 * ch1 [I] First character to compare
199 * ch2 [I] Second character to compare
202 * FALSE, if the characters are equal.
203 * Non-zero otherwise.
205 BOOL WINAPI
ChrCmpIA(WORD ch1
, WORD ch2
)
207 TRACE("(%d,%d)\n", ch1
, ch2
);
209 return SHLWAPI_ChrCmpHelperA(ch1
, ch2
, NORM_IGNORECASE
);
212 /*************************************************************************
213 * ChrCmpIW [SHLWAPI.386]
217 BOOL WINAPI
ChrCmpIW(WCHAR ch1
, WCHAR ch2
)
219 return CompareStringW(GetThreadLocale(), NORM_IGNORECASE
, &ch1
, 1, &ch2
, 1) - 2;
222 /*************************************************************************
223 * StrChrA [SHLWAPI.@]
225 * Find a given character in a string.
228 * lpszStr [I] String to search in.
229 * ch [I] Character to search for.
232 * Success: A pointer to the first occurrence of ch in lpszStr, or NULL if
234 * Failure: NULL, if any arguments are invalid.
236 LPSTR WINAPI
StrChrA(LPCSTR lpszStr
, WORD ch
)
238 TRACE("(%s,%i)\n", debugstr_a(lpszStr
), ch
);
244 if (!SHLWAPI_ChrCmpA(*lpszStr
, ch
))
245 return (LPSTR
)lpszStr
;
246 lpszStr
= CharNextA(lpszStr
);
252 /*************************************************************************
253 * StrChrW [SHLWAPI.@]
257 LPWSTR WINAPI
StrChrW(LPCWSTR lpszStr
, WCHAR ch
)
259 LPWSTR lpszRet
= NULL
;
261 TRACE("(%s,%i)\n", debugstr_w(lpszStr
), ch
);
264 lpszRet
= strchrW(lpszStr
, ch
);
268 /*************************************************************************
269 * StrChrIA [SHLWAPI.@]
271 * Find a given character in a string, ignoring case.
274 * lpszStr [I] String to search in.
275 * ch [I] Character to search for.
278 * Success: A pointer to the first occurrence of ch in lpszStr, or NULL if
280 * Failure: NULL, if any arguments are invalid.
282 LPSTR WINAPI
StrChrIA(LPCSTR lpszStr
, WORD ch
)
284 TRACE("(%s,%i)\n", debugstr_a(lpszStr
), ch
);
290 if (!ChrCmpIA(*lpszStr
, ch
))
291 return (LPSTR
)lpszStr
;
292 lpszStr
= CharNextA(lpszStr
);
298 /*************************************************************************
299 * StrChrIW [SHLWAPI.@]
303 LPWSTR WINAPI
StrChrIW(LPCWSTR lpszStr
, WCHAR ch
)
305 TRACE("(%s,%i)\n", debugstr_w(lpszStr
), ch
);
312 if (toupperW(*lpszStr
) == ch
)
313 return (LPWSTR
)lpszStr
;
318 return (LPWSTR
)lpszStr
;
321 /*************************************************************************
322 * StrCmpIW [SHLWAPI.@]
324 * Compare two strings, ignoring case.
327 * lpszStr [I] First string to compare
328 * lpszComp [I] Second string to compare
331 * An integer less than, equal to or greater than 0, indicating that
332 * lpszStr is less than, the same, or greater than lpszComp.
334 int WINAPI
StrCmpIW(LPCWSTR lpszStr
, LPCWSTR lpszComp
)
338 TRACE("(%s,%s)\n", debugstr_w(lpszStr
),debugstr_w(lpszComp
));
340 iRet
= CompareStringW(GetThreadLocale(), NORM_IGNORECASE
, lpszStr
, -1, lpszComp
, -1);
341 return iRet
== CSTR_LESS_THAN
? -1 : iRet
== CSTR_GREATER_THAN
? 1 : 0;
344 /*************************************************************************
345 * StrCmpNA [SHLWAPI.@]
347 * Compare two strings, up to a maximum length.
350 * lpszStr [I] First string to compare
351 * lpszComp [I] Second string to compare
352 * iLen [I] Maximum number of chars to compare.
355 * An integer less than, equal to or greater than 0, indicating that
356 * lpszStr is less than, the same, or greater than lpszComp.
358 INT WINAPI
StrCmpNA(LPCSTR lpszStr
, LPCSTR lpszComp
, INT iLen
)
362 TRACE("(%s,%s,%i)\n", debugstr_a(lpszStr
), debugstr_a(lpszComp
), iLen
);
364 iRet
= CompareStringA(GetThreadLocale(), 0, lpszStr
, iLen
, lpszComp
, iLen
);
365 return iRet
== CSTR_LESS_THAN
? -1 : iRet
== CSTR_GREATER_THAN
? 1 : 0;
368 /*************************************************************************
369 * StrCmpNW [SHLWAPI.@]
373 INT WINAPI
StrCmpNW(LPCWSTR lpszStr
, LPCWSTR lpszComp
, INT iLen
)
377 TRACE("(%s,%s,%i)\n", debugstr_w(lpszStr
), debugstr_w(lpszComp
), iLen
);
379 iRet
= CompareStringW(GetThreadLocale(), 0, lpszStr
, iLen
, lpszComp
, iLen
);
380 return iRet
== CSTR_LESS_THAN
? -1 : iRet
== CSTR_GREATER_THAN
? 1 : 0;
383 /*************************************************************************
384 * StrCmpNIA [SHLWAPI.@]
386 * Compare two strings, up to a maximum length, ignoring case.
389 * lpszStr [I] First string to compare
390 * lpszComp [I] Second string to compare
391 * iLen [I] Maximum number of chars to compare.
394 * An integer less than, equal to or greater than 0, indicating that
395 * lpszStr is less than, the same, or greater than lpszComp.
397 int WINAPI
StrCmpNIA(LPCSTR lpszStr
, LPCSTR lpszComp
, int iLen
)
401 TRACE("(%s,%s,%i)\n", debugstr_a(lpszStr
), debugstr_a(lpszComp
), iLen
);
403 iRet
= CompareStringA(GetThreadLocale(), NORM_IGNORECASE
, lpszStr
, iLen
, lpszComp
, iLen
);
404 return iRet
== CSTR_LESS_THAN
? -1 : iRet
== CSTR_GREATER_THAN
? 1 : 0;
407 /*************************************************************************
408 * StrCmpNIW [SHLWAPI.@]
412 INT WINAPI
StrCmpNIW(LPCWSTR lpszStr
, LPCWSTR lpszComp
, int iLen
)
416 TRACE("(%s,%s,%i)\n", debugstr_w(lpszStr
), debugstr_w(lpszComp
), iLen
);
418 iRet
= CompareStringW(GetThreadLocale(), NORM_IGNORECASE
, lpszStr
, iLen
, lpszComp
, iLen
);
419 return iRet
== CSTR_LESS_THAN
? -1 : iRet
== CSTR_GREATER_THAN
? 1 : 0;
422 /*************************************************************************
423 * StrCmpW [SHLWAPI.@]
425 * Compare two strings.
428 * lpszStr [I] First string to compare
429 * lpszComp [I] Second string to compare
432 * An integer less than, equal to or greater than 0, indicating that
433 * lpszStr is less than, the same, or greater than lpszComp.
435 int WINAPI
StrCmpW(LPCWSTR lpszStr
, LPCWSTR lpszComp
)
439 TRACE("(%s,%s)\n", debugstr_w(lpszStr
), debugstr_w(lpszComp
));
441 iRet
= CompareStringW(GetThreadLocale(), 0, lpszStr
, -1, lpszComp
, -1);
442 return iRet
== CSTR_LESS_THAN
? -1 : iRet
== CSTR_GREATER_THAN
? 1 : 0;
445 /*************************************************************************
446 * StrCatW [SHLWAPI.@]
448 * Concatenate two strings.
451 * lpszStr [O] Initial string
452 * lpszSrc [I] String to concatenate
457 LPWSTR WINAPI
StrCatW(LPWSTR lpszStr
, LPCWSTR lpszSrc
)
459 TRACE("(%s,%s)\n", debugstr_w(lpszStr
), debugstr_w(lpszSrc
));
461 strcatW(lpszStr
, lpszSrc
);
465 /*************************************************************************
466 * StrCpyW [SHLWAPI.@]
468 * Copy a string to another string.
471 * lpszStr [O] Destination string
472 * lpszSrc [I] Source string
477 LPWSTR WINAPI
StrCpyW(LPWSTR lpszStr
, LPCWSTR lpszSrc
)
479 TRACE("(%p,%s)\n", lpszStr
, debugstr_w(lpszSrc
));
481 strcpyW(lpszStr
, lpszSrc
);
485 /*************************************************************************
486 * StrCpyNW [SHLWAPI.@]
488 * Copy a string to another string, up to a maximum number of characters.
491 * lpszStr [O] Destination string
492 * lpszSrc [I] Source string
493 * iLen [I] Maximum number of chars to copy
498 LPWSTR WINAPI
StrCpyNW(LPWSTR lpszStr
, LPCWSTR lpszSrc
, int iLen
)
500 TRACE("(%p,%s,%i)\n", lpszStr
, debugstr_w(lpszSrc
), iLen
);
502 lstrcpynW(lpszStr
, lpszSrc
, iLen
);
508 /*************************************************************************
509 * SHLWAPI_StrStrHelperA
511 * Internal implementation of StrStrA/StrStrIA
513 static LPSTR
SHLWAPI_StrStrHelperA(LPCSTR lpszStr
, LPCSTR lpszSearch
,
514 INT (WINAPI
*pStrCmpFn
)(LPCSTR
,LPCSTR
,INT
))
518 if (!lpszStr
|| !lpszSearch
|| !*lpszSearch
)
521 iLen
= strlen(lpszSearch
);
525 if (!pStrCmpFn(lpszStr
, lpszSearch
, iLen
))
526 return (LPSTR
)lpszStr
;
527 lpszStr
= CharNextA(lpszStr
);
532 /*************************************************************************
533 * StrStrA [SHLWAPI.@]
535 * Find a substring within a string.
538 * lpszStr [I] String to search in
539 * lpszSearch [I] String to look for
542 * The start of lpszSearch within lpszStr, or NULL if not found.
544 LPSTR WINAPI
StrStrA(LPCSTR lpszStr
, LPCSTR lpszSearch
)
546 TRACE("(%s,%s)\n", debugstr_a(lpszStr
), debugstr_a(lpszSearch
));
548 return SHLWAPI_StrStrHelperA(lpszStr
, lpszSearch
, StrCmpNA
);
551 /*************************************************************************
552 * StrStrW [SHLWAPI.@]
556 LPWSTR WINAPI
StrStrW(LPCWSTR lpszStr
, LPCWSTR lpszSearch
)
558 if (!lpszStr
|| !lpszSearch
) return NULL
;
559 return strstrW( lpszStr
, lpszSearch
);
562 /*************************************************************************
563 * StrRStrIA [SHLWAPI.@]
565 * Find the last occurrence of a substring within a string.
568 * lpszStr [I] String to search in
569 * lpszEnd [I] End of lpszStr
570 * lpszSearch [I] String to look for
573 * The last occurrence lpszSearch within lpszStr, or NULL if not found.
575 LPSTR WINAPI
StrRStrIA(LPCSTR lpszStr
, LPCSTR lpszEnd
, LPCSTR lpszSearch
)
580 TRACE("(%s,%s)\n", debugstr_a(lpszStr
), debugstr_a(lpszSearch
));
582 if (!lpszStr
|| !lpszSearch
|| !*lpszSearch
)
586 lpszEnd
= lpszStr
+ lstrlenA(lpszStr
);
587 if (lpszEnd
== lpszStr
)
590 if (IsDBCSLeadByte(*lpszSearch
))
591 ch1
= *lpszSearch
<< 8 | (UCHAR
)lpszSearch
[1];
594 iLen
= lstrlenA(lpszSearch
);
598 lpszEnd
= CharPrevA(lpszStr
, lpszEnd
);
599 ch2
= IsDBCSLeadByte(*lpszEnd
)? *lpszEnd
<< 8 | (UCHAR
)lpszEnd
[1] : *lpszEnd
;
600 if (!ChrCmpIA(ch1
, ch2
))
602 if (!StrCmpNIA(lpszEnd
, lpszSearch
, iLen
))
603 return (LPSTR
)lpszEnd
;
605 } while (lpszEnd
> lpszStr
);
609 /*************************************************************************
610 * StrRStrIW [SHLWAPI.@]
614 LPWSTR WINAPI
StrRStrIW(LPCWSTR lpszStr
, LPCWSTR lpszEnd
, LPCWSTR lpszSearch
)
618 TRACE("(%s,%s)\n", debugstr_w(lpszStr
), debugstr_w(lpszSearch
));
620 if (!lpszStr
|| !lpszSearch
|| !*lpszSearch
)
624 lpszEnd
= lpszStr
+ strlenW(lpszStr
);
626 iLen
= strlenW(lpszSearch
);
628 while (lpszEnd
> lpszStr
)
631 if (!StrCmpNIW(lpszEnd
, lpszSearch
, iLen
))
632 return (LPWSTR
)lpszEnd
;
637 /*************************************************************************
638 * StrStrIA [SHLWAPI.@]
640 * Find a substring within a string, ignoring case.
643 * lpszStr [I] String to search in
644 * lpszSearch [I] String to look for
647 * The start of lpszSearch within lpszStr, or NULL if not found.
649 LPSTR WINAPI
StrStrIA(LPCSTR lpszStr
, LPCSTR lpszSearch
)
651 TRACE("(%s,%s)\n", debugstr_a(lpszStr
), debugstr_a(lpszSearch
));
653 return SHLWAPI_StrStrHelperA(lpszStr
, lpszSearch
, StrCmpNIA
);
656 /*************************************************************************
657 * StrStrIW [SHLWAPI.@]
661 LPWSTR WINAPI
StrStrIW(LPCWSTR lpszStr
, LPCWSTR lpszSearch
)
665 TRACE("(%s,%s)\n", debugstr_w(lpszStr
), debugstr_w(lpszSearch
));
667 if (!lpszStr
|| !lpszSearch
|| !*lpszSearch
)
670 iLen
= strlenW(lpszSearch
);
674 if (!StrCmpNIW(lpszStr
, lpszSearch
, iLen
))
675 return (LPWSTR
)lpszStr
;
681 /*************************************************************************
682 * StrToIntA [SHLWAPI.@]
684 * Read a signed integer from a string.
687 * lpszStr [I] String to read integer from
690 * The signed integer value represented by the string, or 0 if no integer is
694 * No leading space is allowed before the number, although a leading '-' is.
696 int WINAPI
StrToIntA(LPCSTR lpszStr
)
700 TRACE("(%s)\n", debugstr_a(lpszStr
));
704 WARN("Invalid lpszStr would crash under Win32!\n");
708 if (*lpszStr
== '-' || isdigit(*lpszStr
))
709 StrToIntExA(lpszStr
, 0, &iRet
);
713 /*************************************************************************
714 * StrToIntW [SHLWAPI.@]
718 int WINAPI
StrToIntW(LPCWSTR lpszStr
)
722 TRACE("(%s)\n", debugstr_w(lpszStr
));
726 WARN("Invalid lpszStr would crash under Win32!\n");
730 if (*lpszStr
== '-' || isdigitW(*lpszStr
))
731 StrToIntExW(lpszStr
, 0, &iRet
);
735 /*************************************************************************
736 * StrToIntExA [SHLWAPI.@]
738 * Read an integer from a string.
741 * lpszStr [I] String to read integer from
742 * dwFlags [I] Flags controlling the conversion
743 * lpiRet [O] Destination for read integer.
746 * Success: TRUE. lpiRet contains the integer value represented by the string.
747 * Failure: FALSE, if the string is invalid, or no number is present.
750 * Leading whitespace, '-' and '+' are allowed before the number. If
751 * dwFlags includes STIF_SUPPORT_HEX, hexadecimal numbers are allowed, if
752 * preceded by '0x'. If this flag is not set, or there is no '0x' prefix,
753 * the string is treated as a decimal string. A leading '-' is ignored for
754 * hexadecimal numbers.
756 BOOL WINAPI
StrToIntExA(LPCSTR lpszStr
, DWORD dwFlags
, LPINT lpiRet
)
758 BOOL bNegative
= FALSE
;
761 TRACE("(%s,%08X,%p)\n", debugstr_a(lpszStr
), dwFlags
, lpiRet
);
763 if (!lpszStr
|| !lpiRet
)
765 WARN("Invalid parameter would crash under Win32!\n");
768 if (dwFlags
> STIF_SUPPORT_HEX
)
770 WARN("Unknown flags (%08lX)!\n", dwFlags
& ~STIF_SUPPORT_HEX
);
773 /* Skip leading space, '+', '-' */
774 while (isspace(*lpszStr
))
775 lpszStr
= CharNextA(lpszStr
);
782 else if (*lpszStr
== '+')
785 if (dwFlags
& STIF_SUPPORT_HEX
&&
786 *lpszStr
== '0' && tolower(lpszStr
[1]) == 'x')
788 /* Read hex number */
791 if (!isxdigit(*lpszStr
))
794 while (isxdigit(*lpszStr
))
797 if (isdigit(*lpszStr
))
798 iRet
+= (*lpszStr
- '0');
800 iRet
+= 10 + (tolower(*lpszStr
) - 'a');
807 /* Read decimal number */
808 if (!isdigit(*lpszStr
))
811 while (isdigit(*lpszStr
))
814 iRet
+= (*lpszStr
- '0');
817 *lpiRet
= bNegative
? -iRet
: iRet
;
821 /*************************************************************************
822 * StrToIntExW [SHLWAPI.@]
826 BOOL WINAPI
StrToIntExW(LPCWSTR lpszStr
, DWORD dwFlags
, LPINT lpiRet
)
828 BOOL bNegative
= FALSE
;
831 TRACE("(%s,%08X,%p)\n", debugstr_w(lpszStr
), dwFlags
, lpiRet
);
833 if (!lpszStr
|| !lpiRet
)
835 WARN("Invalid parameter would crash under Win32!\n");
838 if (dwFlags
> STIF_SUPPORT_HEX
)
840 WARN("Unknown flags (%08lX)!\n", dwFlags
& ~STIF_SUPPORT_HEX
);
843 /* Skip leading space, '+', '-' */
844 while (isspaceW(*lpszStr
)) lpszStr
++;
851 else if (*lpszStr
== '+')
854 if (dwFlags
& STIF_SUPPORT_HEX
&&
855 *lpszStr
== '0' && tolowerW(lpszStr
[1]) == 'x')
857 /* Read hex number */
860 if (!isxdigitW(*lpszStr
))
863 while (isxdigitW(*lpszStr
))
866 if (isdigitW(*lpszStr
))
867 iRet
+= (*lpszStr
- '0');
869 iRet
+= 10 + (tolowerW(*lpszStr
) - 'a');
876 /* Read decimal number */
877 if (!isdigitW(*lpszStr
))
880 while (isdigitW(*lpszStr
))
883 iRet
+= (*lpszStr
- '0');
886 *lpiRet
= bNegative
? -iRet
: iRet
;
890 /*************************************************************************
891 * StrDupA [SHLWAPI.@]
893 * Duplicate a string.
896 * lpszStr [I] String to duplicate.
899 * Success: A pointer to a new string containing the contents of lpszStr
900 * Failure: NULL, if memory cannot be allocated
903 * The string memory is allocated with LocalAlloc(), and so should be released
904 * by calling LocalFree().
906 LPSTR WINAPI
StrDupA(LPCSTR lpszStr
)
911 TRACE("(%s)\n",debugstr_a(lpszStr
));
913 iLen
= lpszStr
? strlen(lpszStr
) + 1 : 1;
914 lpszRet
= (LPSTR
)LocalAlloc(LMEM_FIXED
, iLen
);
919 memcpy(lpszRet
, lpszStr
, iLen
);
926 /*************************************************************************
927 * StrDupW [SHLWAPI.@]
931 LPWSTR WINAPI
StrDupW(LPCWSTR lpszStr
)
936 TRACE("(%s)\n",debugstr_w(lpszStr
));
938 iLen
= (lpszStr
? strlenW(lpszStr
) + 1 : 1) * sizeof(WCHAR
);
939 lpszRet
= (LPWSTR
)LocalAlloc(LMEM_FIXED
, iLen
);
944 memcpy(lpszRet
, lpszStr
, iLen
);
951 /*************************************************************************
952 * SHLWAPI_StrSpnHelperA
954 * Internal implementation of StrSpnA/StrCSpnA/StrCSpnIA
956 static int SHLWAPI_StrSpnHelperA(LPCSTR lpszStr
, LPCSTR lpszMatch
,
957 LPSTR (WINAPI
*pStrChrFn
)(LPCSTR
,WORD
),
960 LPCSTR lpszRead
= lpszStr
;
961 if (lpszStr
&& *lpszStr
&& lpszMatch
)
965 LPCSTR lpszTest
= pStrChrFn(lpszMatch
, *lpszRead
);
967 if (!bInvert
&& !lpszTest
)
969 if (bInvert
&& lpszTest
)
971 lpszRead
= CharNextA(lpszRead
);
974 return lpszRead
- lpszStr
;
977 /*************************************************************************
978 * StrSpnA [SHLWAPI.@]
980 * Find the length of the start of a string that contains only certain
984 * lpszStr [I] String to search
985 * lpszMatch [I] Characters that can be in the substring
988 * The length of the part of lpszStr containing only chars from lpszMatch,
989 * or 0 if any parameter is invalid.
991 int WINAPI
StrSpnA(LPCSTR lpszStr
, LPCSTR lpszMatch
)
993 TRACE("(%s,%s)\n",debugstr_a(lpszStr
), debugstr_a(lpszMatch
));
995 return SHLWAPI_StrSpnHelperA(lpszStr
, lpszMatch
, StrChrA
, FALSE
);
998 /*************************************************************************
999 * StrSpnW [SHLWAPI.@]
1003 int WINAPI
StrSpnW(LPCWSTR lpszStr
, LPCWSTR lpszMatch
)
1005 if (!lpszStr
|| !lpszMatch
) return 0;
1006 return strspnW( lpszStr
, lpszMatch
);
1009 /*************************************************************************
1010 * StrCSpnA [SHLWAPI.@]
1012 * Find the length of the start of a string that does not contain certain
1016 * lpszStr [I] String to search
1017 * lpszMatch [I] Characters that cannot be in the substring
1020 * The length of the part of lpszStr containing only chars not in lpszMatch,
1021 * or 0 if any parameter is invalid.
1023 int WINAPI
StrCSpnA(LPCSTR lpszStr
, LPCSTR lpszMatch
)
1025 TRACE("(%s,%s)\n",debugstr_a(lpszStr
), debugstr_a(lpszMatch
));
1027 return SHLWAPI_StrSpnHelperA(lpszStr
, lpszMatch
, StrChrA
, TRUE
);
1030 /*************************************************************************
1031 * StrCSpnW [SHLWAPI.@]
1035 int WINAPI
StrCSpnW(LPCWSTR lpszStr
, LPCWSTR lpszMatch
)
1037 if (!lpszStr
|| !lpszMatch
) return 0;
1038 return strcspnW( lpszStr
, lpszMatch
);
1041 /*************************************************************************
1042 * StrCSpnIA [SHLWAPI.@]
1044 * Find the length of the start of a string that does not contain certain
1045 * characters, ignoring case.
1048 * lpszStr [I] String to search
1049 * lpszMatch [I] Characters that cannot be in the substring
1052 * The length of the part of lpszStr containing only chars not in lpszMatch,
1053 * or 0 if any parameter is invalid.
1055 int WINAPI
StrCSpnIA(LPCSTR lpszStr
, LPCSTR lpszMatch
)
1057 TRACE("(%s,%s)\n",debugstr_a(lpszStr
), debugstr_a(lpszMatch
));
1059 return SHLWAPI_StrSpnHelperA(lpszStr
, lpszMatch
, StrChrIA
, TRUE
);
1062 /*************************************************************************
1063 * StrCSpnIW [SHLWAPI.@]
1067 int WINAPI
StrCSpnIW(LPCWSTR lpszStr
, LPCWSTR lpszMatch
)
1069 LPCWSTR lpszRead
= lpszStr
;
1071 TRACE("(%s,%s)\n",debugstr_w(lpszStr
), debugstr_w(lpszMatch
));
1073 if (lpszStr
&& *lpszStr
&& lpszMatch
)
1077 if (StrChrIW(lpszMatch
, *lpszRead
)) break;
1081 return lpszRead
- lpszStr
;
1084 /*************************************************************************
1085 * StrPBrkA [SHLWAPI.@]
1087 * Search a string for any of a group of characters.
1090 * lpszStr [I] String to search
1091 * lpszMatch [I] Characters to match
1094 * A pointer to the first matching character in lpszStr, or NULL if no
1097 LPSTR WINAPI
StrPBrkA(LPCSTR lpszStr
, LPCSTR lpszMatch
)
1099 TRACE("(%s,%s)\n",debugstr_a(lpszStr
), debugstr_a(lpszMatch
));
1101 if (lpszStr
&& lpszMatch
&& *lpszMatch
)
1105 if (StrChrA(lpszMatch
, *lpszStr
))
1106 return (LPSTR
)lpszStr
;
1107 lpszStr
= CharNextA(lpszStr
);
1113 /*************************************************************************
1114 * StrPBrkW [SHLWAPI.@]
1118 LPWSTR WINAPI
StrPBrkW(LPCWSTR lpszStr
, LPCWSTR lpszMatch
)
1120 if (!lpszStr
|| !lpszMatch
) return NULL
;
1121 return strpbrkW( lpszStr
, lpszMatch
);
1124 /*************************************************************************
1125 * SHLWAPI_StrRChrHelperA
1127 * Internal implementation of StrRChrA/StrRChrIA.
1129 static LPSTR
SHLWAPI_StrRChrHelperA(LPCSTR lpszStr
,
1130 LPCSTR lpszEnd
, WORD ch
,
1131 BOOL (WINAPI
*pChrCmpFn
)(WORD
,WORD
))
1133 LPCSTR lpszRet
= NULL
;
1140 lpszEnd
= lpszStr
+ lstrlenA(lpszStr
);
1142 while (*lpszStr
&& lpszStr
<= lpszEnd
)
1144 ch2
= IsDBCSLeadByte(*lpszStr
)? *lpszStr
<< 8 | lpszStr
[1] : *lpszStr
;
1146 if (!pChrCmpFn(ch
, ch2
))
1148 lpszStr
= CharNextA(lpszStr
);
1151 return (LPSTR
)lpszRet
;
1154 /**************************************************************************
1155 * StrRChrA [SHLWAPI.@]
1157 * Find the last occurrence of a character in string.
1160 * lpszStr [I] String to search in
1161 * lpszEnd [I] Place to end search, or NULL to search until the end of lpszStr
1162 * ch [I] Character to search for.
1165 * Success: A pointer to the last occurrence of ch in lpszStr before lpszEnd,
1166 * or NULL if not found.
1167 * Failure: NULL, if any arguments are invalid.
1169 LPSTR WINAPI
StrRChrA(LPCSTR lpszStr
, LPCSTR lpszEnd
, WORD ch
)
1171 TRACE("(%s,%s,%x)\n", debugstr_a(lpszStr
), debugstr_a(lpszEnd
), ch
);
1173 return SHLWAPI_StrRChrHelperA(lpszStr
, lpszEnd
, ch
, SHLWAPI_ChrCmpA
);
1176 /**************************************************************************
1177 * StrRChrW [SHLWAPI.@]
1181 LPWSTR WINAPI
StrRChrW(LPCWSTR str
, LPCWSTR end
, WORD ch
)
1185 if (!str
) return NULL
;
1186 if (!end
) end
= str
+ strlenW(str
);
1189 if (*str
== ch
) ret
= (WCHAR
*)str
;
1195 /**************************************************************************
1196 * StrRChrIA [SHLWAPI.@]
1198 * Find the last occurrence of a character in string, ignoring case.
1201 * lpszStr [I] String to search in
1202 * lpszEnd [I] Place to end search, or NULL to search until the end of lpszStr
1203 * ch [I] Character to search for.
1206 * Success: A pointer to the last occurrence of ch in lpszStr before lpszEnd,
1207 * or NULL if not found.
1208 * Failure: NULL, if any arguments are invalid.
1210 LPSTR WINAPI
StrRChrIA(LPCSTR lpszStr
, LPCSTR lpszEnd
, WORD ch
)
1212 TRACE("(%s,%s,%x)\n", debugstr_a(lpszStr
), debugstr_a(lpszEnd
), ch
);
1214 return SHLWAPI_StrRChrHelperA(lpszStr
, lpszEnd
, ch
, ChrCmpIA
);
1217 /**************************************************************************
1218 * StrRChrIW [SHLWAPI.@]
1222 LPWSTR WINAPI
StrRChrIW(LPCWSTR str
, LPCWSTR end
, WORD ch
)
1226 if (!str
) return NULL
;
1227 if (!end
) end
= str
+ strlenW(str
);
1230 if (!ChrCmpIW(*str
, ch
)) ret
= (WCHAR
*)str
;
1236 /*************************************************************************
1237 * StrCatBuffA [SHLWAPI.@]
1239 * Concatenate two strings together.
1242 * lpszStr [O] String to concatenate to
1243 * lpszCat [I] String to add to lpszCat
1244 * cchMax [I] Maximum number of characters for the whole string
1250 * cchMax determines the number of characters in the final length of the
1251 * string, not the number appended to lpszStr from lpszCat.
1253 LPSTR WINAPI
StrCatBuffA(LPSTR lpszStr
, LPCSTR lpszCat
, INT cchMax
)
1257 TRACE("(%p,%s,%d)\n", lpszStr
, debugstr_a(lpszCat
), cchMax
);
1261 WARN("Invalid lpszStr would crash under Win32!\n");
1265 iLen
= strlen(lpszStr
);
1269 StrCpyNA(lpszStr
+ iLen
, lpszCat
, cchMax
);
1273 /*************************************************************************
1274 * StrCatBuffW [SHLWAPI.@]
1278 LPWSTR WINAPI
StrCatBuffW(LPWSTR lpszStr
, LPCWSTR lpszCat
, INT cchMax
)
1282 TRACE("(%p,%s,%d)\n", lpszStr
, debugstr_w(lpszCat
), cchMax
);
1286 WARN("Invalid lpszStr would crash under Win32!\n");
1290 iLen
= strlenW(lpszStr
);
1294 StrCpyNW(lpszStr
+ iLen
, lpszCat
, cchMax
);
1298 /*************************************************************************
1299 * StrRetToBufA [SHLWAPI.@]
1301 * Convert a STRRET to a normal string.
1304 * lpStrRet [O] STRRET to convert
1305 * pIdl [I] ITEMIDLIST for lpStrRet->uType == STRRET_OFFSET
1306 * lpszDest [O] Destination for normal string
1307 * dwLen [I] Length of lpszDest
1310 * Success: S_OK. lpszDest contains up to dwLen characters of the string.
1311 * If lpStrRet is of type STRRET_WSTR, its memory is freed with
1312 * CoTaskMemFree() and its type set to STRRET_CSTRA.
1313 * Failure: E_FAIL, if any parameters are invalid.
1315 HRESULT WINAPI
StrRetToBufA (LPSTRRET src
, const ITEMIDLIST
*pidl
, LPSTR dest
, UINT len
)
1318 * This routine is identical to that in dlls/shell32/shellstring.c.
1319 * It was duplicated because not every version of Shlwapi.dll exports
1320 * StrRetToBufA. If you change one routine, change them both.
1322 TRACE("dest=%p len=0x%x strret=%p pidl=%p stub\n",dest
,len
,src
,pidl
);
1326 WARN("Invalid lpStrRet would crash under Win32!\n");
1340 WideCharToMultiByte(CP_ACP
, 0, src
->u
.pOleStr
, -1, dest
, len
, NULL
, NULL
);
1341 CoTaskMemFree(src
->u
.pOleStr
);
1345 lstrcpynA((LPSTR
)dest
, src
->u
.cStr
, len
);
1349 lstrcpynA((LPSTR
)dest
, ((LPCSTR
)&pidl
->mkid
)+src
->u
.uOffset
, len
);
1353 FIXME("unknown type!\n");
1359 /*************************************************************************
1360 * StrRetToBufW [SHLWAPI.@]
1364 HRESULT WINAPI
StrRetToBufW (LPSTRRET src
, const ITEMIDLIST
*pidl
, LPWSTR dest
, UINT len
)
1366 TRACE("dest=%p len=0x%x strret=%p pidl=%p stub\n",dest
,len
,src
,pidl
);
1370 WARN("Invalid lpStrRet would crash under Win32!\n");
1384 lstrcpynW((LPWSTR
)dest
, src
->u
.pOleStr
, len
);
1385 CoTaskMemFree(src
->u
.pOleStr
);
1389 if (!MultiByteToWideChar( CP_ACP
, 0, src
->u
.cStr
, -1, dest
, len
) && len
)
1396 if (!MultiByteToWideChar( CP_ACP
, 0, ((LPCSTR
)&pidl
->mkid
)+src
->u
.uOffset
, -1,
1403 FIXME("unknown type!\n");
1409 /*************************************************************************
1410 * StrRetToStrA [SHLWAPI.@]
1412 * Converts a STRRET to a normal string.
1415 * lpStrRet [O] STRRET to convert
1416 * pidl [I] ITEMIDLIST for lpStrRet->uType == STRRET_OFFSET
1417 * ppszName [O] Destination for converted string
1420 * Success: S_OK. ppszName contains the new string, allocated with CoTaskMemAlloc().
1421 * Failure: E_FAIL, if any parameters are invalid.
1423 HRESULT WINAPI
StrRetToStrA(LPSTRRET lpStrRet
, const ITEMIDLIST
*pidl
, LPSTR
*ppszName
)
1425 HRESULT hRet
= E_FAIL
;
1427 switch (lpStrRet
->uType
)
1430 hRet
= _SHStrDupAW(lpStrRet
->u
.pOleStr
, ppszName
);
1431 CoTaskMemFree(lpStrRet
->u
.pOleStr
);
1435 hRet
= _SHStrDupAA(lpStrRet
->u
.cStr
, ppszName
);
1439 hRet
= _SHStrDupAA(((LPCSTR
)&pidl
->mkid
) + lpStrRet
->u
.uOffset
, ppszName
);
1449 /*************************************************************************
1450 * StrRetToStrW [SHLWAPI.@]
1454 HRESULT WINAPI
StrRetToStrW(LPSTRRET lpStrRet
, const ITEMIDLIST
*pidl
, LPWSTR
*ppszName
)
1456 HRESULT hRet
= E_FAIL
;
1458 switch (lpStrRet
->uType
)
1461 hRet
= SHStrDupW(lpStrRet
->u
.pOleStr
, ppszName
);
1462 CoTaskMemFree(lpStrRet
->u
.pOleStr
);
1466 hRet
= SHStrDupA(lpStrRet
->u
.cStr
, ppszName
);
1470 hRet
= SHStrDupA(((LPCSTR
)&pidl
->mkid
) + lpStrRet
->u
.uOffset
, ppszName
);
1480 /* Create an ASCII string copy using SysAllocString() */
1481 static HRESULT
_SHStrDupAToBSTR(LPCSTR src
, BSTR
*pBstrOut
)
1487 INT len
= MultiByteToWideChar(CP_ACP
, 0, src
, -1, NULL
, 0);
1488 WCHAR
* szTemp
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1492 MultiByteToWideChar(CP_ACP
, 0, src
, -1, szTemp
, len
);
1493 *pBstrOut
= SysAllocString(szTemp
);
1494 HeapFree(GetProcessHeap(), 0, szTemp
);
1500 return E_OUTOFMEMORY
;
1503 /*************************************************************************
1504 * StrRetToBSTR [SHLWAPI.@]
1506 * Converts a STRRET to a BSTR.
1509 * lpStrRet [O] STRRET to convert
1510 * pidl [I] ITEMIDLIST for lpStrRet->uType = STRRET_OFFSET
1511 * pBstrOut [O] Destination for converted BSTR
1514 * Success: S_OK. pBstrOut contains the new string.
1515 * Failure: E_FAIL, if any parameters are invalid.
1517 HRESULT WINAPI
StrRetToBSTR(STRRET
*lpStrRet
, LPCITEMIDLIST pidl
, BSTR
* pBstrOut
)
1519 HRESULT hRet
= E_FAIL
;
1521 switch (lpStrRet
->uType
)
1524 *pBstrOut
= SysAllocString(lpStrRet
->u
.pOleStr
);
1527 CoTaskMemFree(lpStrRet
->u
.pOleStr
);
1531 hRet
= _SHStrDupAToBSTR(lpStrRet
->u
.cStr
, pBstrOut
);
1535 hRet
= _SHStrDupAToBSTR(((LPCSTR
)&pidl
->mkid
) + lpStrRet
->u
.uOffset
, pBstrOut
);
1545 /*************************************************************************
1546 * StrFormatKBSizeA [SHLWAPI.@]
1548 * Create a formatted string containing a byte count in Kilobytes.
1551 * llBytes [I] Byte size to format
1552 * lpszDest [I] Destination for formatted string
1553 * cchMax [I] Size of lpszDest
1558 LPSTR WINAPI
StrFormatKBSizeA(LONGLONG llBytes
, LPSTR lpszDest
, UINT cchMax
)
1562 if (!StrFormatKBSizeW(llBytes
, wszBuf
, 256))
1564 if (!WideCharToMultiByte(CP_ACP
, 0, wszBuf
, -1, lpszDest
, cchMax
, NULL
, NULL
))
1569 /*************************************************************************
1570 * StrFormatKBSizeW [SHLWAPI.@]
1572 * See StrFormatKBSizeA.
1574 LPWSTR WINAPI
StrFormatKBSizeW(LONGLONG llBytes
, LPWSTR lpszDest
, UINT cchMax
)
1576 static const WCHAR kb
[] = {' ','K','B',0};
1577 LONGLONG llKB
= (llBytes
+ 1023) >> 10;
1580 TRACE("(0x%s,%p,%d)\n", wine_dbgstr_longlong(llBytes
), lpszDest
, cchMax
);
1582 if (!FormatInt(llKB
, lpszDest
, cchMax
))
1585 len
= lstrlenW(lpszDest
);
1586 if (cchMax
- len
< 4)
1588 lstrcatW(lpszDest
, kb
);
1592 /*************************************************************************
1593 * StrNCatA [SHLWAPI.@]
1595 * Concatenate two strings together.
1598 * lpszStr [O] String to concatenate to
1599 * lpszCat [I] String to add to lpszCat
1600 * cchMax [I] Maximum number of characters to concatenate
1606 * cchMax determines the number of characters that are appended to lpszStr,
1607 * not the total length of the string.
1609 LPSTR WINAPI
StrNCatA(LPSTR lpszStr
, LPCSTR lpszCat
, INT cchMax
)
1611 LPSTR lpszRet
= lpszStr
;
1613 TRACE("(%s,%s,%i)\n", debugstr_a(lpszStr
), debugstr_a(lpszCat
), cchMax
);
1617 WARN("Invalid lpszStr would crash under Win32!\n");
1621 StrCpyNA(lpszStr
+ strlen(lpszStr
), lpszCat
, cchMax
);
1625 /*************************************************************************
1626 * StrNCatW [SHLWAPI.@]
1630 LPWSTR WINAPI
StrNCatW(LPWSTR lpszStr
, LPCWSTR lpszCat
, INT cchMax
)
1632 LPWSTR lpszRet
= lpszStr
;
1634 TRACE("(%s,%s,%i)\n", debugstr_w(lpszStr
), debugstr_w(lpszCat
), cchMax
);
1638 WARN("Invalid lpszStr would crash under Win32\n");
1642 StrCpyNW(lpszStr
+ strlenW(lpszStr
), lpszCat
, cchMax
);
1646 /*************************************************************************
1647 * StrTrimA [SHLWAPI.@]
1649 * Remove characters from the start and end of a string.
1652 * lpszStr [O] String to remove characters from
1653 * lpszTrim [I] Characters to remove from lpszStr
1656 * TRUE If lpszStr was valid and modified
1659 BOOL WINAPI
StrTrimA(LPSTR lpszStr
, LPCSTR lpszTrim
)
1662 LPSTR lpszRead
= lpszStr
;
1665 TRACE("(%s,%s)\n", debugstr_a(lpszStr
), debugstr_a(lpszTrim
));
1667 if (lpszRead
&& *lpszRead
)
1669 while (*lpszRead
&& StrChrA(lpszTrim
, *lpszRead
))
1670 lpszRead
= CharNextA(lpszRead
); /* Skip leading matches */
1672 dwLen
= strlen(lpszRead
);
1674 if (lpszRead
!= lpszStr
)
1676 memmove(lpszStr
, lpszRead
, dwLen
+ 1);
1681 lpszRead
= lpszStr
+ dwLen
;
1682 while (StrChrA(lpszTrim
, lpszRead
[-1]))
1683 lpszRead
= CharPrevA(lpszStr
, lpszRead
); /* Skip trailing matches */
1685 if (lpszRead
!= lpszStr
+ dwLen
)
1695 /*************************************************************************
1696 * StrTrimW [SHLWAPI.@]
1700 BOOL WINAPI
StrTrimW(LPWSTR lpszStr
, LPCWSTR lpszTrim
)
1703 LPWSTR lpszRead
= lpszStr
;
1706 TRACE("(%s,%s)\n", debugstr_w(lpszStr
), debugstr_w(lpszTrim
));
1708 if (lpszRead
&& *lpszRead
)
1710 while (*lpszRead
&& StrChrW(lpszTrim
, *lpszRead
)) lpszRead
++;
1712 dwLen
= strlenW(lpszRead
);
1714 if (lpszRead
!= lpszStr
)
1716 memmove(lpszStr
, lpszRead
, (dwLen
+ 1) * sizeof(WCHAR
));
1721 lpszRead
= lpszStr
+ dwLen
;
1722 while (StrChrW(lpszTrim
, lpszRead
[-1]))
1723 lpszRead
--; /* Skip trailing matches */
1725 if (lpszRead
!= lpszStr
+ dwLen
)
1735 /*************************************************************************
1736 * _SHStrDupAA [INTERNAL]
1738 * Duplicates a ASCII string to ASCII. The destination buffer is allocated.
1740 static HRESULT
_SHStrDupAA(LPCSTR src
, LPSTR
* dest
)
1746 len
= lstrlenA(src
) + 1;
1747 *dest
= CoTaskMemAlloc(len
);
1753 lstrcpynA(*dest
,src
, len
);
1759 TRACE("%s->(%p)\n", debugstr_a(src
), *dest
);
1763 /*************************************************************************
1764 * SHStrDupA [SHLWAPI.@]
1766 * Return a Unicode copy of a string, in memory allocated by CoTaskMemAlloc().
1769 * lpszStr [I] String to copy
1770 * lppszDest [O] Destination for the new string copy
1773 * Success: S_OK. lppszDest contains the new string in Unicode format.
1774 * Failure: E_OUTOFMEMORY, If any arguments are invalid or memory allocation
1777 HRESULT WINAPI
SHStrDupA(LPCSTR lpszStr
, LPWSTR
* lppszDest
)
1784 len
= MultiByteToWideChar(0, 0, lpszStr
, -1, 0, 0) * sizeof(WCHAR
);
1785 *lppszDest
= CoTaskMemAlloc(len
);
1792 MultiByteToWideChar(0, 0, lpszStr
, -1, *lppszDest
, len
/sizeof(WCHAR
));
1796 hRet
= E_OUTOFMEMORY
;
1798 TRACE("%s->(%p)\n", debugstr_a(lpszStr
), *lppszDest
);
1802 /*************************************************************************
1803 * _SHStrDupAW [INTERNAL]
1805 * Duplicates a UNICODE to a ASCII string. The destination buffer is allocated.
1807 static HRESULT
_SHStrDupAW(LPCWSTR src
, LPSTR
* dest
)
1813 len
= WideCharToMultiByte(CP_ACP
, 0, src
, -1, NULL
, 0, NULL
, NULL
);
1814 *dest
= CoTaskMemAlloc(len
);
1820 WideCharToMultiByte(CP_ACP
, 0, src
, -1, *dest
, len
, NULL
, NULL
);
1826 TRACE("%s->(%p)\n", debugstr_w(src
), *dest
);
1830 /*************************************************************************
1831 * SHStrDupW [SHLWAPI.@]
1835 HRESULT WINAPI
SHStrDupW(LPCWSTR src
, LPWSTR
* dest
)
1841 len
= (lstrlenW(src
) + 1) * sizeof(WCHAR
);
1842 *dest
= CoTaskMemAlloc(len
);
1848 memcpy(*dest
, src
, len
);
1854 TRACE("%s->(%p)\n", debugstr_w(src
), *dest
);
1858 /*************************************************************************
1859 * SHLWAPI_WriteReverseNum
1861 * Internal helper for SHLWAPI_WriteTimeClass.
1863 static inline LPWSTR
SHLWAPI_WriteReverseNum(LPWSTR lpszOut
, DWORD dwNum
)
1867 /* Write a decimal number to a string, backwards */
1870 DWORD dwNextDigit
= dwNum
% 10;
1871 *lpszOut
-- = '0' + dwNextDigit
;
1872 dwNum
= (dwNum
- dwNextDigit
) / 10;
1873 } while (dwNum
> 0);
1878 /*************************************************************************
1879 * SHLWAPI_FormatSignificant
1881 * Internal helper for SHLWAPI_WriteTimeClass.
1883 static inline int SHLWAPI_FormatSignificant(LPWSTR lpszNum
, int dwDigits
)
1885 /* Zero non significant digits, return remaining significant digits */
1889 if (--dwDigits
== 0)
1899 /*************************************************************************
1900 * SHLWAPI_WriteTimeClass
1902 * Internal helper for StrFromTimeIntervalW.
1904 static int SHLWAPI_WriteTimeClass(LPWSTR lpszOut
, DWORD dwValue
,
1905 UINT uClassStringId
, int iDigits
)
1907 WCHAR szBuff
[64], *szOut
= szBuff
+ 32;
1909 szOut
= SHLWAPI_WriteReverseNum(szOut
, dwValue
);
1910 iDigits
= SHLWAPI_FormatSignificant(szOut
+ 1, iDigits
);
1912 LoadStringW(shlwapi_hInstance
, uClassStringId
, szBuff
+ 32, 32);
1913 strcatW(lpszOut
, szOut
);
1917 /*************************************************************************
1918 * StrFromTimeIntervalA [SHLWAPI.@]
1920 * Format a millisecond time interval into a string
1923 * lpszStr [O] Output buffer for formatted time interval
1924 * cchMax [I] Size of lpszStr
1925 * dwMS [I] Number of milliseconds
1926 * iDigits [I] Number of digits to print
1929 * The length of the formatted string, or 0 if any parameter is invalid.
1932 * This implementation mimics the Win32 behaviour of always writing a leading
1933 * space before the time interval begins.
1935 * iDigits is used to provide approximate times if accuracy is not important.
1936 * This number of digits will be written of the first non-zero time class
1937 * (hours/minutes/seconds). If this does not complete the time classification,
1938 * the remaining digits are changed to zeros (i.e. The time is _not_ rounded).
1939 * If there are digits remaining following the writing of a time class, the
1940 * next time class will be written.
1942 * For example, given dwMS represents 138 hours,43 minutes and 15 seconds, the
1943 * following will result from the given values of iDigits:
1945 *| iDigits 1 2 3 4 5 ...
1946 *| lpszStr "100 hr" "130 hr" "138 hr" "138 hr 40 min" "138 hr 43 min" ...
1948 INT WINAPI
StrFromTimeIntervalA(LPSTR lpszStr
, UINT cchMax
, DWORD dwMS
,
1953 TRACE("(%p,%d,%d,%d)\n", lpszStr
, cchMax
, dwMS
, iDigits
);
1955 if (lpszStr
&& cchMax
)
1958 StrFromTimeIntervalW(szBuff
, sizeof(szBuff
)/sizeof(WCHAR
), dwMS
, iDigits
);
1959 WideCharToMultiByte(CP_ACP
,0,szBuff
,-1,lpszStr
,cchMax
,0,0);
1965 /*************************************************************************
1966 * StrFromTimeIntervalW [SHLWAPI.@]
1968 * See StrFromTimeIntervalA.
1970 INT WINAPI
StrFromTimeIntervalW(LPWSTR lpszStr
, UINT cchMax
, DWORD dwMS
,
1975 TRACE("(%p,%d,%d,%d)\n", lpszStr
, cchMax
, dwMS
, iDigits
);
1977 if (lpszStr
&& cchMax
)
1980 DWORD dwHours
, dwMinutes
;
1982 if (!iDigits
|| cchMax
== 1)
1988 /* Calculate the time classes */
1989 dwMS
= (dwMS
+ 500) / 1000;
1990 dwHours
= dwMS
/ 3600;
1991 dwMS
-= dwHours
* 3600;
1992 dwMinutes
= dwMS
/ 60;
1993 dwMS
-= dwMinutes
* 60;
1998 iDigits
= SHLWAPI_WriteTimeClass(szCopy
, dwHours
, IDS_TIME_INTERVAL_HOURS
, iDigits
);
2000 if (dwMinutes
&& iDigits
)
2001 iDigits
= SHLWAPI_WriteTimeClass(szCopy
, dwMinutes
, IDS_TIME_INTERVAL_MINUTES
, iDigits
);
2003 if (iDigits
) /* Always write seconds if we have significant digits */
2004 SHLWAPI_WriteTimeClass(szCopy
, dwMS
, IDS_TIME_INTERVAL_SECONDS
, iDigits
);
2006 lstrcpynW(lpszStr
, szCopy
, cchMax
);
2007 iRet
= strlenW(lpszStr
);
2012 /*************************************************************************
2013 * StrIsIntlEqualA [SHLWAPI.@]
2015 * Compare two strings.
2018 * bCase [I] Whether to compare case sensitively
2019 * lpszStr [I] First string to compare
2020 * lpszComp [I] Second string to compare
2021 * iLen [I] Length to compare
2024 * TRUE If the strings are equal.
2027 BOOL WINAPI
StrIsIntlEqualA(BOOL bCase
, LPCSTR lpszStr
, LPCSTR lpszComp
,
2032 TRACE("(%d,%s,%s,%d)\n", bCase
,
2033 debugstr_a(lpszStr
), debugstr_a(lpszComp
), iLen
);
2035 /* FIXME: This flag is undocumented and unknown by our CompareString.
2036 * We need a define for it.
2038 dwFlags
= 0x10000000;
2039 if (!bCase
) dwFlags
|= NORM_IGNORECASE
;
2041 return (CompareStringA(GetThreadLocale(), dwFlags
, lpszStr
, iLen
, lpszComp
, iLen
) == CSTR_EQUAL
);
2044 /*************************************************************************
2045 * StrIsIntlEqualW [SHLWAPI.@]
2047 * See StrIsIntlEqualA.
2049 BOOL WINAPI
StrIsIntlEqualW(BOOL bCase
, LPCWSTR lpszStr
, LPCWSTR lpszComp
,
2054 TRACE("(%d,%s,%s,%d)\n", bCase
,
2055 debugstr_w(lpszStr
),debugstr_w(lpszComp
), iLen
);
2057 /* FIXME: This flag is undocumented and unknown by our CompareString.
2058 * We need a define for it.
2060 dwFlags
= 0x10000000;
2061 if (!bCase
) dwFlags
|= NORM_IGNORECASE
;
2063 return (CompareStringW(GetThreadLocale(), dwFlags
, lpszStr
, iLen
, lpszComp
, iLen
) == CSTR_EQUAL
);
2066 /*************************************************************************
2069 * Copy a string to another string, up to a maximum number of characters.
2072 * lpszDest [O] Destination string
2073 * lpszSrc [I] Source string
2074 * iLen [I] Maximum number of chars to copy
2077 * Success: A pointer to the last character written to lpszDest.
2078 * Failure: lpszDest, if any arguments are invalid.
2080 LPSTR WINAPI
StrCpyNXA(LPSTR lpszDest
, LPCSTR lpszSrc
, int iLen
)
2082 TRACE("(%p,%s,%i)\n", lpszDest
, debugstr_a(lpszSrc
), iLen
);
2084 if (lpszDest
&& lpszSrc
&& iLen
> 0)
2086 while ((iLen
-- > 1) && *lpszSrc
)
2087 *lpszDest
++ = *lpszSrc
++;
2094 /*************************************************************************
2097 * Unicode version of StrCpyNXA.
2099 LPWSTR WINAPI
StrCpyNXW(LPWSTR lpszDest
, LPCWSTR lpszSrc
, int iLen
)
2101 TRACE("(%p,%s,%i)\n", lpszDest
, debugstr_w(lpszSrc
), iLen
);
2103 if (lpszDest
&& lpszSrc
&& iLen
> 0)
2105 while ((iLen
-- > 1) && *lpszSrc
)
2106 *lpszDest
++ = *lpszSrc
++;
2113 /*************************************************************************
2114 * StrCmpLogicalW [SHLWAPI.@]
2116 * Compare two strings, ignoring case and comparing digits as numbers.
2119 * lpszStr [I] First string to compare
2120 * lpszComp [I] Second string to compare
2121 * iLen [I] Length to compare
2124 * TRUE If the strings are equal.
2127 INT WINAPI
StrCmpLogicalW(LPCWSTR lpszStr
, LPCWSTR lpszComp
)
2131 TRACE("(%s,%s)\n", debugstr_w(lpszStr
), debugstr_w(lpszComp
));
2133 if (lpszStr
&& lpszComp
)
2139 else if (isdigitW(*lpszStr
))
2143 if (!isdigitW(*lpszComp
))
2146 /* Compare the numbers */
2147 StrToIntExW(lpszStr
, 0, &iStr
);
2148 StrToIntExW(lpszComp
, 0, &iComp
);
2152 else if (iStr
> iComp
)
2156 while (isdigitW(*lpszStr
))
2158 while (isdigitW(*lpszComp
))
2161 else if (isdigitW(*lpszComp
))
2165 iDiff
= ChrCmpIW(*lpszStr
,*lpszComp
);
2181 /* Structure for formatting byte strings */
2182 typedef struct tagSHLWAPI_BYTEFORMATS
2189 } SHLWAPI_BYTEFORMATS
;
2191 /*************************************************************************
2192 * StrFormatByteSizeW [SHLWAPI.@]
2194 * Create a string containing an abbreviated byte count of up to 2^63-1.
2197 * llBytes [I] Byte size to format
2198 * lpszDest [I] Destination for formatted string
2199 * cchMax [I] Size of lpszDest
2205 * There is no StrFormatByteSize64W function, it is called StrFormatByteSizeW().
2207 LPWSTR WINAPI
StrFormatByteSizeW(LONGLONG llBytes
, LPWSTR lpszDest
, UINT cchMax
)
2209 #define KB ((ULONGLONG)1024)
2211 #define GB (KB*KB*KB)
2212 #define TB (KB*KB*KB*KB)
2213 #define PB (KB*KB*KB*KB*KB)
2215 static const SHLWAPI_BYTEFORMATS bfFormats
[] =
2217 { 10*KB
, 10.24, 100.0, 2, 'K' }, /* 10 KB */
2218 { 100*KB
, 102.4, 10.0, 1, 'K' }, /* 100 KB */
2219 { 1000*KB
, 1024.0, 1.0, 0, 'K' }, /* 1000 KB */
2220 { 10*MB
, 10485.76, 100.0, 2, 'M' }, /* 10 MB */
2221 { 100*MB
, 104857.6, 10.0, 1, 'M' }, /* 100 MB */
2222 { 1000*MB
, 1048576.0, 1.0, 0, 'M' }, /* 1000 MB */
2223 { 10*GB
, 10737418.24, 100.0, 2, 'G' }, /* 10 GB */
2224 { 100*GB
, 107374182.4, 10.0, 1, 'G' }, /* 100 GB */
2225 { 1000*GB
, 1073741824.0, 1.0, 0, 'G' }, /* 1000 GB */
2226 { 10*TB
, 10485.76, 100.0, 2, 'T' }, /* 10 TB */
2227 { 100*TB
, 104857.6, 10.0, 1, 'T' }, /* 100 TB */
2228 { 1000*TB
, 1048576.0, 1.0, 0, 'T' }, /* 1000 TB */
2229 { 10*PB
, 10737418.24, 100.00, 2, 'P' }, /* 10 PB */
2230 { 100*PB
, 107374182.4, 10.00, 1, 'P' }, /* 100 PB */
2231 { 1000*PB
, 1073741824.0, 1.00, 0, 'P' }, /* 1000 PB */
2232 { 0, 10995116277.76, 100.00, 2, 'E' } /* EB's, catch all */
2234 WCHAR wszAdd
[] = {' ','?','B',0};
2238 TRACE("(0x%s,%p,%d)\n", wine_dbgstr_longlong(llBytes
), lpszDest
, cchMax
);
2240 if (!lpszDest
|| !cchMax
)
2243 if (llBytes
< 1024) /* 1K */
2245 WCHAR wszBytesFormat
[64];
2246 LoadStringW(shlwapi_hInstance
, IDS_BYTES_FORMAT
, wszBytesFormat
, 64);
2247 snprintfW(lpszDest
, cchMax
, wszBytesFormat
, (long)llBytes
);
2251 /* Note that if this loop completes without finding a match, i will be
2252 * pointing at the last entry, which is a catch all for > 1000 PB
2254 while (i
< sizeof(bfFormats
) / sizeof(SHLWAPI_BYTEFORMATS
) - 1)
2256 if (llBytes
< bfFormats
[i
].dLimit
)
2260 /* Above 1 TB we encounter problems with FP accuracy. So for amounts above
2261 * this number we integer shift down by 1 MB first. The table above has
2262 * the divisors scaled down from the '< 10 TB' entry onwards, to account
2263 * for this. We also add a small fudge factor to get the correct result for
2264 * counts that lie exactly on a 1024 byte boundary.
2267 dBytes
= (double)(llBytes
>> 20) + 0.001; /* Scale down by I MB */
2269 dBytes
= (double)llBytes
+ 0.00001;
2271 dBytes
= floor(dBytes
/ bfFormats
[i
].dDivisor
) / bfFormats
[i
].dNormaliser
;
2273 if (!FormatDouble(dBytes
, bfFormats
[i
].nDecimals
, lpszDest
, cchMax
))
2275 wszAdd
[1] = bfFormats
[i
].wPrefix
;
2276 StrCatBuffW(lpszDest
, wszAdd
, cchMax
);
2280 /*************************************************************************
2281 * StrFormatByteSize64A [SHLWAPI.@]
2283 * See StrFormatByteSizeW.
2285 LPSTR WINAPI
StrFormatByteSize64A(LONGLONG llBytes
, LPSTR lpszDest
, UINT cchMax
)
2289 StrFormatByteSizeW(llBytes
, wszBuff
, sizeof(wszBuff
)/sizeof(WCHAR
));
2292 WideCharToMultiByte(CP_ACP
, 0, wszBuff
, -1, lpszDest
, cchMax
, 0, 0);
2296 /*************************************************************************
2297 * StrFormatByteSizeA [SHLWAPI.@]
2299 * Create a string containing an abbreviated byte count of up to 2^31-1.
2302 * dwBytes [I] Byte size to format
2303 * lpszDest [I] Destination for formatted string
2304 * cchMax [I] Size of lpszDest
2310 * The Ascii and Unicode versions of this function accept a different
2311 * integer type for dwBytes. See StrFormatByteSize64A().
2313 LPSTR WINAPI
StrFormatByteSizeA(DWORD dwBytes
, LPSTR lpszDest
, UINT cchMax
)
2315 TRACE("(%d,%p,%d)\n", dwBytes
, lpszDest
, cchMax
);
2317 return StrFormatByteSize64A(dwBytes
, lpszDest
, cchMax
);
2320 /*************************************************************************
2323 * Remove a hanging lead byte from the end of a string, if present.
2326 * lpStr [I] String to check for a hanging lead byte
2327 * size [I] Length of lpStr
2330 * Success: The new length of the string. Any hanging lead bytes are removed.
2331 * Failure: 0, if any parameters are invalid.
2333 DWORD WINAPI
SHTruncateString(LPSTR lpStr
, DWORD size
)
2337 LPSTR lastByte
= lpStr
+ size
- 1;
2339 while(lpStr
< lastByte
)
2340 lpStr
+= IsDBCSLeadByte(*lpStr
) ? 2 : 1;
2342 if(lpStr
== lastByte
&& IsDBCSLeadByte(*lpStr
))
2352 /*************************************************************************
2355 * Remove a single non-trailing ampersand ('&') from a string.
2358 * lpszStr [I/O] String to remove ampersand from.
2361 * The character after the first ampersand in lpszStr, or the first character
2362 * in lpszStr if there is no ampersand in the string.
2364 char WINAPI
SHStripMneumonicA(LPCSTR lpszStr
)
2366 LPSTR lpszIter
, lpszTmp
;
2369 TRACE("(%s)\n", debugstr_a(lpszStr
));
2373 if ((lpszIter
= StrChrA(lpszStr
, '&')))
2375 lpszTmp
= CharNextA(lpszIter
);
2376 if (lpszTmp
&& *lpszTmp
)
2378 if (*lpszTmp
!= '&')
2381 while (lpszIter
&& *lpszIter
)
2383 lpszTmp
= CharNextA(lpszIter
);
2384 *lpszIter
= *lpszTmp
;
2393 /*************************************************************************
2396 * Unicode version of SHStripMneumonicA.
2398 WCHAR WINAPI
SHStripMneumonicW(LPCWSTR lpszStr
)
2400 LPWSTR lpszIter
, lpszTmp
;
2403 TRACE("(%s)\n", debugstr_w(lpszStr
));
2407 if ((lpszIter
= StrChrW(lpszStr
, '&')))
2409 lpszTmp
= lpszIter
+ 1;
2410 if (lpszTmp
&& *lpszTmp
)
2412 if (*lpszTmp
!= '&')
2415 while (lpszIter
&& *lpszIter
)
2417 lpszTmp
= lpszIter
+ 1;
2418 *lpszIter
= *lpszTmp
;
2427 /*************************************************************************
2430 * Convert an Ascii string to Unicode.
2433 * dwCp [I] Code page for the conversion
2434 * lpSrcStr [I] Source Ascii string to convert
2435 * lpDstStr [O] Destination for converted Unicode string
2436 * iLen [I] Length of lpDstStr
2439 * The return value of the MultiByteToWideChar() function called on lpSrcStr.
2441 DWORD WINAPI
SHAnsiToUnicodeCP(DWORD dwCp
, LPCSTR lpSrcStr
, LPWSTR lpDstStr
, int iLen
)
2445 dwRet
= MultiByteToWideChar(dwCp
, 0, lpSrcStr
, -1, lpDstStr
, iLen
);
2446 TRACE("%s->%s,ret=%d\n", debugstr_a(lpSrcStr
), debugstr_w(lpDstStr
), dwRet
);
2450 /*************************************************************************
2453 * Convert an Ascii string to Unicode.
2456 * lpSrcStr [I] Source Ascii string to convert
2457 * lpDstStr [O] Destination for converted Unicode string
2458 * iLen [I] Length of lpDstStr
2461 * The return value of the MultiByteToWideChar() function called on lpSrcStr.
2464 * This function simply calls SHAnsiToUnicodeCP with code page CP_ACP.
2466 DWORD WINAPI
SHAnsiToUnicode(LPCSTR lpSrcStr
, LPWSTR lpDstStr
, int iLen
)
2468 return SHAnsiToUnicodeCP(CP_ACP
, lpSrcStr
, lpDstStr
, iLen
);
2471 /*************************************************************************
2474 * Convert a Unicode string to Ascii.
2477 * CodePage [I] Code page to use for the conversion
2478 * lpSrcStr [I] Source Unicode string to convert
2479 * lpDstStr [O] Destination for converted Ascii string
2480 * lpiLen [I/O] Input length of lpDstStr/destination for length of lpDstStr
2483 * Success: The number of characters that result from the conversion.
2486 INT WINAPI
SHUnicodeToAnsiCP(UINT CodePage
, LPCWSTR lpSrcStr
, LPSTR lpDstStr
,
2489 static const WCHAR emptyW
[] = { '\0' };
2493 if (!lpDstStr
|| !lpiLen
)
2501 len
= strlenW(lpSrcStr
) + 1;
2506 CodePage
= CP_UTF8
; /* Fall through... */
2507 case 0x0000C350: /* FIXME: CP_ #define */
2512 INT nWideCharCount
= len
- 1;
2514 if (ConvertINetUnicodeToMultiByte(&dwMode
, CodePage
, lpSrcStr
,
2515 &nWideCharCount
, lpDstStr
,
2519 if (nWideCharCount
< len
- 1)
2521 mem
= HeapAlloc(GetProcessHeap(), 0, *lpiLen
);
2527 if (ConvertINetUnicodeToMultiByte(&dwMode
, CodePage
, lpSrcStr
, &len
,
2528 mem
, lpiLen
) != S_OK
)
2530 SHTruncateString(mem
, *lpiLen
);
2531 lstrcpynA(lpDstStr
, mem
, *lpiLen
+ 1);
2532 HeapFree(GetProcessHeap(), 0, mem
);
2535 HeapFree(GetProcessHeap(), 0, mem
);
2538 lpDstStr
[*lpiLen
] = '\0';
2545 reqLen
= WideCharToMultiByte(CodePage
, 0, lpSrcStr
, len
, lpDstStr
,
2546 *lpiLen
, NULL
, NULL
);
2548 if (!reqLen
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
2550 reqLen
= WideCharToMultiByte(CodePage
, 0, lpSrcStr
, len
, NULL
, 0, NULL
, NULL
);
2553 mem
= HeapAlloc(GetProcessHeap(), 0, reqLen
);
2556 reqLen
= WideCharToMultiByte(CodePage
, 0, lpSrcStr
, len
, mem
,
2557 reqLen
, NULL
, NULL
);
2559 reqLen
= SHTruncateString(mem
, *lpiLen
);
2562 lstrcpynA(lpDstStr
, mem
, *lpiLen
);
2564 HeapFree(GetProcessHeap(), 0, mem
);
2571 /*************************************************************************
2574 * Convert a Unicode string to Ascii.
2577 * lpSrcStr [I] Source Unicode string to convert
2578 * lpDstStr [O] Destination for converted Ascii string
2579 * iLen [O] Length of lpDstStr in characters
2582 * See SHUnicodeToAnsiCP
2585 * This function simply calls SHUnicodeToAnsiCP() with CodePage = CP_ACP.
2587 INT WINAPI
SHUnicodeToAnsi(LPCWSTR lpSrcStr
, LPSTR lpDstStr
, INT iLen
)
2591 return SHUnicodeToAnsiCP(CP_ACP
, lpSrcStr
, lpDstStr
, &myint
);
2594 /*************************************************************************
2597 * Copy one string to another.
2600 * lpszSrc [I] Source string to copy
2601 * lpszDst [O] Destination for copy
2602 * iLen [I] Length of lpszDst in characters
2605 * The length of the copied string, including the terminating NUL. lpszDst
2606 * contains iLen characters of lpszSrc.
2608 DWORD WINAPI
SHAnsiToAnsi(LPCSTR lpszSrc
, LPSTR lpszDst
, int iLen
)
2612 TRACE("(%s,%p,0x%08x)\n", debugstr_a(lpszSrc
), lpszDst
, iLen
);
2614 lpszRet
= StrCpyNXA(lpszDst
, lpszSrc
, iLen
);
2615 return lpszRet
- lpszDst
+ 1;
2618 /*************************************************************************
2621 * Unicode version of SSHAnsiToAnsi.
2623 DWORD WINAPI
SHUnicodeToUnicode(LPCWSTR lpszSrc
, LPWSTR lpszDst
, int iLen
)
2627 TRACE("(%s,%p,0x%08x)\n", debugstr_w(lpszSrc
), lpszDst
, iLen
);
2629 lpszRet
= StrCpyNXW(lpszDst
, lpszSrc
, iLen
);
2630 return lpszRet
- lpszDst
+ 1;
2633 /*************************************************************************
2636 * Determine if an Ascii string converts to Unicode and back identically.
2639 * lpSrcStr [I] Source Unicode string to convert
2640 * lpDst [O] Destination for resulting Ascii string
2641 * iLen [I] Length of lpDst in characters
2644 * TRUE, since Ascii strings always convert identically.
2646 BOOL WINAPI
DoesStringRoundTripA(LPCSTR lpSrcStr
, LPSTR lpDst
, INT iLen
)
2648 lstrcpynA(lpDst
, lpSrcStr
, iLen
);
2652 /*************************************************************************
2655 * Determine if a Unicode string converts to Ascii and back identically.
2658 * lpSrcStr [I] Source Unicode string to convert
2659 * lpDst [O] Destination for resulting Ascii string
2660 * iLen [I] Length of lpDst in characters
2663 * TRUE, if lpSrcStr converts to Ascii and back identically,
2666 BOOL WINAPI
DoesStringRoundTripW(LPCWSTR lpSrcStr
, LPSTR lpDst
, INT iLen
)
2668 WCHAR szBuff
[MAX_PATH
];
2670 SHUnicodeToAnsi(lpSrcStr
, lpDst
, iLen
);
2671 SHAnsiToUnicode(lpDst
, szBuff
, MAX_PATH
);
2672 return !strcmpW(lpSrcStr
, szBuff
);
2675 /*************************************************************************
2676 * SHLoadIndirectString [SHLWAPI.@]
2678 * If passed a string that begins with '@', extract the string from the
2679 * appropriate resource, otherwise do a straight copy.
2682 HRESULT WINAPI
SHLoadIndirectString(LPCWSTR src
, LPWSTR dst
, UINT dst_len
, void **reserved
)
2684 WCHAR
*dllname
= NULL
;
2685 HMODULE hmod
= NULL
;
2686 HRESULT hr
= E_FAIL
;
2688 TRACE("(%s %p %08x %p)\n", debugstr_w(src
), dst
, dst_len
, reserved
);
2696 dllname
= StrDupW(src
+ 1);
2697 index_str
= strchrW(dllname
, ',');
2699 if(!index_str
) goto end
;
2703 index
= atoiW(index_str
);
2705 hmod
= LoadLibraryW(dllname
);
2710 if(LoadStringW(hmod
, -index
, dst
, dst_len
))
2714 FIXME("can't handle non-negative indices (%d)\n", index
);
2719 lstrcpynW(dst
, src
, dst_len
);
2723 TRACE("returning %s\n", debugstr_w(dst
));
2725 if(hmod
) FreeLibrary(hmod
);
2726 HeapFree(GetProcessHeap(), 0, dllname
);