]> git.lyx.org Git - features.git/blob - src/insets/insetlabel.C
the runlatex merge
[features.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-1999 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
19 /* Label. Used to insert a label automatically */
20
21
22 InsetLabel::InsetLabel(string const & cmd)
23 {
24         scanCommand(cmd);
25 }
26
27
28 InsetLabel::~InsetLabel()
29 {
30 }
31
32
33 Inset * InsetLabel::Clone()
34 {
35         InsetLabel * result = new InsetLabel(getCommand());
36         return result;
37 }
38
39
40 int InsetLabel::GetNumberOfLabels() const
41 {
42         return 1;
43 }
44
45
46 string InsetLabel::getLabel(int) const
47 {
48         return contents;
49 }
50
51 int InsetLabel::Latex(FILE * file, signed char /*fragile*/)
52 {
53         fprintf(file, "%s", escape(getCommand()).c_str());
54         return 0;
55 }
56
57
58 int InsetLabel::Latex(string & file, signed char /*fragile*/)
59 {
60         file += escape(getCommand());
61         return 0;
62 }
63
64
65 int InsetLabel::Linuxdoc(string & file)
66 {
67         file += "<label id=\"" + getContents() +"\" >";
68         return 0;
69 }
70
71
72 int InsetLabel::DocBook(string & file)
73 {
74         file += "<anchor id=\"" + getContents() +"\" >";
75         return 0;
76 }
77
78
79 // This function escapes 8-bit characters and other problematic characters
80 // It's exactly the same code as in insetref.C.
81 string InsetLabel::escape(string const & lab) const {
82         char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
83                               '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
84         string enc;
85         for (string::size_type i=0; i < lab.length(); ++i) {
86                 unsigned char c = lab[i];
87                 if (c >= 128 || c == '=' || c == '%') {
88                         enc += '=';
89                         enc += hexdigit[c >> 4];
90                         enc += hexdigit[c & 15];
91                 } else {
92                         enc += c;
93                 }
94         }
95         return enc;
96 }