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);
31 
33 class EPath
34 {
35 public:
38  static cpStr getDirectorySeparatorString();
39 
42  static cChar getDirectorySeparatorChar();
45  static cChar getAltDirectorySeparatorChar();
48  static cChar getVolumeSeparatorChar();
49 
52  static cpStr getPathSeparatorChars();
55  static cpStr getInvalidPathChars();
58  static cpStr getInvalidFileNameChars();
59 
64  static Void changeExtension(cpStr path, cpStr extension, EString &newPath);
65 
72  static Void combine(cpStr path1, cpStr path2, cpStr path3, cpStr path4, EString &path);
78  static Void combine(cpStr path1, cpStr path2, cpStr path3, EString &path);
83  static Void combine(cpStr path1, cpStr path2, EString &path);
90  static EString combine(cpStr path1, cpStr path2, cpStr path3, cpStr path4);
96  static EString combine(cpStr path1, cpStr path2, cpStr path3);
101  static EString combine(cpStr path1, cpStr path2);
102 
106  static Void getDirectoryName(cpStr path, EString &dirName);
110  static Void getExtension(cpStr path, EString &ext);
114  static Void getFileName(cpStr path, EString &fileName);
118  static Void getFileNameWithoutExtension(cpStr path, EString &fileName);
122  static Void getPathRoot(cpStr path, EString &root);
123 
127  static EString getDirectoryName(cpStr path) { EString s; getDirectoryName(path, s); return s; }
131  static EString getExtension(cpStr path) { EString s; getExtension(path, s); return s; }
135  static EString getFileName(cpStr path) { EString s; getFileName(path, s); return s; }
139  static EString getFileNameWithoutExtension(cpStr path) { EString s; getFileNameWithoutExtension(path, s); return s; }
143  static EString getPathRoot(cpStr path) { EString s; getPathRoot(path, s); return s; }
144 
145 private:
146  static Bool m_dirEqualsVolume;
147 
148  static Void cleanPath(cpStr path, EString &cleanPath);
149  static Void insecureFullPath(cpStr path, EString &fullPath);
150  static Bool isDsc(cChar c);
151  static Bool isPathRooted(cpStr path);
152  static Int findExtension(cpStr path);
153 };
154 
157 {
158  return "/";
159 }
160 
162 {
163  return '/';
164 }
165 
167 {
168  return '/';
169 }
170 
171 inline cChar EPath::getVolumeSeparatorChar()
172 {
173  return ':';
174 }
175 
176 inline cpStr EPath::getPathSeparatorChars()
177 {
178  return "/:";
179 }
180 
181 inline cpStr EPath::getInvalidPathChars()
182 {
183  return "";
184 }
185 
186 inline cpStr EPath::getInvalidFileNameChars()
187 {
188  return "/";
189 }
190 
191 inline Bool EPath::isDsc(cChar c)
192 {
194 }
196 
197 #endif // #define __epath_h_included
eerror.h
Defines base class for exceptions and declaration helper macros.
EPath::getPathRoot
static Void getPathRoot(cpStr path, EString &root)
Retrieves the path root.
Definition: epath.cpp:218
ebase.h
Macros for various standard C library functions and standard includes.
EPath::combine
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:115
EPath::getPathRoot
static EString getPathRoot(cpStr path)
Retrieves the path root.
Definition: epath.h:143
EPath::getExtension
static Void getExtension(cpStr path, EString &ext)
Retrieves the extension of a file name.
Definition: epath.cpp:167
EPath::getExtension
static EString getExtension(cpStr path)
Retrieves the extension of a file name.
Definition: epath.h:131
DECLARE_ERROR_ADVANCED4
#define DECLARE_ERROR_ADVANCED4(__e__)
Declares exception class derived from EError with an const char* as a constructor parameter and devel...
Definition: eerror.h:83
EPath::changeExtension
static Void changeExtension(cpStr path, cpStr extension, EString &newPath)
Changes the extension of an exist path name.
Definition: epath.cpp:38
EPath::getDirectoryName
static EString getDirectoryName(cpStr path)
Retrieves the directory name from a file name.
Definition: epath.h:127
EPath
A path manipulation helper class.
Definition: epath.h:33
EPath::getAltDirectorySeparatorChar
static cChar getAltDirectorySeparatorChar()
Retrieves the alternate directory separator character.
EPath::getInvalidFileNameChars
static cpStr getInvalidFileNameChars()
Retrieves the invalid file name characters.
EPath::getFileName
static Void getFileName(cpStr path, EString &fileName)
Retrieves just the file name from a fully qualified file name.
Definition: epath.cpp:194
EPath::getFileNameWithoutExtension
static EString getFileNameWithoutExtension(cpStr path)
Retrieves the file name without any extension.
Definition: epath.h:139
EPath::getDirectorySeparatorString
static cpStr getDirectorySeparatorString()
Retrieves the directory separator string.
EString
String class.
Definition: estring.h:30
EPath::getInvalidPathChars
static cpStr getInvalidPathChars()
Retrieves the invalid path characters.
EPath::getVolumeSeparatorChar
static cChar getVolumeSeparatorChar()
Retrieves the volume separator character.
EPath::getPathSeparatorChars
static cpStr getPathSeparatorChars()
Retrieves the path separator characters.
EPath::getDirectorySeparatorChar
static cChar getDirectorySeparatorChar()
Retrieves the directory separator character.
EPath::getDirectoryName
static Void getDirectoryName(cpStr path, EString &dirName)
Retrieves the directory name from a file name.
Definition: epath.cpp:143
estring.h
Encapsulates and extends a std::string object.
EPath::getFileNameWithoutExtension
static Void getFileNameWithoutExtension(cpStr path, EString &fileName)
Retrieves the file name without any extension.
Definition: epath.cpp:212
EPath::getFileName
static EString getFileName(cpStr path)
Retrieves just the file name from a fully qualified file name.
Definition: epath.h:135