Need to quote and escape in some further situations

This commit is contained in:
Matthias Neeracher 2008-08-15 13:28:06 +00:00
parent f0b6bdf907
commit 782b37d572

View File

@ -202,10 +202,12 @@ static std::string LilypondPitchName(int8_t pitch, bool useSharps)
static std::string EscapeSyllable(std::string syll) static std::string EscapeSyllable(std::string syll)
{ {
bool seenAlpha = false;
for (size_t i=0; i<syll.size(); ++i) for (size_t i=0; i<syll.size(); ++i)
if (isalpha(syll[i])) if (isalpha(syll[i])) {
seenAlpha = true;
continue; continue;
else } else {
switch (syll[i]) { switch (syll[i]) {
case '-': case '-':
case ':': case ':':
@ -214,10 +216,13 @@ static std::string EscapeSyllable(std::string syll)
case ';': case ';':
case '\'': case '\'':
case '_': case '_':
if (seenAlpha)
continue; continue;
/* Else fall through */
default: default:
goto escape; goto escape;
} }
}
// //
// Purely alphabetic syllable, no need to escape. // Purely alphabetic syllable, no need to escape.
// //
@ -225,6 +230,11 @@ static std::string EscapeSyllable(std::string syll)
escape: escape:
size_t q=0; size_t q=0;
while ((q = syll.find_first_of('\\', q)) != std::string::npos) {
syll.replace(q, 1, "\\\\", 2);
q += 2;
}
q = 0;
while ((q = syll.find_first_of('"', q)) != std::string::npos) { while ((q = syll.find_first_of('"', q)) != std::string::npos) {
syll.replace(q, 1, "\\\"", 2); syll.replace(q, 1, "\\\"", 2);
q += 2; q += 2;