3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS.
15 #include "filetools.h"
19 #include <boost/assert.hpp>
30 : save_abs_path_(true)
34 FileName::FileName(string const & abs_filename, bool save_abs)
35 : name_(abs_filename), save_abs_path_(save_abs)
37 BOOST_ASSERT(AbsolutePath(name_));
41 void FileName::set(string const & name, string const & buffer_path)
43 save_abs_path_ = AbsolutePath(name);
44 name_ = save_abs_path_ ? name : MakeAbsPath(name, buffer_path);
48 void FileName::erase()
54 string const FileName::relFilename(string const & path) const
56 return MakeRelPath(name_, path);
60 string const FileName::outputFilename(string const & path) const
62 return save_abs_path_ ? name_ : MakeRelPath(name_, path);
66 string const FileName::mangledFilename() const
68 string mname = os::slashify_path(name_);
69 // Remove the extension.
70 mname = ChangeExtension(name_, string());
71 // Replace '/' in the file name with '_'
72 mname = subst(mname, "/", "_");
73 // Replace '.' in the file name with '_'
74 mname = subst(mname, ".", "_");
75 // Add the extension back on
76 return ChangeExtension(mname, GetExtension(name_));
80 bool FileName::isZipped() const
82 return zippedFile(name_);
86 string const FileName::unzippedFilename() const
88 return unzippedFileName(name_);
92 bool operator==(FileName const & lhs, FileName const & rhs)
94 return lhs.absFilename() == rhs.absFilename() &&
95 lhs.saveAbsPath() == rhs.saveAbsPath();
99 bool operator!=(FileName const & lhs, FileName const & rhs)
101 return !(lhs == rhs);
104 } // namespace support