1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright (C) 1995 Matthias Ettrich
7 * Copyright (C) 1995-1998 The LyX Team.
9 *======================================================*/
14 #pragma implementation
17 #include "insetlabel.h"
19 // $Id: insetlabel.C,v 1.1 1999/09/27 18:44:39 larsbj Exp $
21 #if !defined(lint) && !defined(WITH_WARNINGS)
22 static char vcid[] = "$Id: insetlabel.C,v 1.1 1999/09/27 18:44:39 larsbj Exp $";
25 /* Label. Used to insert a label automatically */
28 InsetLabel::InsetLabel(LString const & cmd)
34 InsetLabel::~InsetLabel()
39 Inset* InsetLabel::Clone()
41 InsetLabel *result = new InsetLabel(getCommand());
46 int InsetLabel::GetNumberOfLabels() const
52 LString InsetLabel::getLabel(int) const
57 int InsetLabel::Latex(FILE *file, signed char /*fragile*/)
59 fprintf(file, "%s", escape(getCommand()).c_str());
64 int InsetLabel::Latex(LString &file, signed char /*fragile*/)
66 file += escape(getCommand());
71 int InsetLabel::Linuxdoc(LString &file)
73 file += "<label id=\"" + getContents() +"\" >";
78 int InsetLabel::DocBook(LString &file)
80 file += "<anchor id=\"" + getContents() +"\" >";
85 // This function escapes 8-bit characters and other problematic characters
86 // It's exactly the same code as in insetref.C.
87 LString InsetLabel::escape(LString const & lab) const {
88 char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
89 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
91 for (int i=0; i<lab.length(); i++) {
92 unsigned char c=lab[i];
93 if (c >= 128 || c=='=' || c=='%') {
95 enc += hexdigit[c>>4];
96 enc += hexdigit[c & 15];