From 49b1aceb8bbbd7549f684a2950f3b08387b3f5fa Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 22 Mar 2021 21:18:34 +0000 Subject: [PATCH] Handle doc urls enclosed in parens. It seems this has become a common pattern in at least some of our libraries. Fixes https://gitlab.com/kicad/code/kicad/issues/7963 --- pcbnew/generate_footprint_info.cpp | 40 ++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/pcbnew/generate_footprint_info.cpp b/pcbnew/generate_footprint_info.cpp index 91fbab6800..bc1cadf4f7 100644 --- a/pcbnew/generate_footprint_info.cpp +++ b/pcbnew/generate_footprint_info.cpp @@ -94,15 +94,41 @@ public: // It is currently common practice to store a documentation link in the description. int idx = desc.find( wxT( "http:" ) ); + if( idx < 0 ) + idx = desc.find( wxT( "https:" ) ); + if( idx >= 0 ) { - doc = desc.substr( (unsigned) idx ); - - desc = desc.substr( 0, (unsigned) idx ); - desc = desc.Trim( true ); - - if( !desc.IsEmpty() && desc.Last() == ',' ) - desc.RemoveLast( 1 ); + // And, sadly, it appears to have also become customary to bury the url inside + // parentheses. + if( idx >= 1 && desc.at( idx - 1 ) == '(' ) + { + int nesting = 0; + + while( idx < (int) desc.size() ) + { + char c = desc.at( idx++ ); + + if( c == '(' ) + nesting++; + else if( c == ')' && --nesting < 0 ) + break; + + doc += c; + } + + 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 ) );