[LyX/master] InsetIPAMacro: refactor code between DocBook and XHTML.

Thibaut Cuvelier tcuvelier at lyx.org
Mon Dec 26 18:25:57 UTC 2022


commit df025d15df89dac100a368eed7c86a5b754e9f7c
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Mon Dec 26 20:23:05 2022 +0100

    InsetIPAMacro: refactor code between DocBook and XHTML.
---
 src/insets/InsetIPAMacro.cpp |   67 +++++++++++++----------------------------
 1 files changed, 21 insertions(+), 46 deletions(-)

diff --git a/src/insets/InsetIPAMacro.cpp b/src/insets/InsetIPAMacro.cpp
index a529d04..5aeaf84 100644
--- a/src/insets/InsetIPAMacro.cpp
+++ b/src/insets/InsetIPAMacro.cpp
@@ -553,59 +553,34 @@ int InsetIPAChar::plaintext(odocstringstream & os, OutputParams const &, size_t)
 }
 
 
+namespace {
+std::string ipaCharToXMLEntity(InsetIPAChar::Kind kind) {
+	switch (kind) {
+	case InsetIPAChar::Kind::TONE_FALLING:
+		return "&#x2e5;&#x2e9;";
+	case InsetIPAChar::Kind::TONE_RISING:
+		return "&#x2e9;&#x2e5;";
+	case InsetIPAChar::Kind::TONE_HIGH_RISING:
+		return "&#x2e7;&#x2e5;";
+	case InsetIPAChar::Kind::TONE_LOW_RISING:
+		return "&#x2e9;&#x2e7;";
+	case InsetIPAChar::Kind::TONE_HIGH_RISING_FALLING:
+		return "&#x2e8;&#x2e5;&#x2e8;";
+	}
+	return "";
+}
+}
+
+
 void InsetIPAChar::docbook(XMLStream & xs, OutputParams const &) const
 {
-	switch (kind_) {
-	case TONE_FALLING:
-		xs << XMLStream::ESCAPE_NONE << "&#x2e5;";
-		xs << XMLStream::ESCAPE_NONE << "&#x2e9;";
-		break;
-	case TONE_RISING:
-		xs << XMLStream::ESCAPE_NONE << "&#x2e9;";
-		xs << XMLStream::ESCAPE_NONE << "&#x2e5;";
-		break;
-	case TONE_HIGH_RISING:
-		xs << XMLStream::ESCAPE_NONE << "&#x2e7;";
-		xs << XMLStream::ESCAPE_NONE << "&#x2e5;";
-		break;
-	case TONE_LOW_RISING:
-		xs << XMLStream::ESCAPE_NONE << "&#x2e9;";
-		xs << XMLStream::ESCAPE_NONE << "&#x2e7;";
-		break;
-	case TONE_HIGH_RISING_FALLING:
-		xs << XMLStream::ESCAPE_NONE << "&#x2e8;";
-		xs << XMLStream::ESCAPE_NONE << "&#x2e5;";
-		xs << XMLStream::ESCAPE_NONE << "&#x2e8;";
-		break;
-	}
+	xs << XMLStream::ESCAPE_NONE << from_ascii(ipaCharToXMLEntity(kind()));
 }
 
 
 docstring InsetIPAChar::xhtml(XMLStream & xs, OutputParams const &) const
 {
-	switch (kind_) {
-	case TONE_FALLING:
-		xs << XMLStream::ESCAPE_NONE << "&#x2e5;"
-		   << XMLStream::ESCAPE_NONE << "&#x2e9;";
-		break;
-	case TONE_RISING:
-		xs << XMLStream::ESCAPE_NONE << "&#x2e9;"
-		   << XMLStream::ESCAPE_NONE << "&#x2e5;";
-		break;
-	case TONE_HIGH_RISING:
-		xs << XMLStream::ESCAPE_NONE << "&#x2e7;"
-		   << XMLStream::ESCAPE_NONE << "&#x2e5;";
-		break;
-	case TONE_LOW_RISING:
-		xs << XMLStream::ESCAPE_NONE << "&#x2e9;"
-		   << XMLStream::ESCAPE_NONE << "&#x2e7;";
-		break;
-	case TONE_HIGH_RISING_FALLING:
-		xs << XMLStream::ESCAPE_NONE << "&#x2e8;"
-		   << XMLStream::ESCAPE_NONE << "&#x2e5;"
-		   << XMLStream::ESCAPE_NONE << "&#x2e8;";
-		break;
-	}
+	xs << XMLStream::ESCAPE_NONE << from_ascii(ipaCharToXMLEntity(kind()));
 	return docstring();
 }
 


More information about the lyx-cvs mailing list