mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 23:42:57 +00:00
[SHLWAPI][WINESYNC] Import PathRemoveBlanks wine fix + adaptation for ReactOS (#7636)
kernelbase: Always remove trailing spaces in PathRemoveBlanks. Signed-off-by: Esme Povirk <esme@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 404cd8a92bd99332a7ef8ec96edbf5aeea8cab76 by Esme Povirk <esme@codeweavers.com> Co-authored-by: Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
This commit is contained in:
parent
f189d8c454
commit
848ad61bba
2 changed files with 77 additions and 26 deletions
|
@ -891,25 +891,28 @@ LPWSTR WINAPI PathRemoveBackslashW( LPWSTR lpszPath )
|
||||||
* RETURNS
|
* RETURNS
|
||||||
* Nothing.
|
* Nothing.
|
||||||
*/
|
*/
|
||||||
VOID WINAPI PathRemoveBlanksA(LPSTR lpszPath)
|
void WINAPI PathRemoveBlanksA(LPSTR pszPath)
|
||||||
{
|
{
|
||||||
TRACE("(%s)\n", debugstr_a(lpszPath));
|
LPSTR start, first;
|
||||||
|
|
||||||
if(lpszPath && *lpszPath)
|
TRACE("(%s)\n", debugstr_a(pszPath));
|
||||||
{
|
|
||||||
LPSTR start = lpszPath;
|
|
||||||
|
|
||||||
while (*lpszPath == ' ')
|
if (!pszPath || !*pszPath)
|
||||||
lpszPath = CharNextA(lpszPath);
|
return;
|
||||||
|
|
||||||
while(*lpszPath)
|
start = first = pszPath;
|
||||||
*start++ = *lpszPath++;
|
|
||||||
|
while (*pszPath == ' ')
|
||||||
|
pszPath = CharNextA(pszPath);
|
||||||
|
|
||||||
|
while (*pszPath)
|
||||||
|
*start++ = *pszPath++;
|
||||||
|
|
||||||
|
if (start != first)
|
||||||
|
while (start[-1] == ' ')
|
||||||
|
start--;
|
||||||
|
|
||||||
if (start != lpszPath)
|
|
||||||
while (start[-1] == ' ')
|
|
||||||
start--;
|
|
||||||
*start = '\0';
|
*start = '\0';
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
|
@ -917,25 +920,28 @@ VOID WINAPI PathRemoveBlanksA(LPSTR lpszPath)
|
||||||
*
|
*
|
||||||
* See PathRemoveBlanksA.
|
* See PathRemoveBlanksA.
|
||||||
*/
|
*/
|
||||||
VOID WINAPI PathRemoveBlanksW(LPWSTR lpszPath)
|
void WINAPI PathRemoveBlanksW(LPWSTR pszPath)
|
||||||
{
|
{
|
||||||
TRACE("(%s)\n", debugstr_w(lpszPath));
|
LPWSTR start, first;
|
||||||
|
|
||||||
if(lpszPath && *lpszPath)
|
TRACE("(%s)\n", debugstr_w(pszPath));
|
||||||
{
|
|
||||||
LPWSTR start = lpszPath;
|
|
||||||
|
|
||||||
while (*lpszPath == ' ')
|
if (!pszPath || !*pszPath)
|
||||||
lpszPath++;
|
return;
|
||||||
|
|
||||||
while(*lpszPath)
|
start = first = pszPath;
|
||||||
*start++ = *lpszPath++;
|
|
||||||
|
while (*pszPath == ' ')
|
||||||
|
pszPath++;
|
||||||
|
|
||||||
|
while (*pszPath)
|
||||||
|
*start++ = *pszPath++;
|
||||||
|
|
||||||
|
if (start != first)
|
||||||
|
while (start[-1] == ' ')
|
||||||
|
start--;
|
||||||
|
|
||||||
if (start != lpszPath)
|
|
||||||
while (start[-1] == ' ')
|
|
||||||
start--;
|
|
||||||
*start = '\0';
|
*start = '\0';
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
|
|
|
@ -1712,6 +1712,50 @@ static void test_PathUndecorate(void)
|
||||||
PathUndecorateW(NULL);
|
PathUndecorateW(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_PathRemoveBlanks(void)
|
||||||
|
{
|
||||||
|
struct remove_blanks_test {
|
||||||
|
const char* input;
|
||||||
|
const char* expected;
|
||||||
|
};
|
||||||
|
struct remove_blanks_test tests[] = {
|
||||||
|
{"", ""},
|
||||||
|
{" ", ""},
|
||||||
|
{"test", "test"},
|
||||||
|
{" test", "test"},
|
||||||
|
{" test", "test"},
|
||||||
|
{"test ", "test"},
|
||||||
|
{"test ", "test"},
|
||||||
|
{" test ", "test"},
|
||||||
|
{" test ", "test"}};
|
||||||
|
char pathA[MAX_PATH];
|
||||||
|
WCHAR pathW[MAX_PATH];
|
||||||
|
int i, ret;
|
||||||
|
const UINT CP_ASCII = 20127;
|
||||||
|
|
||||||
|
PathRemoveBlanksW(NULL);
|
||||||
|
PathRemoveBlanksA(NULL);
|
||||||
|
|
||||||
|
for (i=0; i < ARRAY_SIZE(tests); i++)
|
||||||
|
{
|
||||||
|
strcpy(pathA, tests[i].input);
|
||||||
|
PathRemoveBlanksA(pathA);
|
||||||
|
ok(strcmp(pathA, tests[i].expected) == 0, "input string '%s', expected '%s', got '%s'\n",
|
||||||
|
tests[i].input, tests[i].expected, pathA);
|
||||||
|
|
||||||
|
ret = MultiByteToWideChar(CP_ASCII, MB_ERR_INVALID_CHARS, tests[i].input, -1, pathW, MAX_PATH);
|
||||||
|
ok(ret != 0, "MultiByteToWideChar failed for '%s'\n", tests[i].input);
|
||||||
|
|
||||||
|
PathRemoveBlanksW(pathW);
|
||||||
|
|
||||||
|
ret = WideCharToMultiByte(CP_ASCII, 0, pathW, -1, pathA, MAX_PATH, NULL, NULL);
|
||||||
|
ok(ret != 0, "WideCharToMultiByte failed for %s from test string '%s'\n", wine_dbgstr_w(pathW), tests[i].input);
|
||||||
|
|
||||||
|
ok(strcmp(pathA, tests[i].expected) == 0, "input string '%s', expected '%s', got '%s'\n",
|
||||||
|
tests[i].input, tests[i].expected, pathA);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
START_TEST(path)
|
START_TEST(path)
|
||||||
{
|
{
|
||||||
HMODULE hShlwapi = GetModuleHandleA("shlwapi.dll");
|
HMODULE hShlwapi = GetModuleHandleA("shlwapi.dll");
|
||||||
|
@ -1759,4 +1803,5 @@ START_TEST(path)
|
||||||
test_PathIsRelativeW();
|
test_PathIsRelativeW();
|
||||||
test_PathStripPathA();
|
test_PathStripPathA();
|
||||||
test_PathUndecorate();
|
test_PathUndecorate();
|
||||||
|
test_PathRemoveBlanks();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue