Handle updated document description format

parentheses are rarely if ever used independently, so trim the unmatched
ones regardless of whether we find the starting parenthesis in the
description

Fixes https://gitlab.com/kicad/code/kicad/issues/11403

(cherry picked from commit be7e9d300e)
This commit is contained in:
Seth Hillbrand 2022-04-15 11:15:46 -07:00
parent d600fd3498
commit b6e7bf4768
1 changed files with 14 additions and 24 deletions

View File

@ -100,36 +100,26 @@ public:
if( idx >= 0 ) if( idx >= 0 )
{ {
// And, sadly, it appears to have also become customary to bury the url inside int nesting = 0;
// parentheses.
if( idx >= 1 && desc.at( idx - 1 ) == '(' ) for( auto chit = desc.begin() + idx; chit != desc.end(); ++chit )
{ {
int nesting = 0; int ch = *chit;
while( idx < (int) desc.size() ) // Break on invalid URI characters
{ if( ch <= 0x20 || ch >= 0x7F || ch == '"' )
char c = desc.at( idx++ ); break;
if( c == '(' ) // Check for nesting parentheses, e.g. (Body style from: https://this.url/part.pdf)
nesting++; if( ch == '(' )
else if( c == ')' && --nesting < 0 ) ++nesting;
break; else if( ch == ')' && --nesting < 0 )
break;
doc += c; doc += ch;
} }
desc.Replace( doc, _( "doc url" ) ); desc.Replace( doc, _( "doc url" ) );
}
else
{
doc = desc.substr( (unsigned) idx );
desc = desc.substr( 0, (unsigned) idx );
desc = desc.Trim( true );
if( !desc.IsEmpty() && desc.Last() == ',' )
desc.RemoveLast( 1 );
}
} }
m_html.Replace( "__NAME__", EscapeHTML( name ) ); m_html.Replace( "__NAME__", EscapeHTML( name ) );