1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
17 #include "insetlabel.h"
19 /* Label. Used to insert a label automatically */
22 InsetLabel::InsetLabel(string const & cmd)
28 Inset * InsetLabel::Clone() const
30 return new InsetLabel(getCommand());
34 int InsetLabel::GetNumberOfLabels() const
40 string InsetLabel::getLabel(int) const
46 int InsetLabel::Latex(ostream & os, signed char /*fragile*/)
48 os << escape(getCommand());
53 int InsetLabel::Latex(string & file, signed char /*fragile*/)
55 file += escape(getCommand());
60 int InsetLabel::Linuxdoc(string & file)
62 file += "<label id=\"" + getContents() +"\" >";
67 int InsetLabel::DocBook(string & file)
69 file += "<anchor id=\"" + getContents() +"\" >";
74 // This function escapes 8-bit characters and other problematic characters
75 // It's exactly the same code as in insetref.C.
76 string InsetLabel::escape(string const & lab) const {
77 char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
78 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
80 for (string::size_type i= 0; i < lab.length(); ++i) {
81 unsigned char c = lab[i];
82 if (c >= 128 || c == '=' || c == '%') {
84 enc += hexdigit[c >> 4];
85 enc += hexdigit[c & 15];