• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 kOSDirDelimiter = WCHAR_PATH_SEPARATOR;
11 static const wchar_t kDirDelimiter = L'/';
12 
ReplaceToOsPathSeparator(wchar_t * s)13 void ReplaceToOsPathSeparator(wchar_t *s)
14 {
15   #ifdef _WIN32
16   for (;;)
17   {
18     wchar_t c = *s;
19     if (c == 0)
20       break;
21     if (c == kDirDelimiter)
22       *s = kOSDirDelimiter;
23     s++;
24   }
25   #endif
26 }
27 
MakeLegalName(const UString & name)28 UString MakeLegalName(const UString &name)
29 {
30   UString zipName = name;
31   zipName.Replace(kOSDirDelimiter, kDirDelimiter);
32   return zipName;
33 }
34 
GetOSName(const UString & name)35 UString GetOSName(const UString &name)
36 {
37   UString newName = name;
38   newName.Replace(kDirDelimiter, kOSDirDelimiter);
39   return newName;
40 }
41 
GetOSName2(const UString & name)42 UString GetOSName2(const UString &name)
43 {
44   if (name.IsEmpty())
45     return UString();
46   UString newName = GetOSName(name);
47   if (newName.Back() == kOSDirDelimiter)
48     newName.DeleteBack();
49   return newName;
50 }
51 
ConvertToOSName2(UString & name)52 void ConvertToOSName2(UString &name)
53 {
54   if (!name.IsEmpty())
55   {
56     name.Replace(kDirDelimiter, kOSDirDelimiter);
57     if (name.Back() == kOSDirDelimiter)
58       name.DeleteBack();
59   }
60 }
61 
HasTailSlash(const AString & name,UINT codePage)62 bool HasTailSlash(const AString &name, UINT
63   #if defined(_WIN32) && !defined(UNDER_CE)
64     codePage
65   #endif
66   )
67 {
68   if (name.IsEmpty())
69     return false;
70   LPCSTR prev =
71   #if defined(_WIN32) && !defined(UNDER_CE)
72     CharPrevExA((WORD)codePage, name, &name[name.Len()], 0);
73   #else
74     (LPCSTR)(name) + (name.Len() - 1);
75   #endif
76   return (*prev == '/');
77 }
78 
79 #ifndef _WIN32
WinNameToOSName(const UString & name)80 UString WinNameToOSName(const UString &name)
81 {
82   UString newName = name;
83   newName.Replace(L'\\', kOSDirDelimiter);
84   return newName;
85 }
86 #endif
87 
88 }}
89