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 InsetLabel::~InsetLabel()
33 Inset* InsetLabel::Clone()
35 InsetLabel *result = new InsetLabel(getCommand());
40 int InsetLabel::GetNumberOfLabels() const
46 string InsetLabel::getLabel(int) const
51 int InsetLabel::Latex(FILE *file, signed char /*fragile*/)
53 fprintf(file, "%s", escape(getCommand()).c_str());
58 int InsetLabel::Latex(string &file, signed char /*fragile*/)
60 file += escape(getCommand());
65 int InsetLabel::Linuxdoc(string &file)
67 file += "<label id=\"" + getContents() +"\" >";
72 int InsetLabel::DocBook(string &file)
74 file += "<anchor id=\"" + getContents() +"\" >";
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' };
85 for (string::size_type i=0; i<lab.length(); i++) {
86 unsigned char c=lab[i];
87 if (c >= 128 || c=='=' || c=='%') {
89 enc += hexdigit[c>>4];
90 enc += hexdigit[c & 15];