1 // Archive/Common/ItemNameUtils.cpp
2 
3 #include "StdAfx.h"
4 
5 #include "../../../../C/Types.h"
6 
7 #include "ItemNameUtils.h"
8 
9 namespace NArchive {
10 namespace NItemName {
11 
12 static const wchar_t kOSDirDelimiter = WCHAR_PATH_SEPARATOR;
13 static const wchar_t kDirDelimiter = L'/';
14 
MakeLegalName(const UString & name)15 UString MakeLegalName(const UString &name)
16 {
17   UString zipName = name;
18   zipName.Replace(kOSDirDelimiter, kDirDelimiter);
19   return zipName;
20 }
21 
GetOSName(const UString & name)22 UString GetOSName(const UString &name)
23 {
24   UString newName = name;
25   newName.Replace(kDirDelimiter, kOSDirDelimiter);
26   return newName;
27 }
28 
GetOSName2(const UString & name)29 UString 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 
HasTailSlash(const AString & name,UINT codePage)39 bool 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
WinNameToOSName(const UString & name)53 UString WinNameToOSName(const UString &name)
54 {
55   UString newName = name;
56   newName.Replace(L'\\', kOSDirDelimiter);
57   return newName;
58 }
59 #endif
60 
61 }}
62