Skip to content

Commit

Permalink
Code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
CMakeScore committed Nov 13, 2024
1 parent 2d54b34 commit f241f95
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
18 changes: 11 additions & 7 deletions src/engraving/dom/dynamic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,23 +428,27 @@ void Dynamic::setDynamicType(const String& tag)

if (dt == DynamicType::OTHER) {
LOGD("setDynamicType: other <%s>", muPrintable(tag));
} else {
std::string utf8Tag = tag.toStdString();
const std::regex asciiDynamic(R"((?:\b))" + std::string(TConv::toXml(dt).ascii()) + R"((?:\b(?=[^>]|$)))");
utf8Tag = std::regex_replace(utf8Tag, asciiDynamic, DYN_LIST[int(dt)].text);
setXmlText(String::fromStdString(utf8Tag));
}

setDynamicType(dt);
}

DynamicType Dynamic::parseDynamicText(const String& tag)
DynamicType Dynamic::parseDynamicText(const String& tag) const
{
std::string utf8Tag = tag.toStdString();
std::regex dynamicRegex(R"((?:<sym>.*?</sym>)+|(?:\b)[fmnprsz]+(?:\b(?=[^>]|$)))");
for (std::sregex_iterator it(utf8Tag.begin(), utf8Tag.end(), dynamicRegex), end; it != end; ++it) {
std::smatch match = *it;
std::string matchStr = match.str();
const std::regex dynamicRegex(R"((?:<sym>.*?</sym>)+|(?:\b)[fmnprsz]+(?:\b(?=[^>]|$)))");
auto begin = std::sregex_iterator(utf8Tag.begin(), utf8Tag.end(), dynamicRegex);
for (auto it = begin; it != std::sregex_iterator(); ++it) {
const std::smatch match = *it;
const std::string matchStr = match.str();
size_t n = DYN_LIST.size();
for (size_t i = 0; i < n; ++i) {
if (TConv::toXml(DynamicType(i)).ascii() == matchStr || DYN_LIST[i].text == matchStr) {
utf8Tag.replace(match.position(0), match.length(0), DYN_LIST[i].text);
setXmlText(String::fromStdString(utf8Tag));
return DynamicType(i);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/dom/dynamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Dynamic final : public TextBase
void setDynamicType(DynamicType val) { m_dynamicType = val; }
void setDynamicType(const String&);

DynamicType parseDynamicText(const String&);
DynamicType parseDynamicText(const String&) const;

DynamicType dynamicType() const { return m_dynamicType; }
int subtype() const override { return static_cast<int>(m_dynamicType); }
Expand Down
1 change: 1 addition & 0 deletions src/engraving/dom/textedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ void TextBase::endEdit(EditData& ed)
Dynamic* d = toDynamic(this);
const DynamicType dt = d->parseDynamicText(xmlText());
undoChangeProperty(Pid::DYNAMIC_TYPE, dt);
d->setDynamicType(xmlText());
}

UndoStack* undo = score()->undoStack();
Expand Down

0 comments on commit f241f95

Please sign in to comment.