]> git.lyx.org Git - lyx.git/blob - src/support/filename.C
Fix export of graphics images when compiling latex file.
[lyx.git] / src / support / filename.C
1 /**
2  * \file filename.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * This file is part of LyX, the document processor.
9  * Licence details can be found in the file COPYING.
10  */
11
12 #include <config.h>
13
14 #include "filename.h"
15 #include "support/filetools.h"
16 #include "lstrings.h"
17 #include "LAssert.h"
18
19
20 namespace lyx {
21 namespace support {
22
23
24 FileName::FileName()
25         : save_abs_path_(true)
26 {}
27
28
29 FileName::FileName(string const & abs_filename, bool save_abs)
30         : name_(abs_filename), save_abs_path_(save_abs)
31 {
32         Assert(AbsolutePath(name_));
33 }
34
35
36 void FileName::set(string const & name, string const & buffer_path)
37 {
38         save_abs_path_ = AbsolutePath(name);
39         name_ = save_abs_path_ ? name : MakeAbsPath(name, buffer_path);
40 }
41
42
43 void FileName::erase()
44 {
45         name_.erase();
46 }
47
48
49 string const FileName::relFilename(string const & path) const
50 {
51         return MakeRelPath(name_, path);
52 }
53
54
55 string const FileName::outputFilename(string const & path) const
56 {
57         return save_abs_path_ ? name_ : MakeRelPath(name_, path);
58 }
59
60
61 string const FileName::mangledFilename() const
62 {
63         string mname = os::slashify_path(name_);
64         // Remove the extension.
65         mname = ChangeExtension(name_, string());
66         // Replace '/' in the file name with '_'
67         mname = subst(mname, "/", "_");
68         // Replace '.' in the file name with '_'
69         mname = subst(mname, ".", "_");
70         // Add the extension back on
71         return ChangeExtension(mname, GetExtension(name_));
72 }
73
74
75 bool FileName::isZipped() const
76 {
77         return zippedFile(name_);
78 }
79
80
81 string const FileName::unzippedFilename() const
82 {
83         return unzippedFileName(name_);
84 }
85
86
87 bool operator==(FileName const & lhs, FileName const & rhs)
88 {
89         return lhs.absFilename() == rhs.absFilename() &&
90                 lhs.saveAbsPath() == rhs.saveAbsPath();
91 }
92
93
94 bool operator!=(FileName const & lhs, FileName const & rhs)
95 {
96         return !(lhs == rhs);
97 }
98
99 } // namespace support
100 } // namespace lyx