27 Filename::split(
const string& full_name,
string& directory,
string& name,
28 string& extension)
const {
29 directory = name = extension =
"";
30 if (!full_name.empty()) {
32 bool dir_present =
false;
34 size_t last_slash = full_name.find_last_of(
'/');
35 if (last_slash != string::npos) {
39 directory = full_name.substr(0, last_slash + 1);
40 if (last_slash == full_name.size()) {
52 size_t last_dot = full_name.find_last_of(
'.');
53 if ((last_dot == string::npos) ||
54 (dir_present && (last_dot < last_slash))) {
60 name = full_name.substr(last_slash + 1);
66 extension = full_name.substr(last_dot);
69 if ((last_dot - last_slash) > 1) {
70 name = full_name.substr(last_slash + 1, last_dot - last_slash - 1);
79 Filename::expandWithDefault(
const string& defname)
const {
81 string def_directory(
"");
83 string def_extension(
"");
92 split(copy_defname, def_directory, def_name, def_extension);
96 (directory_.empty() ? def_directory : directory_) +
98 (extension_.empty() ? def_extension : extension_);
105 Filename::useAsDefault(
const string& name)
const {
107 string name_directory(
"");
108 string name_name(
"");
109 string name_extension(
"");
118 split(copy_name, name_directory, name_name, name_extension);
122 (name_directory.empty() ? directory_ : name_directory) +
123 (name_name.empty() ?
name_ : name_name) +
124 (name_extension.empty() ? extension_ : name_extension);
129 Filename::setDirectory(
const std::string& new_directory) {
130 std::string directory(new_directory);
132 if (directory.length() > 0) {
134 size_t sep = directory.rfind(
'/');
135 if (sep == std::string::npos || sep < directory.size() - 1) {
140 std::string full_name = directory +
name_ + extension_;
142 directory_.swap(directory);
143 full_name_.swap(full_name);
void normalizeSlash(std::string &name)
Normalize Backslash.
Defines the logger used by the top-level component of kea-dhcp-ddns.
string trim(const string &instring)
Trim Leading and Trailing Spaces.