ItemNameUtils.cpp revision baa3858d3f5d128a5c8466b700098109edcad5f2
1// Archive/Common/ItemNameUtils.cpp 2 3#include "StdAfx.h" 4 5#include "../../../../C/Types.h" 6 7#include "ItemNameUtils.h" 8 9namespace NArchive { 10namespace NItemName { 11 12static const wchar_t kOSDirDelimiter = WCHAR_PATH_SEPARATOR; 13static const wchar_t kDirDelimiter = L'/'; 14 15UString MakeLegalName(const UString &name) 16{ 17 UString zipName = name; 18 zipName.Replace(kOSDirDelimiter, kDirDelimiter); 19 return zipName; 20} 21 22UString GetOSName(const UString &name) 23{ 24 UString newName = name; 25 newName.Replace(kDirDelimiter, kOSDirDelimiter); 26 return newName; 27} 28 29UString GetOSName2(const UString &name) 30{ 31 if (name.IsEmpty()) 32 return UString(); 33 UString newName = GetOSName(name); 34 if (newName[newName.Length() - 1] == kOSDirDelimiter) 35 newName.Delete(newName.Length() - 1); 36 return newName; 37} 38 39bool HasTailSlash(const AString &name, UINT codePage) 40{ 41 if (name.IsEmpty()) 42 return false; 43 LPCSTR prev = 44 #if defined(_WIN32) && !defined(UNDER_CE) 45 CharPrevExA((WORD)codePage, name, &name[name.Length()], 0); 46 #else 47 (LPCSTR)(name) + (name.Length() - 1); 48 #endif 49 return (*prev == '/'); 50} 51 52#ifndef _WIN32 53UString WinNameToOSName(const UString &name) 54{ 55 UString newName = name; 56 newName.Replace(L'\\', kOSDirDelimiter); 57 return newName; 58} 59#endif 60 61}} 62