]> git.lyx.org Git - lyx.git/blob - src/support/filename.C
more cursor dispatch
[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  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "filename.h"
14
15 #include "filetools.h"
16 #include "lstrings.h"
17 #include "os.h"
18
19 #include <boost/assert.hpp>
20
21
22 using std::string;
23
24
25 namespace lyx {
26 namespace support {
27
28
29 FileName::FileName()
30         : save_abs_path_(true)
31 {}
32
33
34 FileName::FileName(string const & abs_filename, bool save_abs)
35         : name_(abs_filename), save_abs_path_(save_abs)
36 {
37         BOOST_ASSERT(AbsolutePath(name_));
38 }
39
40
41 void FileName::set(string const & name, string const & buffer_path)
42 {
43         save_abs_path_ = AbsolutePath(name);
44         name_ = save_abs_path_ ? name : MakeAbsPath(name, buffer_path);
45 }
46
47
48 void FileName::erase()
49 {
50         name_.erase();
51 }
52
53
54 string const FileName::relFilename(string const & path) const
55 {
56         return MakeRelPath(name_, path);
57 }
58
59
60 string const FileName::outputFilename(string const & path) const
61 {
62         return save_abs_path_ ? name_ : MakeRelPath(name_, path);
63 }
64
65
66 string const FileName::mangledFilename() const
67 {
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_));
77 }
78
79
80 bool FileName::isZipped() const
81 {
82         return zippedFile(name_);
83 }
84
85
86 string const FileName::unzippedFilename() const
87 {
88         return unzippedFileName(name_);
89 }
90
91
92 bool operator==(FileName const & lhs, FileName const & rhs)
93 {
94         return lhs.absFilename() == rhs.absFilename() &&
95                 lhs.saveAbsPath() == rhs.saveAbsPath();
96 }
97
98
99 bool operator!=(FileName const & lhs, FileName const & rhs)
100 {
101         return !(lhs == rhs);
102 }
103
104 } // namespace support
105 } // namespace lyx