2 file-name.cc - implement File_name
4 source file of the Flower Library
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "file-name.hh"
22 #include <sys/cygwin.h>
25 /* We don't have multiple roots, set this to '\0'? */
40 dos_to_posix (String file_name)
43 char *s = file_name.get_copy_str0 ();
44 /* urg, wtf? char const* argument gets modified! */
45 cygwin_conv_to_posix_path (s, buf);
49 #endif /* __CYGWIN__ */
52 /** Use slash as directory separator. On Windows, they can pretty
55 slashify (String file_name)
57 if (file_name.index ('/'))
59 file_name.substitute ('\\', '/');
60 file_name.substitute ("\"", "\\\"");
61 file_name.substitute ("\'", "\\\'");
64 #endif /* __MINGW32__ */
66 /* Join components to full file_name. */
68 File_name::to_string () const
71 if (!root_.is_empty ())
72 s = root_ + ::to_string (ROOTSEP);
73 if (!dir_.is_empty ())
74 s += dir_ + ::to_string (DIRSEP);
76 if (!ext_.is_empty ())
77 s += ::to_string (EXTSEP) + ext_;
82 File_name::to_str0 () const
84 return to_string ().to_str0 ();
87 File_name::File_name (String file_name)
90 /* All system functions would work, even if we do not convert to
91 posix file_name, but we would think that \foe\bar\baz.ly is in
93 file_name = dos_to_posix (file_name);
96 file_name = slashify (file_name);
99 int i = file_name.index (ROOTSEP);
102 root_ = file_name.left_string (i);
103 file_name = file_name.right_string (file_name.length () - i - 1);
106 i = file_name.index_last (DIRSEP);
109 dir_ = file_name.left_string (i);
110 file_name = file_name.right_string (file_name.length () - i - 1);
113 i = file_name.index_last ('.');
116 base_ = file_name.left_string (i);
117 ext_ = file_name.right_string (file_name.length () - i - 1);