commit 392af2012a37c2b27ea5a9e976964adf35e281b3
Author: Juergen Spitzmueller <[email protected]>
Date: Sun Nov 23 17:24:20 2025 +0100
factor out SpecialChar code
to make this available to other places
---
src/Makefile.am | 2 +
src/SpecialChar.cpp | 179 +++++++++++++++++++++++++++++++++++++++++++++
src/SpecialChar.h | 61 +++++++++++++++
src/TextClass.cpp | 148 +------------------------------------
src/TextClass.h | 22 +-----
src/tex2lyx/CMakeLists.txt | 2 +-
src/tex2lyx/Makefile.am | 1 +
7 files changed, 247 insertions(+), 168 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index 15d67d31ce..7d0117fd46 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -282,6 +282,8 @@ liblyxcore_a_SOURCES = \
Session.h \
Spacing.cpp \
Spacing.h \
+ SpecialChar.cpp \
+ SpecialChar.h \
SpellChecker.h \
Statistics.cpp \
Statistics.h \
diff --git a/src/SpecialChar.cpp b/src/SpecialChar.cpp
new file mode 100644
index 0000000000..4ef1786e01
--- /dev/null
+++ b/src/SpecialChar.cpp
@@ -0,0 +1,179 @@
+/**
+ * \file SpecialChar.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Jürgen Spitzmüller
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "SpecialChar.h"
+
+#include "support/Lexer.h"
+#include "support/lstrings.h"
+
+#ifdef ERROR
+#undef ERROR
+#endif
+
+using namespace std;
+using namespace lyx::support;
+
+namespace lyx {
+
+SpecialChars specialchars;
+
+SpecialChar SpecialChars::readSpecialChars(Lexer & lexrc, SpecialChar & sc)
const
+{
+ enum {
+ SC_LYX_OUTPUT,
+ SC_LATEX_OUTPUT,
+ SC_LATEX_OUTPUT_RTL,
+ SC_LATEX_OUTPUT_UTF8,
+ SC_PLAINTEXT_OUTPUT,
+ SC_XHTML_OUTPUT,
+ SC_TOOLTIP,
+ SC_MENUSTRING,
+ SC_REQUIRES,
+ SC_FORCE_LTR,
+ SC_IS_CHAR,
+ SC_IS_LETTER,
+ SC_CAN_BREAK_AFTER,
+ SC_FONT,
+ SC_NEED_PROTECT,
+ SC_TYPE,
+ SC_END
+ };
+
+ LexerKeyword specialCharTags[] = {
+ {"canbreakafter", SC_CAN_BREAK_AFTER },
+ {"end", SC_END },
+ {"font", SC_FONT },
+ {"forceltr", SC_FORCE_LTR },
+ {"ischar", SC_IS_CHAR },
+ {"isletter", SC_IS_LETTER },
+ {"latexoutput", SC_LATEX_OUTPUT },
+ {"latexoutputrtl", SC_LATEX_OUTPUT_RTL },
+ {"latexoutpututf8", SC_LATEX_OUTPUT_UTF8 },
+ {"lyxoutput", SC_LYX_OUTPUT },
+ {"menustring", SC_MENUSTRING },
+ {"needprotect", SC_NEED_PROTECT },
+ {"plaintextoutput", SC_PLAINTEXT_OUTPUT },
+ {"requires", SC_REQUIRES },
+ {"tooltip", SC_TOOLTIP },
+ {"type", SC_TYPE },
+ {"xhtmloutput", SC_XHTML_OUTPUT }
+ };
+
+ lexrc.pushTable(specialCharTags);
+ bool getout = false;
+ while (!getout && lexrc.isOK()) {
+ int le = lexrc.lex();
+ switch (le) {
+ case Lexer::LEX_UNDEF:
+ lexrc.printError("Unknown SpecialChar tag `$$Token'");
+ continue;
+ default:
+ break;
+ }
+ switch (le) {
+ case SC_CAN_BREAK_AFTER:
+ lexrc.next();
+ sc.can_break_after = lexrc.getBool();
+ break;
+ case SC_FORCE_LTR:
+ lexrc.next();
+ sc.force_ltr = lexrc.getBool();
+ break;
+ case SC_IS_CHAR:
+ lexrc.next();
+ sc.is_char = lexrc.getBool();
+ break;
+ case SC_IS_LETTER:
+ lexrc.next();
+ sc.is_letter = lexrc.getBool();
+ break;
+ case SC_NEED_PROTECT:
+ lexrc.next();
+ sc.need_protect = lexrc.getBool();
+ break;
+ case SC_MENUSTRING:
+ lexrc.eatLine();
+ sc.menustring = trim(lexrc.getString(), "\"");
+ break;
+ case SC_LATEX_OUTPUT: {
+ lexrc.next(true);
+ docstring const res = rtrim(lexrc.getDocString());
+ if (isHex(res))
+ sc.latex_output = docstring(1, hexToInt(res));
+ else
+ sc.latex_output = rtrim(lexrc.getDocString());
+ break;
+ }
+ case SC_LATEX_OUTPUT_RTL: {
+ lexrc.next(true);
+ docstring const res = rtrim(lexrc.getDocString());
+ if (isHex(res))
+ sc.latex_output_rtl = docstring(1,
hexToInt(res));
+ else
+ sc.latex_output_rtl =
rtrim(lexrc.getDocString());
+ break;
+ }
+ case SC_LATEX_OUTPUT_UTF8: {
+ lexrc.next(true);
+ docstring const res = rtrim(lexrc.getDocString());
+ if (isHex(res))
+ sc.latex_output_utf8 = docstring(1,
hexToInt(res));
+ else
+ sc.latex_output_utf8 =
rtrim(lexrc.getDocString());
+ break;
+ }
+ case SC_LYX_OUTPUT: {
+ lexrc.next();
+ docstring const res = rtrim(lexrc.getDocString());
+ if (isHex(res))
+ sc.lyx_output = docstring(1, hexToInt(res));
+ else
+ sc.lyx_output = rtrim(lexrc.getDocString());
+ break;
+ }
+ case SC_PLAINTEXT_OUTPUT: {
+ lexrc.next();
+ docstring const res = rtrim(lexrc.getDocString());
+ if (isHex(res))
+ sc.plaintext_output = docstring(1,
hexToInt(res));
+ else
+ sc.plaintext_output =
rtrim(lexrc.getDocString());
+ break;
+ }
+ case SC_REQUIRES:
+ lexrc.eatLine();
+ sc.req = lexrc.getString();
+ break;
+ case SC_TOOLTIP:
+ lexrc.next();
+ sc.tooltip = rtrim(lexrc.getDocString());
+ break;
+ case SC_TYPE:
+ lexrc.next();
+ sc.type = lowercase(lexrc.getString());
+ break;
+ case SC_XHTML_OUTPUT:
+ lexrc.next();
+ sc.xhtml_output = rtrim(lexrc.getDocString());
+ break;
+ case SC_FONT:
+ sc.font = lyxRead(lexrc, sc.font);
+ break;
+ case SC_END:
+ getout = true;
+ break;
+ }
+ }
+ return sc;
+}
+
+} // namespace lyx
diff --git a/src/SpecialChar.h b/src/SpecialChar.h
new file mode 100644
index 0000000000..3dc963c18d
--- /dev/null
+++ b/src/SpecialChar.h
@@ -0,0 +1,61 @@
+// -*- C++ -*-
+/**
+ * \file SpecialChar.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef SPECIALCHAR_H
+#define SPECIALCHAR_H
+
+#include "FontInfo.h"
+
+#include "support/docstring.h"
+
+#ifdef ERROR
+#undef ERROR
+#endif
+
+namespace lyx {
+
+namespace support {
+class Lexer;
+}
+
+class SpecialChar
+{
+public:
+ docstring lyx_output;
+ docstring latex_output;
+ docstring latex_output_rtl;
+ docstring latex_output_utf8;
+ docstring plaintext_output;
+ docstring xhtml_output;
+ docstring tooltip;
+ std::string menustring;
+ std::string req;
+ std::string type;
+ bool can_break_after = false;
+ bool is_letter = false;
+ bool is_char = false;
+ bool need_protect = false;
+ bool force_ltr = false;
+ FontInfo font;
+};
+
+class SpecialChars
+{
+public:
+ ///
+ SpecialChar readSpecialChars(support::Lexer &, SpecialChar & sc) const;
+};
+
+/// Global singleton instance.
+extern SpecialChars specialchars;
+
+
+} // namespace lyx
+
+#endif
diff --git a/src/TextClass.cpp b/src/TextClass.cpp
index 987c13f87a..7462af8245 100644
--- a/src/TextClass.cpp
+++ b/src/TextClass.cpp
@@ -1149,155 +1149,11 @@ void TextClass::readSpecialChars(Lexer & lexrc)
lexrc.printError("No type given for SpecialChar: `$$Token'.");
return;
}
- enum {
- SC_LYX_OUTPUT,
- SC_LATEX_OUTPUT,
- SC_LATEX_OUTPUT_RTL,
- SC_LATEX_OUTPUT_UTF8,
- SC_PLAINTEXT_OUTPUT,
- SC_XHTML_OUTPUT,
- SC_TOOLTIP,
- SC_MENUSTRING,
- SC_REQUIRES,
- SC_FORCE_LTR,
- SC_IS_CHAR,
- SC_IS_LETTER,
- SC_CAN_BREAK_AFTER,
- SC_FONT,
- SC_NEED_PROTECT,
- SC_TYPE,
- SC_END
- };
-
- LexerKeyword specialCharTags[] = {
- {"canbreakafter", SC_CAN_BREAK_AFTER },
- {"end", SC_END },
- {"font", SC_FONT },
- {"forceltr", SC_FORCE_LTR },
- {"ischar", SC_IS_CHAR },
- {"isletter", SC_IS_LETTER },
- {"latexoutput", SC_LATEX_OUTPUT },
- {"latexoutputrtl", SC_LATEX_OUTPUT_RTL },
- {"latexoutpututf8", SC_LATEX_OUTPUT_UTF8 },
- {"lyxoutput", SC_LYX_OUTPUT },
- {"menustring", SC_MENUSTRING },
- {"needprotect", SC_NEED_PROTECT },
- {"plaintextoutput", SC_PLAINTEXT_OUTPUT },
- {"requires", SC_REQUIRES },
- {"tooltip", SC_TOOLTIP },
- {"type", SC_TYPE },
- {"xhtmloutput", SC_XHTML_OUTPUT }
- };
-
- lexrc.pushTable(specialCharTags);
- bool getout = false;
SpecialChar sc;
if (special_chars_.find(name) != special_chars_.end())
sc = special_chars_[name];
- while (!getout && lexrc.isOK()) {
- int le = lexrc.lex();
- switch (le) {
- case Lexer::LEX_UNDEF:
- lexrc.printError("Unknown SpecialChar tag `$$Token'");
- continue;
- default:
- break;
- }
- switch (le) {
- case SC_CAN_BREAK_AFTER:
- lexrc.next();
- sc.can_break_after = lexrc.getBool();
- break;
- case SC_FORCE_LTR:
- lexrc.next();
- sc.force_ltr = lexrc.getBool();
- break;
- case SC_IS_CHAR:
- lexrc.next();
- sc.is_char = lexrc.getBool();
- break;
- case SC_IS_LETTER:
- lexrc.next();
- sc.is_letter = lexrc.getBool();
- break;
- case SC_NEED_PROTECT:
- lexrc.next();
- sc.need_protect = lexrc.getBool();
- break;
- case SC_MENUSTRING:
- lexrc.eatLine();
- sc.menustring = trim(lexrc.getString(), "\"");
- break;
- case SC_LATEX_OUTPUT: {
- lexrc.next(true);
- docstring const res = rtrim(lexrc.getDocString());
- if (isHex(res))
- sc.latex_output = docstring(1, hexToInt(res));
- else
- sc.latex_output = rtrim(lexrc.getDocString());
- break;
- }
- case SC_LATEX_OUTPUT_RTL: {
- lexrc.next(true);
- docstring const res = rtrim(lexrc.getDocString());
- if (isHex(res))
- sc.latex_output_rtl = docstring(1,
hexToInt(res));
- else
- sc.latex_output_rtl =
rtrim(lexrc.getDocString());
- break;
- }
- case SC_LATEX_OUTPUT_UTF8: {
- lexrc.next(true);
- docstring const res = rtrim(lexrc.getDocString());
- if (isHex(res))
- sc.latex_output_utf8 = docstring(1,
hexToInt(res));
- else
- sc.latex_output_utf8 =
rtrim(lexrc.getDocString());
- break;
- }
- case SC_LYX_OUTPUT: {
- lexrc.next();
- docstring const res = rtrim(lexrc.getDocString());
- if (isHex(res))
- sc.lyx_output = docstring(1, hexToInt(res));
- else
- sc.lyx_output = rtrim(lexrc.getDocString());
- break;
- }
- case SC_PLAINTEXT_OUTPUT: {
- lexrc.next();
- docstring const res = rtrim(lexrc.getDocString());
- if (isHex(res))
- sc.plaintext_output = docstring(1,
hexToInt(res));
- else
- sc.plaintext_output =
rtrim(lexrc.getDocString());
- break;
- }
- case SC_REQUIRES:
- lexrc.eatLine();
- sc.req = lexrc.getString();
- break;
- case SC_TOOLTIP:
- lexrc.next();
- sc.tooltip = rtrim(lexrc.getDocString());
- break;
- case SC_TYPE:
- lexrc.next();
- sc.type = lowercase(lexrc.getString());
- break;
- case SC_XHTML_OUTPUT:
- lexrc.next();
- sc.xhtml_output = rtrim(lexrc.getDocString());
- break;
- case SC_FONT:
- sc.font = lyxRead(lexrc, sc.font);
- break;
- case SC_END:
- getout = true;
- break;
- }
- }
- special_chars_[name] = sc;
+
+ special_chars_[name] = specialchars.readSpecialChars(lexrc, sc);
lexrc.popTable();
}
diff --git a/src/TextClass.h b/src/TextClass.h
index 4731b131f4..4816840ae0 100644
--- a/src/TextClass.h
+++ b/src/TextClass.h
@@ -17,6 +17,7 @@
#include "FontInfo.h"
#include "LayoutEnums.h"
#include "LayoutModuleList.h"
+#include "SpecialChar.h"
#include "insets/InsetLayout.h"
@@ -43,27 +44,6 @@ class FloatList;
class Layout;
class LayoutFile;
-class SpecialChar
-{
-public:
- docstring lyx_output;
- docstring latex_output;
- docstring latex_output_rtl;
- docstring latex_output_utf8;
- docstring plaintext_output;
- docstring xhtml_output;
- docstring tooltip;
- std::string menustring;
- std::string req;
- std::string type;
- bool can_break_after = false;
- bool is_letter = false;
- bool is_char = false;
- bool need_protect = false;
- bool force_ltr = false;
- FontInfo font;
-};
-
/// Based upon ideas in boost::noncopyable, inheriting from this
/// class effectively makes the copy constructor protected but the
/// assignment constructor private.
diff --git a/src/tex2lyx/CMakeLists.txt b/src/tex2lyx/CMakeLists.txt
index 161b60f66d..cd2cdf0ceb 100644
--- a/src/tex2lyx/CMakeLists.txt
+++ b/src/tex2lyx/CMakeLists.txt
@@ -14,7 +14,7 @@ foreach(_src graphics/GraphicsParams insets/ExternalTemplate
insets/ExternalTransforms insets/InsetLayout Author CiteEnginesList
Color Counters
Encoding FloatList Floating FontInfo LaTeXPackages Layout
LayoutFile LayoutModuleList support/Lexer ModuleList TextClass
- LaTeXColors Spacing version)
+ LaTeXColors Spacing SpecialChar version)
list(APPEND LINKED_sources ${TOP_SRC_DIR}/src/${_src}.cpp)
list(APPEND LINKED_headers ${TOP_SRC_DIR}/src/${_src}.h)
endforeach(_src)
diff --git a/src/tex2lyx/Makefile.am b/src/tex2lyx/Makefile.am
index c19bc2723e..3a1db4ca76 100644
--- a/src/tex2lyx/Makefile.am
+++ b/src/tex2lyx/Makefile.am
@@ -106,6 +106,7 @@ LYX_OBJS = \
../LayoutModuleList.o \
../ModuleList.o \
../Spacing.o \
+ ../SpecialChar.o \
../TextClass.o \
../version.o
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs