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