Skip to content

Commit

Permalink
switch to std::regex
Browse files Browse the repository at this point in the history
  • Loading branch information
rettinghaus committed Aug 24, 2024
1 parent 334cdb5 commit 453f510
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/importexport/musicxml/internal/musicxml/exportxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8701,14 +8701,14 @@ void ExportMusicXml::harmony(Harmony const* const h, FretDiagram const* const fd
String functionText = h->hFunction();
if (functionText.empty()) {
// we just dump the text as deprecated function
m_xml.tag("function", h->musicXmlText());
m_xml.tag("function", textName);
m_xml.tag("kind", "none");
break;
}
m_xml.startElement("numeral");
if (!functionText.at(0).isDigit()) {
} else if (!functionText.at(0).isDigit()) {
alter = functionText.at(0);
functionText = functionText.at(1);
}
m_xml.startElement("numeral");
m_xml.tag("numeral-root", functionText);
if (alter == u"b") {
m_xml.tag("numeral-alter", "-1");
Expand All @@ -8730,20 +8730,19 @@ void ExportMusicXml::harmony(Harmony const* const h, FretDiagram const* const fd
}
m_xml.tagRaw(s, h->xmlKind());
} else {
m_xml.tag("kind", "none");
// default is major
m_xml.tag("kind", "major");
}
}
break;
case HarmonyType::ROMAN: {
QRegularExpression romanRegex("[iv]+", QRegularExpression::CaseInsensitiveOption);
QRegularExpressionMatch romanMatch = romanRegex.match(textName);
if (romanMatch.capturedTexts().size()) {
String rootText = romanMatch.capturedTexts()[0];
static const std::regex roman("[iv]+|[IV]+");
if (std::regex_match(textName.toStdString(), roman)) {
m_xml.startElement("numeral");
m_xml.tag("numeral-root", { { "text", rootText } }, "1");
m_xml.tag("numeral-root", { { "text", textName } }, "1");
m_xml.endElement();
// only check for major or minor
m_xml.tag("kind", rootText.at(0).isUpper() ? "major" : "minor");
m_xml.tag("kind", textName.at(0).isUpper() ? "major" : "minor");
break;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/importexport/musicxml/tests/data/testHarmony6_ref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ containing recognized text, unrecognized plaintext and unrecognized text requiri
<measure number="6">
<harmony print-frame="no">
<function>xyz</function>
<kind>none</kind>
</harmony>
<note>
<pitch>
Expand Down Expand Up @@ -221,6 +222,7 @@ containing recognized text, unrecognized plaintext and unrecognized text requiri
<measure number="9">
<harmony print-frame="no">
<function>&lt;&gt;&amp;&quot;</function>
<kind>none</kind>
</harmony>
<note>
<pitch>
Expand Down

0 comments on commit 453f510

Please sign in to comment.