2 file-name.cc - implement File_name
4 source file of the Flower Library
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
21 #include <sys/cygwin.h>
24 #include "file-name.hh"
26 /* We don't have multiple roots, set this to '\0'? */
41 dos_to_posix (String file_name)
44 char *s = file_name.get_copy_str0 ();
45 /* urg, wtf? char const* argument gets modified! */
46 cygwin_conv_to_posix_path (s, buf);
50 #endif /* __CYGWIN__ */
52 /* Join components to full file_name. */
54 File_name::to_string () const
57 if (!root_.is_empty ())
58 s = root_ + ::to_string (ROOTSEP);
59 if (!dir_.is_empty ())
60 s += dir_ + ::to_string (DIRSEP);
62 if (!ext_.is_empty ())
63 s += ::to_string (EXTSEP) + ext_;
68 File_name::to_str0 () const
70 return to_string ().to_str0 ();
73 File_name::File_name (String file_name)
76 /* All system functions would work, even if we don't convert to
77 posix file_name, but we'd think that \foe\bar\baz.ly is in the cwd.
79 file_name = dos_to_posix (file_name);
82 int i = file_name.index (ROOTSEP);
85 root_ = file_name.left_string (i);
86 file_name = file_name.right_string (file_name.length () - i - 1);
89 i = file_name.index_last (DIRSEP);
92 dir_ = file_name.left_string (i);
93 file_name = file_name.right_string (file_name.length () - i - 1);
96 i = file_name.index_last ('.');
99 base_ = file_name.left_string (i);
100 ext_ = file_name.right_string (file_name.length () - i - 1);