1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
17 #include "insetlabel.h"
21 /* Label. Used to insert a label automatically */
24 InsetLabel::InsetLabel(string const & cmd)
30 Inset * InsetLabel::Clone() const
32 return new InsetLabel(getCommand());
36 int InsetLabel::GetNumberOfLabels() const
42 string InsetLabel::getLabel(int) const
48 int InsetLabel::Latex(ostream & os,
49 signed char /*fragile*/, bool /*fs*/) const
51 os << escape(getCommand());
56 int InsetLabel::Linuxdoc(ostream & os) const
58 os << "<label id=\"" << getContents() << "\" >";
63 int InsetLabel::DocBook(ostream & os) const
65 os << "<anchor id=\"" << getContents() << "\" >";
70 // This function escapes 8-bit characters and other problematic characters
71 // It's exactly the same code as in insetref.C.
72 string InsetLabel::escape(string const & lab) const {
73 char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
74 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
76 for (string::size_type i= 0; i < lab.length(); ++i) {
77 unsigned char c = lab[i];
78 if (c >= 128 || c == '=' || c == '%') {
80 enc += hexdigit[c >> 4];
81 enc += hexdigit[c & 15];