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"
18 #include "support/LOstream.h"
22 /* Label. Used to insert a label automatically */
25 InsetLabel::InsetLabel(string const & cmd)
31 Inset * InsetLabel::Clone() const
33 return new InsetLabel(getCommand());
37 int InsetLabel::GetNumberOfLabels() const
43 string InsetLabel::getLabel(int) const
49 int InsetLabel::Latex(ostream & os,
50 bool /*fragile*/, bool /*fs*/) const
52 os << escape(getCommand());
57 int InsetLabel::Linuxdoc(ostream & os) const
59 os << "<label id=\"" << getContents() << "\" >";
64 int InsetLabel::DocBook(ostream & os) const
66 os << "<anchor id=\"" << getContents() << "\" >";
71 // This function escapes 8-bit characters and other problematic characters
72 // It's exactly the same code as in insetref.C.
73 string InsetLabel::escape(string const & lab) const {
74 char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
75 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
77 for (string::size_type i= 0; i < lab.length(); ++i) {
78 unsigned char c = lab[i];
79 if (c >= 128 || c == '=' || c == '%') {
81 enc += hexdigit[c >> 4];
82 enc += hexdigit[c & 15];