Kea
1.9.9-git
|
Class to Manipulate Filenames. More...
#include <filename.h>
Public Member Functions | |
Filename (const std::string &name) | |
Constructor. More... | |
std::string | directory () const |
std::string | expandWithDefault (const std::string &defname) const |
Expand Name with Default. More... | |
std::string | extension () const |
std::string | fullName () const |
std::string | name () const |
std::string | nameAndExtension () const |
void | setDirectory (const std::string &new_directory) |
Set directory for the file. More... | |
void | setName (const std::string &name) |
Sets Stored Filename. More... | |
std::string | useAsDefault (const std::string &name) const |
Use as Default and Substitute into String. More... | |
Class to Manipulate Filenames.
This is a utility class to manipulate filenames. It repeats some of the features found in the Boost filename class, but is self-contained so avoids the need to link in the Boost library.
A Unix-style filename comprises three parts:
Directory - everything up to and including the last "/". If there is no "/" in the string, there is no directory component. Note that the requirement of a trailing slash eliminates the ambiguity of whether a component is a directory or not, e.g. in /alpha/beta", "beta" could be the name of a directory or is could be a file. The interpretation here is that "beta" is the name of a file (although that file could be a directory).
Note: Under Windows, the drive letter is considered to be part of the directory specification. Unless this class becomes more widely-used on Windows, there is no point in adding redundant code.
Name - everything from the character after the last "/" up to but not including the last ".".
Extension - everything from the right-most "." (after the right-most "/") to the end of the string. If there is no "." after the last "/", there is no file extension.
(Note that on Windows, this function will replace all "\" characters with "/" characters on input strings.)
This class provides functions for extracting the components and for substituting components.
Definition at line 50 of file filename.h.
|
inline |
Constructor.
Definition at line 54 of file filename.h.
References setName().
|
inline |
Definition at line 76 of file filename.h.
string isc::util::Filename::expandWithDefault | ( | const std::string & | defname | ) | const |
Expand Name with Default.
A default file specified is supplied and used to fill in any missing fields. For example, if the name stored is "/a/b" and the supplied name is "c.d", the result is "/a/b.d": the only field missing from the stored name is the extension, which is supplied by the default. Another example would be to store "a.b" and to supply a default of "/c/d/" - the result is "/c/d/a.b". (Note that if the supplied default was "/c/d", the result would be "/c/a.b", even if "/c/d" were actually a directory.)
defname | Default name |
Definition at line 79 of file filename.cc.
References name_, isc::util::str::normalizeSlash(), and isc::util::str::trim().
|
inline |
Definition at line 93 of file filename.h.
Referenced by sentinel().
|
inline |
Definition at line 71 of file filename.h.
Referenced by writeHeaderFile(), and writeProgramFile().
|
inline |
Definition at line 88 of file filename.h.
Referenced by isc::process::Daemon::checkConfigFile(), isc::process::Daemon::makePIDFileName(), sentinel(), writeHeaderFile(), and writeProgramFile().
|
inline |
Definition at line 98 of file filename.h.
void isc::util::Filename::setDirectory | ( | const std::string & | new_directory | ) |
Set directory for the file.
new_directory | The directory to set. If this is an empty string, the directory this filename object currently has will be removed. |
Definition at line 129 of file filename.cc.
References name_.
Referenced by writeHeaderFile(), and writeProgramFile().
|
inline |
Sets Stored Filename.
name | New name to replaced currently stored name |
Definition at line 62 of file filename.h.
References isc::util::str::normalizeSlash(), and isc::util::str::trim().
Referenced by Filename().
string isc::util::Filename::useAsDefault | ( | const std::string & | name | ) | const |
Use as Default and Substitute into String.
Does essentially the inverse of expand(); that filled in the stored name with a default and returned the result. This treats the stored name as the default and uses it to fill in a given name. In essence, the code:
gives as a result "/a/b.d". This is the same as:
name | Name to expand |
Definition at line 105 of file filename.cc.
References name_, isc::util::str::normalizeSlash(), and isc::util::str::trim().