KiCad PCB EDA Suite
html_link_parser.cpp
Go to the documentation of this file.
1 
5 /*
6  * This program source code file is part of KiCad, a free EDA CAD application.
7  *
8  * Copyright (C) 1992-2014 KiCad Developers, see AUTHORS.txt for contributors.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 /*
29  * wxWidgets gives very few info about wxwebkit. For more info and more comments:
30  * see https://forums.wxwidgets.org/viewtopic.php?f=1&t=1119#
31  */
32 
33 #include <html_link_parser.h>
34 
35 bool LINK_TAGHANDLER::HandleTag(const wxHtmlTag& tag)
36 {
37  if( tag.HasParam( wxT("HREF") ) )
38  {
39  wxString href( tag.GetParam( wxT("HREF") ) );
40  // Add the first parameter (the link)
41  m_Parser->AddString( href );
42  // Parse other params, but do nothing, because the AddText() callback
43  // do nothing
44  ParseInner(tag);
45  return true;
46  }
47  else
48  return false;
49 }
50 
51 HTML_LINK_PARSER::HTML_LINK_PARSER( const wxString& aSrc, wxArrayString& aUrls )
52  : m_src( aSrc ), stringUrls( aUrls )
53 {
54  m_filter = NULL;
55  AddTagHandler( new LINK_TAGHANDLER(this) );
56 }
57 
58 
59 void HTML_LINK_PARSER::AddString( const wxString& aText )
60 {
61  wxString text = aText;
62  text.Trim( true );
63  text.Trim( false );
64 
65  if( ! m_filter || m_filter( text ) )
66  {
67  stringUrls.Add( text );
68  }
69 }