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__ */
51 /* Join components to full file_name. */
53 File_name::to_string () const
56 if (!root_.is_empty ())
57 s = root_ + ::to_string (ROOTSEP);
58 if (!dir_.is_empty ())
59 s += dir_ + ::to_string (DIRSEP);
61 if (!ext_.is_empty ())
62 s += ::to_string (EXTSEP) + ext_;
67 File_name::to_str0 () const
69 return to_string ().to_str0 ();
72 File_name::File_name (String file_name)
75 /* All system functions would work, even if we do not convert to
76 posix file_name, but we would think that \foe\bar\baz.ly is in
78 file_name = dos_to_posix (file_name);
81 file_name.substitute ('\\', '/');
84 int i = file_name.index (ROOTSEP);
87 root_ = file_name.left_string (i);
88 file_name = file_name.right_string (file_name.length () - i - 1);
91 i = file_name.index_last (DIRSEP);
94 dir_ = file_name.left_string (i);
95 file_name = file_name.right_string (file_name.length () - i - 1);
98 i = file_name.index_last ('.');
101 base_ = file_name.left_string (i);
102 ext_ = file_name.right_string (file_name.length () - i - 1);