/*************************************************************************** * Copyright (C) 2007 by Andreas Eckstein * * andreas.eckstein@gmx.net * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "findurl.h" FindURL::~FindURL() { } FindURL::FindURL(KURL& kurl) : KURL(kurl) { parsePath(); } FindURL::FindURL(const KURL& kurl) : KURL(kurl) { parsePath(); } FindURL::FindURL(TQString urlstring) : KURL(urlstring) { parsePath(); } bool FindURL::hasFilter() { return m_filter!=TQString::null; } bool FindURL::hasSearch() { return m_search!=TQString::null; } bool FindURL::parsePath() { TQString p = path(); normalised = false; malformed = false; if(p.at(0)=='/') p=p.mid(1); else //leading slash is standard! if it wasn't there, we do normalisation when returning getURL()! normalised=true; //extract filter int lastslash = p.findRev('/'); if(lastslash>-1) { m_filter = p.mid(lastslash+1); p = p.left(lastslash); } //what is left has to be our search string m_search=p; //now for a few checks and normalisations if(m_search.find('/')>-1) { malformed = true; return false; } TQString nsearch = m_search.simplifyWhiteSpace(); nsearch = nsearch.replace(' ', "+"); if(nsearch!=m_search) { normalised = true; m_search = nsearch; } TQString np = "/"; np += (m_search + "/" + m_filter); setPath(np); return true; } bool FindURL::isMalformed() { return malformed; } bool FindURL::isNormalised() { return normalised; } TQString FindURL::search() { return m_search; } TQString FindURL::filter() { return m_filter; }