1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/other-licenses/7zstub/src/Windows/FileName.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,111 @@ 1.4 +// Windows/FileName.cpp 1.5 + 1.6 +#include "StdAfx.h" 1.7 + 1.8 +#include "Windows/FileName.h" 1.9 +#include "Common/Wildcard.h" 1.10 + 1.11 +namespace NWindows { 1.12 +namespace NFile { 1.13 +namespace NName { 1.14 + 1.15 +static const wchar_t kDiskDelimiter = L':'; 1.16 + 1.17 +/* 1.18 +static bool IsCharAPrefixDelimiter(wchar_t c) 1.19 + { return (c == kDirDelimiter || c == kDiskDelimiter); } 1.20 +*/ 1.21 + 1.22 +void NormalizeDirPathPrefix(CSysString &dirPath) 1.23 +{ 1.24 + if (dirPath.IsEmpty()) 1.25 + return; 1.26 + if (dirPath.ReverseFind(kDirDelimiter) != dirPath.Length() - 1) 1.27 + dirPath += kDirDelimiter; 1.28 +} 1.29 + 1.30 +#ifndef _UNICODE 1.31 +void NormalizeDirPathPrefix(UString &dirPath) 1.32 +{ 1.33 + if (dirPath.IsEmpty()) 1.34 + return; 1.35 + if (dirPath.ReverseFind(wchar_t(kDirDelimiter)) != dirPath.Length() - 1) 1.36 + dirPath += wchar_t(kDirDelimiter); 1.37 +} 1.38 +#endif 1.39 + 1.40 +namespace NPathType 1.41 +{ 1.42 + EEnum GetPathType(const UString &path) 1.43 + { 1.44 + if (path.Length() <= 2) 1.45 + return kLocal; 1.46 + if (path[0] == kDirDelimiter && path[1] == kDirDelimiter) 1.47 + return kUNC; 1.48 + return kLocal; 1.49 + } 1.50 +} 1.51 + 1.52 +void CParsedPath::ParsePath(const UString &path) 1.53 +{ 1.54 + int curPos = 0; 1.55 + switch (NPathType::GetPathType(path)) 1.56 + { 1.57 + case NPathType::kLocal: 1.58 + { 1.59 + int posDiskDelimiter = path.Find(kDiskDelimiter); 1.60 + if(posDiskDelimiter >= 0) 1.61 + { 1.62 + curPos = posDiskDelimiter + 1; 1.63 + if (path.Length() > curPos) 1.64 + if(path[curPos] == kDirDelimiter) 1.65 + curPos++; 1.66 + } 1.67 + break; 1.68 + } 1.69 + case NPathType::kUNC: 1.70 + { 1.71 + int curPos = path.Find(kDirDelimiter, 2); 1.72 + if(curPos < 0) 1.73 + curPos = path.Length(); 1.74 + else 1.75 + curPos++; 1.76 + } 1.77 + } 1.78 + Prefix = path.Left(curPos); 1.79 + SplitPathToParts(path.Mid(curPos), PathParts); 1.80 +} 1.81 + 1.82 +UString CParsedPath::MergePath() const 1.83 +{ 1.84 + UString result = Prefix; 1.85 + for(int i = 0; i < PathParts.Size(); i++) 1.86 + { 1.87 + if (i != 0) 1.88 + result += kDirDelimiter; 1.89 + result += PathParts[i]; 1.90 + } 1.91 + return result; 1.92 +} 1.93 + 1.94 +const wchar_t kExtensionDelimiter = L'.'; 1.95 + 1.96 +void SplitNameToPureNameAndExtension(const UString &fullName, 1.97 + UString &pureName, UString &extensionDelimiter, UString &extension) 1.98 +{ 1.99 + int index = fullName.ReverseFind(kExtensionDelimiter); 1.100 + if (index < 0) 1.101 + { 1.102 + pureName = fullName; 1.103 + extensionDelimiter.Empty(); 1.104 + extension.Empty(); 1.105 + } 1.106 + else 1.107 + { 1.108 + pureName = fullName.Left(index); 1.109 + extensionDelimiter = kExtensionDelimiter; 1.110 + extension = fullName.Mid(index + 1); 1.111 + } 1.112 +} 1.113 + 1.114 +}}}