[LyX/master] Implement Paragraph::getLabel()
Jean-Marc Lasgouttes
lasgouttes at lyx.org
Sun Jul 28 17:39:36 UTC 2024
Le 28 juillet 2024 16:00:56 GMT+02:00, Juergen Spitzmueller <spitz at lyx.org> a écrit :
>commit a303600b544d9f4c82f2dee77616f821d0051854
>Author: Juergen Spitzmueller <spitz at lyx.org>
>Date: Sun Jul 28 15:52:19 2024 +0200
>
> Implement Paragraph::getLabel()
>
> This function returns the first label (as string) if there is any
Usually, when we use getLabel, it concerns the label at the start of the paragraph. It would be nice to clarify the naming, or at least to document this
JMarc
>---
> src/Paragraph.cpp | 15 +++++++++++++++
> src/Paragraph.h | 3 +++
> 2 files changed, 18 insertions(+)
>
>diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
>index d21e86ebbf..1d239ef5a0 100644
>--- a/src/Paragraph.cpp
>+++ b/src/Paragraph.cpp
>@@ -3350,6 +3350,21 @@ string Paragraph::getID(Buffer const &, OutputParams const &)
> }
>
>
>+string Paragraph::getLabel() const
>+{
>+ for (pos_type i = 0; i < size(); ++i) {
>+ if (Inset const * inset = getInset(i)) {
>+ InsetCode lyx_code = inset->lyxCode();
>+ if (lyx_code == LABEL_CODE) {
>+ InsetLabel const * const il = static_cast<InsetLabel const *>(inset);
>+ return to_utf8(il->getParam("name"));
>+ }
>+ }
>+ }
>+ return string();
>+}
>+
>+
> pos_type Paragraph::firstWordDocBook(XMLStream & xs, OutputParams const & runparams) const
> {
> pos_type i;
>diff --git a/src/Paragraph.h b/src/Paragraph.h
>index ef94352f37..ee27e170ec 100644
>--- a/src/Paragraph.h
>+++ b/src/Paragraph.h
>@@ -201,6 +201,9 @@ public:
> /// Get the id of the paragraph, useful for DocBook
> std::string getID(Buffer const & buf, OutputParams const & runparams) const;
>
>+ /// Get the (first) string of a \label in this paragraph, or empty string
>+ std::string getLabel() const;
>+
> /// Output the first word of a paragraph, return the position where it left.
> pos_type firstWordDocBook(XMLStream & xs, OutputParams const & runparams) const;
>
More information about the lyx-devel
mailing list