Changeset 25923 in vbox for trunk/src/VBox
- Timestamp:
- Jan 20, 2010 11:06:27 AM (15 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/path/RTPathStripTrailingSlash.cpp
r21673 r25923 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Sun Microsystems, Inc.7 * Copyright (C) 2006-2010 Sun Microsystems, Inc. 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 36 36 #include <iprt/path.h> 37 37 #include <iprt/string.h> 38 #include <iprt/ctype.h> 38 39 39 40 40 41 41 /** 42 * Strips the trailing slashes of a path name. 43 * 44 * @param pszPath Path to strip. 45 * 46 * @todo This isn't safe for a root element! Needs fixing. 47 */ 48 RTDECL(void) RTPathStripTrailingSlash(char *pszPath) 42 RTDECL(size_t) RTPathStripTrailingSlash(char *pszPath) 49 43 { 50 char *pszEnd = strchr(pszPath, '\0');51 while ( pszEnd-- > pszPath)44 size_t off = strlen(pszPath); 45 while (off > 1) 52 46 { 53 switch (*pszEnd) 47 off--; 48 switch (pszPath[off]) 54 49 { 55 50 case '/': 56 51 #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2) 57 52 case '\\': 53 if ( off == 2 54 && pszPath[1] == ':' 55 && RT_C_IS_ALPHA(pszPath[0])) 56 return cch + 1; 58 57 #endif 59 *pszEnd= '\0';58 pszPath[off] = '\0'; 60 59 break; 60 61 61 default: 62 return ;62 return off + 1; 63 63 } 64 64 } 65 return; 65 66 return 1; 66 67 } 67 68 -
trunk/src/VBox/Runtime/testcase/tstPath.cpp
r25000 r25923 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Sun Microsystems, Inc.7 * Copyright (C) 2006-2010 Sun Microsystems, Inc. 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 330 330 } 331 331 332 332 /* 333 * RTPathStripTrailingSlash 334 */ 335 static const char *s_apszStripTrailingSlash[] = 336 { 337 /* input result */ 338 "/", "/", 339 "//", "/", 340 "////////////////////", "/", 341 "/tmp", "/tmp", 342 "/tmp////////////////", "/tmp", 343 "tmp", "tmp", 344 "tmp////////////////", "tmp", 345 "./", ".", 346 #if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS) 347 "////////////////////", "/", 348 "D:", "D:", 349 "D:/", "D:/", 350 "D:\\", "D:\\", 351 "D:\\/\\", "D:\\", 352 "D:/\\/\\", "D:/", 353 "C:/Temp", "D:/Temp", 354 "C:/Temp/", "D:/Temp/", 355 "C:/Temp\\/", "D:/Temp", 356 #endif 357 }; 358 for (unsigned i = 0; i < RT_ELEMENTS(s_apszStripTrailingSlash); i += 2) 359 { 360 const char *pszInput = s_apszStripTrailingSlash[i]; 361 const char *pszExpect = s_apszStripTrailingSlash[i + 1]; 362 363 strcpy(szPath, pszInput); 364 cch = RTPathStripTrailingSlash(szPath); 365 if (strcmp(szPath, pszExpect)) 366 RTTestIFailed("Unexpected result\n" 367 " input: '%s'\n" 368 " output: '%s'\n" 369 "expected: '%s'", 370 pszInput, szPath, pszExpect); 371 else 372 RTTESTI_CHECK(cch == strlen(szPath)); 373 } 333 374 334 375 /*
Note:
See TracChangeset
for help on using the changeset viewer.