diff options
Diffstat (limited to 'flower/file-name.cc')
-rw-r--r-- | flower/file-name.cc | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/flower/file-name.cc b/flower/file-name.cc index 66b1aaa114..787c27f25a 100644 --- a/flower/file-name.cc +++ b/flower/file-name.cc @@ -73,7 +73,13 @@ dir_name (string const file_name) ssize n = s.length (); if (n && s[n - 1] == '/') s[n - 1] = 0; - s = s.substr (0, s.rfind ('/')); + if (s.rfind ('/') != NPOS) + { + s = s.substr (0, s.rfind ('/')); + } + else + s = ""; + return s; } @@ -88,23 +94,46 @@ get_working_directory () /* Join components to full file_name. */ string -File_name::to_string () const +File_name::dir_part () const { string s; if (!root_.empty ()) s = root_ + ::to_string (ROOTSEP); + if (!dir_.empty ()) { s += dir_; - if (!base_.empty () || !ext_.empty ()) - s += ::to_string (DIRSEP); } - s += base_; + + return s; +} + + +string +File_name::file_part () const +{ + string s; + s = base_; if (!ext_.empty ()) s += ::to_string (EXTSEP) + ext_; return s; } +string +File_name::to_string () const +{ + string d = dir_part (); + string f = file_part (); + + if (!f.empty () + && !dir_.empty()) + { + d += ::to_string (DIRSEP); + } + + return d + f; +} + File_name::File_name (string file_name) { #ifdef __CYGWIN__ |