This commit was manufactured by cvs2svn to create tag
[lyx.git] / src / insets / insetlabel.C
blob2ebb685295e86b4ca01490d5b20c2308b010f4aa
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  * ======================================================*/
11 #include <config.h>
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
17 #include "insetlabel.h"
19 /* Label. Used to insert a label automatically */
22 InsetLabel::InsetLabel(string const & cmd)
24         scanCommand(cmd);
28 InsetLabel::~InsetLabel()
33 Inset* InsetLabel::Clone()
35         InsetLabel *result = new InsetLabel(getCommand());
36         return result;
40 int InsetLabel::GetNumberOfLabels() const
42         return 1;
46 string InsetLabel::getLabel(int) const
48         return contents;
51 int InsetLabel::Latex(FILE *file, signed char /*fragile*/)
53         fprintf(file, "%s", escape(getCommand()).c_str());
54         return 0;
58 int InsetLabel::Latex(string &file, signed char /*fragile*/)
60         file += escape(getCommand());
61         return 0;
65 int InsetLabel::Linuxdoc(string &file)
67         file += "<label id=\"" + getContents() +"\" >";
68         return 0;
72 int InsetLabel::DocBook(string &file)
74         file += "<anchor id=\"" + getContents() +"\" >";
75         return 0;
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 += (char) c;
93                 }
94         }
95         return enc;