]> git.lyx.org Git - lyx.git/blob - src/insets/insetlabel.C
clear()->erase() ; lots of using directives for cxx
[lyx.git] / src / insets / insetlabel.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1995 Matthias Ettrich
7  *          Copyright 1995-2000 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "insetlabel.h"
18 #include "support/LOstream.h"
19
20 using std::ostream;
21
22 /* Label. Used to insert a label automatically */
23
24
25 InsetLabel::InsetLabel(string const & cmd)
26 {
27         scanCommand(cmd);
28 }
29
30
31 Inset * InsetLabel::Clone() const
32 {
33         return new InsetLabel(getCommand());
34 }
35
36
37 int InsetLabel::GetNumberOfLabels() const
38 {
39         return 1;
40 }
41
42
43 string InsetLabel::getLabel(int) const
44 {
45         return contents;
46 }
47
48
49 int InsetLabel::Latex(ostream & os,
50                       bool /*fragile*/, bool /*fs*/) const
51 {
52         os << escape(getCommand());
53         return 0;
54 }
55
56 int InsetLabel::Ascii(ostream & os) const
57 {
58         os << "<" << getContents()  << ">";
59         return 0;
60 }
61
62
63 int InsetLabel::Linuxdoc(ostream & os) const
64 {
65         os << "<label id=\"" << getContents() << "\" >";
66         return 0;
67 }
68
69
70 int InsetLabel::DocBook(ostream & os) const
71 {
72         os << "<anchor id=\"" << getContents() << "\" >";
73         return 0;
74 }
75
76
77 // This function escapes 8-bit characters and other problematic characters
78 // It's exactly the same code as in insetref.C.
79 string InsetLabel::escape(string const & lab) const {
80         char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
81                               '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
82         string enc;
83         for (string::size_type i= 0; i < lab.length(); ++i) {
84                 unsigned char c = lab[i];
85                 if (c >= 128 || c == '=' || c == '%') {
86                         enc += '=';
87                         enc += hexdigit[c >> 4];
88                         enc += hexdigit[c & 15];
89                 } else {
90                         enc += c;
91                 }
92         }
93         return enc;
94 }