Welcome to mirror list, hosted at ThFree Co, Russian Federation.

pathmix.hpp « mix « src « far2l - github.com/elfmz/far2l.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9f57649921e62ff08d48ede8be15130457bb8d03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#pragma once

/*
pathmix.hpp

Misc functions for processing of path names
*/
/*
Copyright (c) 1996 Eugene Roshal
Copyright (c) 2000 Far Group
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
3. The name of the authors may not be used to endorse or promote products
   derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "FARString.hpp"

const size_t cVolumeGuidLen = 48;

class NTPath
{
		FARString Str;
	public:
		NTPath(LPCWSTR Src);

		operator LPCWSTR() const
		{
			return Str;
		}

		const FARString Get() const
		{
			return Str;
		}
};

inline int IsSlash(wchar_t x) { return x==GOOD_SLASH; }
inline int IsSlashA(char x) { return x==GOOD_SLASH; }

bool IsNetworkPath(const wchar_t *Path);
bool IsNetworkServerPath(const wchar_t *Path);
bool IsLocalPath(const wchar_t *Path);
bool IsLocalRootPath(const wchar_t *Path);
bool IsLocalPrefixPath(const wchar_t *Path);
bool IsLocalPrefixRootPath(const wchar_t *Path);
bool IsLocalVolumePath(const wchar_t *Path);
bool IsLocalVolumeRootPath(const wchar_t *Path);
bool IsAbsolutePath(const wchar_t *Path);
bool IsRootPath(const FARString &Path);
bool HasPathPrefix(const wchar_t *Path);
bool PathCanHoldRegularFile(const wchar_t *Path);
bool IsPluginPrefixPath(const wchar_t *Path);

bool CutToSlash(FARString &strStr, bool bInclude = false);
bool CutToSlash(std::wstring &strStr, bool bInclude = false);

FARString &CutToFolderNameIfFolder(FARString &strPath);

const wchar_t* WINAPI PointToName(const wchar_t *lpwszPath);
const wchar_t* PointToName(FARString &strPath);
const wchar_t* PointToName(const wchar_t *lpwszPath,const wchar_t *lpwszEndPtr);
const wchar_t* WINAPI PointToFolderNameIfFolder(const wchar_t *lpwszPath);
const wchar_t* PointToExt(const wchar_t *lpwszPath);
const wchar_t* PointToExt(FARString& strPath);
const wchar_t* PointToExt(const wchar_t *lpwszPath,const wchar_t *lpwszEndPtr);

void AddEndSlash(FARString &strPath);
void AddEndSlash(std::wstring &strPath);
BOOL WINAPI AddEndSlash(wchar_t *Path);

bool DeleteEndSlash(wchar_t* Path, bool AllEndSlash = false);
BOOL DeleteEndSlash(std::wstring &strPath,bool AllEndSlash = false);
BOOL DeleteEndSlash(FARString &strPath,bool AllEndSlash = false);

const wchar_t *FirstSlash(const wchar_t *String);
const wchar_t *LastSlash(const wchar_t *String);
bool FindSlash(size_t &Pos, const FARString &Str, size_t StartPos = 0);
bool FindLastSlash(size_t &Pos, const FARString &Str);

bool TestParentFolderName(const wchar_t *Name);
bool TestCurrentFolderName(const wchar_t *Name);
bool TestCurrentDirectory(const wchar_t *TestDir);

FARString ExtractFileName(const FARString &Path);
FARString ExtractFilePath(const FARString &Path);

template < bool (*PTranslateFN)(std::wstring &s) > 
	static bool TranslateFarString(FARString &str)
{
	std::wstring tmp(str.CPtr(), str.GetLength());
	if ( !PTranslateFN(tmp))
		return false;
		
	str.Copy(tmp.c_str(), tmp.size());
	return true;
}

FARString LookupExecutable(const char *file);

bool PathHasParentPrefix(const FARString &Path);
void EnsurePathHasParentPrefix(FARString &Path);