From df025d15df89dac100a368eed7c86a5b754e9f7c Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Mon, 26 Dec 2022 20:23:05 +0100 Subject: [PATCH] InsetIPAMacro: refactor code between DocBook and XHTML. --- src/insets/InsetIPAMacro.cpp | 67 +++++++++++------------------------- 1 file changed, 21 insertions(+), 46 deletions(-) diff --git a/src/insets/InsetIPAMacro.cpp b/src/insets/InsetIPAMacro.cpp index a529d04b08..5aeaf8432a 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 "˥˩"; + case InsetIPAChar::Kind::TONE_RISING: + return "˩˥"; + case InsetIPAChar::Kind::TONE_HIGH_RISING: + return "˧˥"; + case InsetIPAChar::Kind::TONE_LOW_RISING: + return "˩˧"; + case InsetIPAChar::Kind::TONE_HIGH_RISING_FALLING: + return "˨˥˨"; + } + return ""; +} +} + + void InsetIPAChar::docbook(XMLStream & xs, OutputParams const &) const { - switch (kind_) { - case TONE_FALLING: - xs << XMLStream::ESCAPE_NONE << "˥"; - xs << XMLStream::ESCAPE_NONE << "˩"; - break; - case TONE_RISING: - xs << XMLStream::ESCAPE_NONE << "˩"; - xs << XMLStream::ESCAPE_NONE << "˥"; - break; - case TONE_HIGH_RISING: - xs << XMLStream::ESCAPE_NONE << "˧"; - xs << XMLStream::ESCAPE_NONE << "˥"; - break; - case TONE_LOW_RISING: - xs << XMLStream::ESCAPE_NONE << "˩"; - xs << XMLStream::ESCAPE_NONE << "˧"; - break; - case TONE_HIGH_RISING_FALLING: - xs << XMLStream::ESCAPE_NONE << "˨"; - xs << XMLStream::ESCAPE_NONE << "˥"; - xs << XMLStream::ESCAPE_NONE << "˨"; - 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 << "˥" - << XMLStream::ESCAPE_NONE << "˩"; - break; - case TONE_RISING: - xs << XMLStream::ESCAPE_NONE << "˩" - << XMLStream::ESCAPE_NONE << "˥"; - break; - case TONE_HIGH_RISING: - xs << XMLStream::ESCAPE_NONE << "˧" - << XMLStream::ESCAPE_NONE << "˥"; - break; - case TONE_LOW_RISING: - xs << XMLStream::ESCAPE_NONE << "˩" - << XMLStream::ESCAPE_NONE << "˧"; - break; - case TONE_HIGH_RISING_FALLING: - xs << XMLStream::ESCAPE_NONE << "˨" - << XMLStream::ESCAPE_NONE << "˥" - << XMLStream::ESCAPE_NONE << "˨"; - break; - } + xs << XMLStream::ESCAPE_NONE << from_ascii(ipaCharToXMLEntity(kind())); return docstring(); }