Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cFilePath.h
Go to the documentation of this file.
1 //
5 
6 #ifndef _INC_cFilePath_H
7 #define _INC_cFilePath_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cString.h"
13 #include "FileName.h"
14 
15 namespace Gray
16 {
17  UNITTEST2_PREDEF(cFilePath);
18 
20 
22  {
26 
33  };
34 
36  {
40 
42 
43  FILECHR_Device = 0x01,
44  FILECHR_Dirs = 0x02,
45 
46  FILECHR_Name = 0x04,
47  FILECHR_Name2 = 0x08,
48  FILECHR_Name3 = 0x10,
49  FILECHR_Ext = 0x20,
50 
51  FILECHR_XPath = 0x3E,
52  FILECHR_All = 0x3F,
53 
55  };
56  typedef WORD FILECHR_MASK_t;
57 
59  {
66 
67  public:
68  static const StrLen_t k_MaxLen = _MAX_PATH;
69  static const FILECHAR_t k_DirSep1 = '/';
70  static const FILECHAR_t k_DirSep2 = '\\';
71 
72 #ifdef _WIN32
73  static const FILECHAR_t k_DirSep = '\\';
74 #define FILESTR_DirSep "\\"
75 #else
76  static const FILECHAR_t k_DirSep = '/';
77 #define FILESTR_DirSep "/"
78 #endif
79 
80 #ifdef _WIN32
81  static const FILECHAR_t k_NamePrefix[5];
82 #endif
83 
84  public:
85  static inline constexpr bool IsCharDirSep(wchar_t ch) noexcept
86  {
89  return ch == k_DirSep1 || ch == k_DirSep2;
90  }
91  static inline constexpr bool IsCharWildcard(wchar_t ch) noexcept
92  {
94  return ch == '?' || ch == '*';
95  }
96 
97  static FILECHR_TYPE_ GRAYCALL GetFileCharType(wchar_t ch, FILESYS_TYPE eSys = FILESYS_DEFAULT);
98  static bool GRAYCALL IsFileNameValid(const FILECHAR_t* pszName, FILECHR_MASK_t uCharMask = FILECHR_All, FILESYS_TYPE eSys = FILESYS_DEFAULT);
99  static bool GRAYCALL IsFileNameExt(const FILECHAR_t* pszFileName, const FILECHAR_t* pszExt) noexcept;
100  static bool GRAYCALL HasTitleWildcards(const FILECHAR_t* pszPath);
101 
102  static FILECHAR_t* GRAYCALL GetFileNameExt(const FILECHAR_t* pszName, StrLen_t iLen = k_StrLen_UNK, bool bMultiDot = false);
103  static StrLen_t GRAYCALL StripFileExt(FILECHAR_t* pszFile, StrLen_t iLen, bool bMultiDot = false);
104  static cStringF GRAYCALL ReplaceFileExt(const FILECHAR_t* pszFilePath, const FILECHAR_t* pszExtNew); // ChangeExtension
105  static cStringF GRAYCALL GetNameExtStar(const FILECHAR_t* pszFilePath);
106 
107  static FILECHAR_t* GRAYCALL GetFileName(const FILECHAR_t* pszPath, StrLen_t iLenPath = k_StrLen_UNK);
108  static cStringF GRAYCALL GetFileNameNE(const FILECHAR_t* pszPath, StrLen_t iLenPath = k_StrLen_UNK, bool bMultiDot = false);
109 
110  static StrLen_t GRAYCALL MakeFileSymbolicName(ATOMCHAR_t* pszOut, const FILECHAR_t* pszPath, const ATOMCHAR_t* pszPrefix = nullptr, ATOMCHAR_t chSub = '_', bool bAllowLeadingNumber = false);
111  static cStringA GRAYCALL GetFileSymbolicName(const FILECHAR_t* pszPath, const ATOMCHAR_t* pszPrefix = nullptr, ATOMCHAR_t chSub = '_', bool bAllowLeadingNumber = false);
112 
113  static StrLen_t GRAYCALL MakeFullPath2(FILECHAR_t* pszFileOut, const FILECHAR_t* pszFileInp, StrLen_t iLenMax, FILECHAR_t chSep = k_DirSep);
114  static StrLen_t GRAYCALL MakeFullPath(FILECHAR_t* pszFileOut, const FILECHAR_t* pszFileInp, StrLen_t iLenMax, FILECHAR_t chSep = k_DirSep);
115  static cStringF GRAYCALL MakeFullPathX(const FILECHAR_t* pszFileInp, FILECHAR_t chSep = k_DirSep);
116 
117  static StrLen_t GRAYCALL MakeProperPath(FILECHAR_t* pszFileOut, StrLen_t iLenMax = _MAX_PATH, const FILECHAR_t* pszFileInp = nullptr, FILECHAR_t chSep = k_DirSep);
118  static cStringF GRAYCALL MakeProperPathX(const FILECHAR_t* pszFileInp, FILECHAR_t chSep = k_DirSep);
119  static StrLen_t GRAYCALL AddFileDirSep(FILECHAR_t* pszOut, StrLen_t iLen = k_StrLen_UNK, FILECHAR_t chSep = k_DirSep);
120  static StrLen_t GRAYCALL CombineFilePathA(FILECHAR_t* pszOut, StrLen_t iLenMax, StrLen_t iLen, const FILECHAR_t* pszName, FILECHAR_t chSep = k_DirSep);
121  static StrLen_t GRAYCALL CombineFilePath(FILECHAR_t* pszFilePathOut, StrLen_t iLenMax, const FILECHAR_t* pszDir, const FILECHAR_t* pszName, FILECHAR_t chSep = k_DirSep); // .NET Combine
122  static cStringF GRAYCALL CombineFilePathX(const FILECHAR_t* pszBase, const FILECHAR_t* pszName, FILECHAR_t chSep = k_DirSep);
123  static cStringF _cdecl CombineFilePathF(FILECHAR_t chSep, const FILECHAR_t* pszBase, ...);
124 
125  static StrLen_t GRAYCALL ExtractDir(FILECHAR_t* pszPath, StrLen_t iLen = k_StrLen_UNK, bool bTrailingSep = true);
126  static StrLen_t GRAYCALL ExtractDirCopy(FILECHAR_t* pszDirPath, StrLen_t iLenMax, const FILECHAR_t* pszFilePathSrc, bool bTrailingSep = true);
127  static cStringF GRAYCALL GetFileDir(const FILECHAR_t* pszFilePath, bool bTrailingSep = true);
128 
129  static bool GRAYCALL IsRelativeRoot(const FILECHAR_t* pszFullPath, const FILECHAR_t* pszRootDir, StrLen_t iLen = k_StrLen_UNK);
130  static bool GRAYCALL IsRelativePath(const FILECHAR_t* pszFullPath, const FILECHAR_t* pszRelativePath);
131  static cStringF GRAYCALL MakeRelativePath(const FILECHAR_t* pszFullPath, const FILECHAR_t* pszRootDir);
132 
133  static StrLen_t GRAYCALL GetFilePathDeviceLen(const FILECHAR_t* pszNameRoot);
134  static bool GRAYCALL IsFileDeviceRemote(const FILECHAR_t* pszPath);
135  static bool GRAYCALL IsFilePathRooted(const FILECHAR_t* pszName); // .NET IsPathRooted
136  static bool GRAYCALL IsFilePathRoot(const FILECHAR_t* pszName);
137  static bool GRAYCALL IsFilePathTitle(const FILECHAR_t* pszName);
138  static bool GRAYCALL HasFilePathRelatives(const FILECHAR_t* pszName, bool bOrDevices = true);
139 
140  static FILECHAR_t* GRAYCALL SkipRelativePrefix(const FILECHAR_t* pszName);
141  static FILECHAR_t* GRAYCALL GetFilePathUpDir2(const FILECHAR_t* pszName, StrLen_t iLen = k_StrLen_UNK, int iQtyDirs = 1);
142  static cStringF GRAYCALL GetFilePathUpDir1(const FILECHAR_t* pszName, StrLen_t iLen = k_StrLen_UNK, int iQtyDirs = 1);
143  static bool GRAYCALL MakeFilePathUpDir(FILECHAR_t* pszName);
144 
146  static COMPARE_t GRAYCALL ComparePath(const FILECHAR_t* pszPath1, const FILECHAR_t* pszPath2, StrLen_t iLenMax = _MAX_PATH);
147 
148 #ifdef _WIN32
149  static const wchar_t* GRAYCALL MakeFileNameLongW(const FILECHAR_t* pszFilePath);
150  static const wchar_t* GRAYCALL GetFileNameLongW(cStringF sFilePath);
151  static const wchar_t* GRAYCALL GetFileNameLongW(const FILECHAR_t* pszFileName);
152 #endif
153 
155  };
156 
157 };
158 #endif // _INC_cFilePath_H
#define GRAYCORE_LINK
Definition: GrayCore.h:47
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define _MAX_PATH
Definition: SysTypes.h:423
#define UNITTEST2_PREDEF(x)
Definition: cUnitTestDecl.h:19
#define UNITTEST_FRIEND(n)
Define this in the class body to be unit tested. Allow the unit test to access private/protected stuf...
Definition: cUnitTestDecl.h:17
Definition: cFilePath.h:59
static constexpr bool IsCharDirSep(wchar_t ch) noexcept
Definition: cFilePath.h:85
static constexpr bool IsCharWildcard(wchar_t ch) noexcept
Definition: cFilePath.h:91
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
int COMPARE_t
result of compare. 0=same, 1=a>b, -1=a<b
Definition: cValT.h:17
const StrLen_t k_StrLen_UNK
use the default/current length of the string argument.
Definition: StrConst.h:34
int StrLen_t
the length of a string in chars (bytes for UTF8, wchar_t for UNICODE). or offset in characters....
Definition: StrConst.h:32
cStringT< FILECHAR_t > cStringF
A file name. checks USE_UNICODE_FN. related to cFilePath.
Definition: cFilePath.h:17
WORD FILECHR_MASK_t
Mask of enum FILECHR_TYPE_.
Definition: cFilePath.h:56
char FILECHAR_t
a UTF8 char in a file name. like TCHAR
Definition: FileName.h:22
char ATOMCHAR_t
the char form (UNICODE or not) for an atom. (for symbolic names)
Definition: StrConst.h:15
FILECHR_TYPE_
Definition: cFilePath.h:36
@ FILECHR_Name3
Char is part of name but is foreign char. UNICODE.
Definition: cFilePath.h:48
@ FILECHR_Name
Char is valid as part of a FILESYS_TYPE file name.
Definition: cFilePath.h:46
@ FILECHR_Name2
Char is part of name but not in base set. "spaces, <, >, |, \, and sometimes :, (,...
Definition: cFilePath.h:47
@ FILECHR_XPath
mask for path but NOT Volume/drive. good for FTP
Definition: cFilePath.h:51
@ FILECHR_Device
Volume: designators (drive letters) or device ? "a:" or "com1:".
Definition: cFilePath.h:43
@ FILECHR_Ext
File type extension. '.' for ".txt".
Definition: cFilePath.h:49
@ FILECHR_Invalid
not a valid char.
Definition: cFilePath.h:41
@ FILECHR_All
mask for any (including Volume/drive). but not wildcard.
Definition: cFilePath.h:52
@ FILECHR_Wildcard
"?*" = allow wildcards in the name.
Definition: cFilePath.h:54
@ FILECHR_Dirs
FILECHAR_IsDirSep, the directory path to the file. may have relatives "..".
Definition: cFilePath.h:44
FILESYS_TYPE
Definition: cFilePath.h:22
@ FILESYS_FAT32
Allow spaces and ~1 equivalent names. long names.
Definition: cFilePath.h:29
@ FILESYS_FAT
Old DOS 8.3 names. Most restrictive of chars allowed.
Definition: cFilePath.h:28
@ FILESYS_DEFAULT
Modern OS's. >= FILESYS_FAT32.
Definition: cFilePath.h:27
@ FILESYS_NFS
Linux names are case sensitive. typical for FTP or HTTP mounted files.
Definition: cFilePath.h:31
@ FILESYS_NTFS
Allow long names, spaces and ~1 equivalent names + extra Attributes.
Definition: cFilePath.h:30
@ FILESYS_QTY
Definition: cFilePath.h:32