1 // Archive/Common/ItemNameUtils.cpp 2 3 #include "StdAfx.h" 4 5 #include "ItemNameUtils.h" 6 7 namespace NArchive { 8 namespace NItemName { 9 10 static const wchar_t kOsPathSepar = WCHAR_PATH_SEPARATOR; 11 static const wchar_t kUnixPathSepar = L'/'; 12 ReplaceSlashes_OsToUnix(UString & name)13void ReplaceSlashes_OsToUnix 14 #if WCHAR_PATH_SEPARATOR != L'/' 15 (UString &name) 16 { 17 name.Replace(kOsPathSepar, kUnixPathSepar); 18 } 19 #else 20 (UString &) {} 21 #endif 22 23 GetOsPath(const UString & name)24UString GetOsPath(const UString &name) 25 { 26 #if WCHAR_PATH_SEPARATOR != L'/' 27 UString newName = name; 28 newName.Replace(kUnixPathSepar, kOsPathSepar); 29 return newName; 30 #else 31 return name; 32 #endif 33 } 34 35 GetOsPath_Remove_TailSlash(const UString & name)36UString GetOsPath_Remove_TailSlash(const UString &name) 37 { 38 if (name.IsEmpty()) 39 return UString(); 40 UString newName = GetOsPath(name); 41 if (newName.Back() == kOsPathSepar) 42 newName.DeleteBack(); 43 return newName; 44 } 45 46 ReplaceToOsSlashes_Remove_TailSlash(UString & name)47void ReplaceToOsSlashes_Remove_TailSlash(UString &name) 48 { 49 if (!name.IsEmpty()) 50 { 51 #if WCHAR_PATH_SEPARATOR != L'/' 52 name.Replace(kUnixPathSepar, kOsPathSepar); 53 #endif 54 55 if (name.Back() == kOsPathSepar) 56 name.DeleteBack(); 57 } 58 } 59 60 HasTailSlash(const AString & name,UINT codePage)61bool HasTailSlash(const AString &name, UINT 62 #if defined(_WIN32) && !defined(UNDER_CE) 63 codePage 64 #endif 65 ) 66 { 67 if (name.IsEmpty()) 68 return false; 69 char c = 70 #if defined(_WIN32) && !defined(UNDER_CE) 71 *CharPrevExA((WORD)codePage, name, name.Ptr(name.Len()), 0); 72 #else 73 name.Back(); 74 #endif 75 return (c == '/'); 76 } 77 78 79 #ifndef _WIN32 WinPathToOsPath(const UString & name)80UString WinPathToOsPath(const UString &name) 81 { 82 UString newName = name; 83 newName.Replace(L'\\', WCHAR_PATH_SEPARATOR); 84 return newName; 85 } 86 #endif 87 88 }} 89