InsetIPAMacro: refactor code between DocBook and XHTML.

This commit is contained in:
Thibaut Cuvelier 2022-12-26 20:23:05 +01:00
parent 21d1d917ba
commit df025d15df

View File

@ -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 << "&#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();
}