]> git.lyx.org Git - lyx.git/blob - src/support/filename.C
Replace LString.h with support/std_string.h,
[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
16 #include "LAssert.h"
17 #include "filetools.h"
18 #include "lstrings.h"
19 #include "os.h"
20
21
22 namespace lyx {
23 namespace support {
24
25
26 FileName::FileName()
27         : save_abs_path_(true)
28 {}
29
30
31 FileName::FileName(string const & abs_filename, bool save_abs)
32         : name_(abs_filename), save_abs_path_(save_abs)
33 {
34         Assert(AbsolutePath(name_));
35 }
36
37
38 void FileName::set(string const & name, string const & buffer_path)
39 {
40         save_abs_path_ = AbsolutePath(name);
41         name_ = save_abs_path_ ? name : MakeAbsPath(name, buffer_path);
42 }
43
44
45 void FileName::erase()
46 {
47         name_.erase();
48 }
49
50
51 string const FileName::relFilename(string const & path) const
52 {
53         return MakeRelPath(name_, path);
54 }
55
56
57 string const FileName::outputFilename(string const & path) const
58 {
59         return save_abs_path_ ? name_ : MakeRelPath(name_, path);
60 }
61
62
63 string const FileName::mangledFilename() const
64 {
65         string mname = os::slashify_path(name_);
66         // Remove the extension.
67         mname = ChangeExtension(name_, string());
68         // Replace '/' in the file name with '_'
69         mname = subst(mname, "/", "_");
70         // Replace '.' in the file name with '_'
71         mname = subst(mname, ".", "_");
72         // Add the extension back on
73         return ChangeExtension(mname, GetExtension(name_));
74 }
75
76
77 bool FileName::isZipped() const
78 {
79         return zippedFile(name_);
80 }
81
82
83 string const FileName::unzippedFilename() const
84 {
85         return unzippedFileName(name_);
86 }
87
88
89 bool operator==(FileName const & lhs, FileName const & rhs)
90 {
91         return lhs.absFilename() == rhs.absFilename() &&
92                 lhs.saveAbsPath() == rhs.saveAbsPath();
93 }
94
95
96 bool operator!=(FileName const & lhs, FileName const & rhs)
97 {
98         return !(lhs == rhs);
99 }
100
101 } // namespace support
102 } // namespace lyx