2 file-name.cc - implement File_name
4 source file of the Flower Library
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "file-name.hh"
23 #include <sys/cygwin.h>
40 dos_to_posix (String file_name)
42 char buf[PATH_MAX] = "";
43 char *s = file_name.get_copy_str0 ();
44 /* ugh: char const* argument gets modified. */
45 int fail = cygwin_conv_to_posix_path (s, buf);
51 #endif /* __CYGWIN__ */
54 /** Use slash as directory separator. On Windows, they can pretty
57 slashify (String file_name)
59 file_name.substitute ('\\', '/');
60 file_name.substitute ("//", "/");
63 #endif /* __MINGW32__ */
65 /* Join components to full file_name. */
67 File_name::to_string () const
70 if (!root_.is_empty ())
71 s = root_ + ::to_string (ROOTSEP);
72 if (!dir_.is_empty ())
75 if (!base_.is_empty () || !ext_.is_empty ())
76 s += ::to_string (DIRSEP);
79 if (!ext_.is_empty ())
80 s += ::to_string (EXTSEP) + ext_;
84 File_name::File_name (String file_name)
87 /* All system functions would work, even if we do not convert to
88 posix file_name, but we would think that \foe\bar\baz.ly is in
90 file_name = dos_to_posix (file_name);
93 file_name = slashify (file_name);
96 int i = file_name.index (ROOTSEP);
99 root_ = file_name.left_string (i);
100 file_name = file_name.right_string (file_name.length () - i - 1);
103 i = file_name.index_last (DIRSEP);
106 dir_ = file_name.left_string (i);
107 file_name = file_name.right_string (file_name.length () - i - 1);
110 i = file_name.index_last ('.');
113 base_ = file_name.left_string (i);
114 ext_ = file_name.right_string (file_name.length () - i - 1);