Skip to content

Commit

Permalink
Prevent empty data tokens in fb spines
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangDrescher committed Dec 8, 2023
1 parent 1d626d8 commit 874e308
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
13 changes: 12 additions & 1 deletion min/humlib.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Programmer: Craig Stuart Sapp <[email protected]>
// Creation Date: Sat Aug 8 12:24:49 PDT 2015
// Last Modified: Fr 8 Dez 2023 00:13:22 CET
// Last Modified: Fr 8 Dez 2023 12:36:58 CET
// Filename: min/humlib.cpp
// URL: https://github.com/craigsapp/humlib/blob/master/min/humlib.cpp
// Syntax: C++11
Expand Down Expand Up @@ -101949,6 +101949,17 @@ string Tool_musicxml2hum::getFiguredBassString(xml_node fnode) {
}
}

output = std::regex_replace(output, std::regex("^ +| +$|( ) +"), "$1");

This comment has been minimized.

Copy link
@craigsapp

craigsapp Dec 8, 2023

Owner

Ideally this would be:

HumRegex hre;
hre.replaceDestructive(output, "$1", "^ +| +$|( ) +");

Or regex could use \\s instead of to make it easier to read the spaces:

hre.replaceDestructive(output, "$1", "^\\s+|\\s+$|(\\s)\\s+");

Or using a literal string to not need to escape the backslashes:

R"(^\s+|\s+$|(\s)\s+)"

I don't understand the regular expression in any case: $1 would only be a space in the case ( ) +, and empty in the first two cases. So I am wondering what this line does?

This comment has been minimized.

Copy link
@WolfgangDrescher

WolfgangDrescher Dec 8, 2023

Author Contributor

I have pushed an update for this regex (c03994d):

hre.replaceDestructive(output, "", R"(^\s+|\s+$)");

Basically I just wanted to trim whitespaces from the beginning and ending of the string. It seems like there is no nativ C++ function for this case, is it? That's why I used a regex.


if (output.empty()) {
if (children.size()) {
cerr << "WARNING: figured bass string is empty but has "
<< children.size() << " figure elements as children. "
<< "The output has been replaced with \".\"" << endl;
}
output = ".";
}

return output;

// HTp fbtok = new HumdrumToken(fbstring);
Expand Down
2 changes: 1 addition & 1 deletion min/humlib.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Programmer: Craig Stuart Sapp <[email protected]>
// Creation Date: Sat Aug 8 12:24:49 PDT 2015
// Last Modified: Fr 8 Dez 2023 00:13:22 CET
// Last Modified: Fr 8 Dez 2023 12:36:58 CET
// Filename: min/humlib.h
// URL: https://github.com/craigsapp/humlib/blob/master/min/humlib.h
// Syntax: C++11
Expand Down
11 changes: 11 additions & 0 deletions src/tool-musicxml2hum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3081,6 +3081,17 @@ string Tool_musicxml2hum::getFiguredBassString(xml_node fnode) {
}
}

output = std::regex_replace(output, std::regex("^ +| +$|( ) +"), "$1");

if (output.empty()) {
if (children.size()) {
cerr << "WARNING: figured bass string is empty but has "
<< children.size() << " figure elements as children. "
<< "The output has been replaced with \".\"" << endl;
}
output = ".";
}

return output;

// HTp fbtok = new HumdrumToken(fbstring);
Expand Down

0 comments on commit 874e308

Please sign in to comment.