EpcTools
An event based multi-threaded C++ development framework.
epath.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2009-2019 Brian Waters
3 * Copyright (c) 2019 Sprint
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 
18 #ifndef __epath_h_included
19 #define __epath_h_included
20 
23 
24 #include "ebase.h"
25 #include "estring.h"
26 #include "eerror.h"
27 
29 DECLARE_ERROR_ADVANCED4(EPathError_ArgumentException);
30 DECLARE_ERROR_ADVANCED3(EPathError_VerifyCreatePath);
31 DECLARE_ERROR_ADVANCED4(EPathError_VerifyNotDirectory);
33 
35 class EPath
36 {
37 public:
40  static cpStr getDirectorySeparatorString();
41 
44  static cChar getDirectorySeparatorChar();
47  static cChar getAltDirectorySeparatorChar();
50  static cChar getVolumeSeparatorChar();
51 
54  static cpStr getPathSeparatorChars();
57  static cpStr getInvalidPathChars();
60  static cpStr getInvalidFileNameChars();
61 
66  static Void changeExtension(cpStr path, cpStr extension, EString &newPath);
67 
74  static Void combine(cpStr path1, cpStr path2, cpStr path3, cpStr path4, EString &path);
80  static Void combine(cpStr path1, cpStr path2, cpStr path3, EString &path);
85  static Void combine(cpStr path1, cpStr path2, EString &path);
92  static EString combine(cpStr path1, cpStr path2, cpStr path3, cpStr path4);
98  static EString combine(cpStr path1, cpStr path2, cpStr path3);
103  static EString combine(cpStr path1, cpStr path2);
104 
108  static Void verify(cpStr path, mode_t mode = 0777);
109 
113  static Void getDirectoryName(cpStr path, EString &dirName);
117  static Void getExtension(cpStr path, EString &ext);
121  static Void getFileName(cpStr path, EString &fileName);
125  static Void getFileNameWithoutExtension(cpStr path, EString &fileName);
129  static Void getPathRoot(cpStr path, EString &root);
130 
134  static EString getDirectoryName(cpStr path) { EString s; getDirectoryName(path, s); return s; }
138  static EString getExtension(cpStr path) { EString s; getExtension(path, s); return s; }
142  static EString getFileName(cpStr path) { EString s; getFileName(path, s); return s; }
146  static EString getFileNameWithoutExtension(cpStr path) { EString s; getFileNameWithoutExtension(path, s); return s; }
150  static EString getPathRoot(cpStr path) { EString s; getPathRoot(path, s); return s; }
151 
152 private:
153  static Bool m_dirEqualsVolume;
154 
155  static Void cleanPath(cpStr path, EString &cleanPath);
156  static Void insecureFullPath(cpStr path, EString &fullPath);
157  static Bool isDsc(cChar c);
158  static Bool isPathRooted(cpStr path);
159  static Int findExtension(cpStr path);
160 };
161 
164 {
165  return "/";
166 }
167 
169 {
170  return '/';
171 }
172 
174 {
175  return '/';
176 }
177 
178 inline cChar EPath::getVolumeSeparatorChar()
179 {
180  return ':';
181 }
182 
183 inline cpStr EPath::getPathSeparatorChars()
184 {
185  return "/:";
186 }
187 
188 inline cpStr EPath::getInvalidPathChars()
189 {
190  return "";
191 }
192 
193 inline cpStr EPath::getInvalidFileNameChars()
194 {
195  return "/";
196 }
197 
198 inline Bool EPath::isDsc(cChar c)
199 {
201 }
203 
204 #endif // #define __epath_h_included
static cChar getDirectorySeparatorChar()
Retrieves the directory separator character.
static Void getDirectoryName(cpStr path, EString &dirName)
Retrieves the directory name from a file name.
Definition: epath.cpp:178
Encapsulates and extends a std::string object.
#define DECLARE_ERROR_ADVANCED4(__e__)
Declares exception class derived from EError with an const char* as a constructor parameter and devel...
Definition: eerror.h:85
Macros for various standard C library functions and standard includes.
static Void getFileNameWithoutExtension(cpStr path, EString &fileName)
Retrieves the file name without any extension.
Definition: epath.cpp:247
static Void combine(cpStr path1, cpStr path2, cpStr path3, cpStr path4, EString &path)
Combines individual path names into a single path name.
Definition: epath.cpp:128
static EString getFileName(cpStr path)
Retrieves just the file name from a fully qualified file name.
Definition: epath.h:142
static Void verify(cpStr path, mode_t mode=0777)
Verifies that a path exists, creating directories as needed.
Definition: epath.cpp:155
static Void getExtension(cpStr path, EString &ext)
Retrieves the extension of a file name.
Definition: epath.cpp:202
static Void getPathRoot(cpStr path, EString &root)
Retrieves the path root.
Definition: epath.cpp:253
static EString getPathRoot(cpStr path)
Retrieves the path root.
Definition: epath.h:150
static EString getExtension(cpStr path)
Retrieves the extension of a file name.
Definition: epath.h:138
static Void changeExtension(cpStr path, cpStr extension, EString &newPath)
Changes the extension of an exist path name.
Definition: epath.cpp:51
#define DECLARE_ERROR_ADVANCED3(__e__)
Declares exception class derived from EError with an Int and a const char * as constructor parameters...
Definition: eerror.h:77
Defines base class for exceptions and declaration helper macros.
static cChar getAltDirectorySeparatorChar()
Retrieves the alternate directory separator character.
static cpStr getDirectorySeparatorString()
Retrieves the directory separator string.
static cpStr getInvalidFileNameChars()
Retrieves the invalid file name characters.
static cpStr getPathSeparatorChars()
Retrieves the path separator characters.
static EString getDirectoryName(cpStr path)
Retrieves the directory name from a file name.
Definition: epath.h:134
static cpStr getInvalidPathChars()
Retrieves the invalid path characters.
static cChar getVolumeSeparatorChar()
Retrieves the volume separator character.
static Void getFileName(cpStr path, EString &fileName)
Retrieves just the file name from a fully qualified file name.
Definition: epath.cpp:229
static EString getFileNameWithoutExtension(cpStr path)
Retrieves the file name without any extension.
Definition: epath.h:146
A path manipulation helper class.
Definition: epath.h:35
String class.
Definition: estring.h:31