tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ItemNameUtils.cpp (1697B)


      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 
     13 void 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 
     24 UString 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 
     36 UString 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 
     47 void 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 
     61 bool 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
     80 UString WinPathToOsPath(const UString &name)
     81 {
     82  UString newName = name;
     83  newName.Replace(L'\\', WCHAR_PATH_SEPARATOR);
     84  return newName;
     85 }
     86 #endif
     87 
     88 }}