Skip to content

Commit

Permalink
Forbid space in score definition with single line input. Fixes #3692
Browse files Browse the repository at this point in the history
* Left allowed in PAE1
  • Loading branch information
lpugin committed Jun 12, 2024
1 parent 50011d1 commit d36412c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/iopae.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2307,7 +2307,8 @@ enum {
ERR_063_LIGATURE_PITCH,
ERR_064_LIGATURE_DURATION,
ERR_065_MREST_INVALID_MEASURE,
ERR_066_EMPTY_CONTAINER
ERR_066_EMPTY_CONTAINER,
ERR_067_SPACE_IN_SCOREDEF
};

// clang-format off
Expand Down Expand Up @@ -2377,7 +2378,8 @@ const std::map<int, std::string> PAEInput::s_errCodes{
{ ERR_063_LIGATURE_PITCH, "A ligature cannot have two consecutive notes with the same pitch." },
{ ERR_064_LIGATURE_DURATION, "The duration in a ligature cannot be shorter than a semibreve." },
{ ERR_065_MREST_INVALID_MEASURE, "A measure with a measure rest cannot include anything else." },
{ ERR_066_EMPTY_CONTAINER, "A grace group or a beam cannot be empty." }
{ ERR_066_EMPTY_CONTAINER, "A grace group or a beam cannot be empty." },
{ ERR_067_SPACE_IN_SCOREDEF, "Single-line input should have no space within the score definition."}
};
// clang-format on

Expand Down Expand Up @@ -2736,18 +2738,26 @@ jsonxx::Object PAEInput::SingleLineToJson(const std::string &singleLine)
std::string::const_iterator start = singleLine.begin() + startPos;
std::string::const_iterator scoreDefEnd;
while ((scoreDefEnd = std::find(start, singleLine.end(), ' ')) != singleLine.end()) {
if (*(scoreDefEnd + 1) != '@' || *(scoreDefEnd + 1) != '$') break;
if (*(scoreDefEnd + 1) != '@' && *(scoreDefEnd + 1) != '$') break;
start = scoreDefEnd + 1;
}

if (std::find(singleLine.begin(), scoreDefEnd, ' ') != scoreDefEnd) {
if (v2) {
pae::Token inputToken(0, pae::INPUT_POS);
LogPAE(ERR_067_SPACE_IN_SCOREDEF, inputToken);
if (m_pedanticMode) return jsonInput;
}
}

// Extract the beginning of each scoreDef element and add flags indicating existence
std::string::const_iterator clefStart = singleLine.begin();
std::string::const_iterator keysigStart = std::find(singleLine.begin(), scoreDefEnd, '$');
std::string::const_iterator clefStart = singleLine.begin() + startPos;
std::string::const_iterator keysigStart = std::find(clefStart, scoreDefEnd, '$');
const bool hasKeysig = (keysigStart != scoreDefEnd);
std::string::const_iterator timesigStart = std::find(singleLine.begin(), scoreDefEnd, '@');
std::string::const_iterator timesigStart = std::find(clefStart, scoreDefEnd, '@');
const bool hasTimesig = (timesigStart != scoreDefEnd);

std::string::const_iterator clefEnd = singleLine.begin() + 4;
std::string::const_iterator clefEnd = clefStart + 4;
std::string clef = std::string(clefStart + 1, clefEnd);

std::string keysig;
Expand Down Expand Up @@ -2824,7 +2834,7 @@ bool PAEInput::Import(const std::string &input)
return false;
}
}
else if (input.at(0) == '%') {
else if (input.at(0) == '%' || input.at(0) == ';') {
jsonInput = this->SingleLineToJson(input);
}
else {
Expand Down
3 changes: 3 additions & 0 deletions src/toolkit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ FileFormat Toolkit::IdentifyInputFrom(const std::string &data)
if (data[0] == '%' && data.size() > 1) {
return (data[1] == 'a') ? ABC : PAE;
}
if (data[0] == ';') {
return PAE;
}
if ((unsigned char)data[0] == 0xff || (unsigned char)data[0] == 0xfe) {
// Handle UTF-16 content here later.
std::cerr << "Warning: Cannot yet auto-detect format of UTF-16 data files." << std::endl;
Expand Down

0 comments on commit d36412c

Please sign in to comment.