/***************************************************************************
- * Copyright (C) 2003 by Hideki Ikemoto *
- * ikemo@wakaba.jp *
- * *
- * 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. *
- ***************************************************************************/
+* Copyright (C) 2003 by Hideki Ikemoto *
+* ikemo@wakaba.jp *
+* *
+* 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. *
+***************************************************************************/
#include "kita_misc.h"
#include <kurl.h>
#include <qregexp.h>
-namespace Kita {
-
-QString datToBoard( const QString& datURL )
+QString Kita::datToBoard( const QString& datURL )
{
KURL url( datURL );
return KURL( url, "../" ).url();
}
-QString datToThread( const QString& datURL )
+QString Kita::datToThread( const QString& datURL )
{
- QRegExp regexp( "http://([^/]*)/([^/]*)/dat/(.*)\\.dat" );
- if( regexp.search( datURL ) == -1 ) {
- // no match
- return "";
- }
- QString url= QString( "http://%1/test/read.cgi/%2/%3/" )
- .arg( regexp.cap(1) )
- .arg( regexp.cap(2) )
- .arg( regexp.cap(3) );
- return url;
+ // http://<host>/<board>/dat/<datname>.dat
+ KURL url( datURL );
+ QString protocol = url.protocol();
+ QString host = url.host();
+
+ QStringList list = QStringList::split( ".", url.fileName() );
+ if ( list.size() != 2 ) {
+ return "";
+ }
+ QString datName = list[ 0 ];
+
+ url.cd( ".." );
+ if ( url.fileName() != "dat" ) {
+ return "";
+ }
+
+ url.cd( ".." );
+ QString board = url.fileName();
+
+ url.cd( ".." );
+ if ( url.fileName() != "" ) {
+ return "";
+ }
+
+ KURL newURL;
+ newURL.setProtocol( protocol );
+ newURL.setHost( host );
+ newURL.addPath( QString( "/test/read.cgi/%2/%3/" )
+ .arg( board ).arg( datName ) );
+
+ return newURL.url();
}
-QString threadToDat( const QString& threadURL )
+QString Kita::threadToDat( const QString& threadURL )
{
- QRegExp regexp( "http://([^/]*)/test/read\\.cgi/([^/]*)/([^/]*)/?" );
- if( regexp.search( threadURL ) == -1 ) {
- // no match
- return "";
- }
- QString url = QString( "http://%1/%2/dat/%3.dat" )
- .arg( regexp.cap(1) )
- .arg( regexp.cap(2) )
- .arg( regexp.cap(3) );
- return url;
+ QRegExp regexp( "http://([^/]*)/test/read\\.cgi/([^/]*)/([^/]*)/?" );
+ if ( regexp.search( threadURL ) == -1 ) {
+ // no match
+ return "";
+ }
+ QString url = QString( "http://%1/%2/dat/%3.dat" )
+ .arg( regexp.cap( 1 ) )
+ .arg( regexp.cap( 2 ) )
+ .arg( regexp.cap( 3 ) );
+ return url;
}
-QString boardToSubject( const QString& boardURL )
+QString Kita::boardToSubject( const QString& boardURL )
{
- KURL url( boardURL );
- url.addPath( "subject.txt" );
- return url.url();
+ KURL url( boardURL );
+ url.addPath( "subject.txt" );
+ return url.url();
}
-QString subjectToBoard( const QString& subjectURL )
+QString Kita::subjectToBoard( const QString& subjectURL )
{
- return KURL( subjectURL, "." ).url();
+ return KURL( subjectURL, "." ).url();
}
-QString datToCache( const QString& datURL )
+QString Kita::datToCache( const QString& datURL )
{
- QRegExp regexp( "http://([^/]*)/([^/]*)/dat/(.*)" );
- if( regexp.search( datURL ) == -1 ) {
- return "";
- }
- return QString( "%1/%2/%3" ).arg( regexp.cap(1) )
- .arg( regexp.cap(2) )
- .arg( regexp.cap(3) );
+ QRegExp regexp( "http://([^/]*)/([^/]*)/dat/(.*)" );
+ if ( regexp.search( datURL ) == -1 ) {
+ return "";
+ }
+ return QString( "%1/%2/%3" ).arg( regexp.cap( 1 ) )
+ .arg( regexp.cap( 2 ) )
+ .arg( regexp.cap( 3 ) );
}
-
-};
void URLConvertTest::setUp()
{
m_datURL = "http://pc.2ch.net/linux/dat/1022744633.dat";
+ m_datURL_k2ch = "k2ch://pc.2ch.net/linux/dat/1022744633.dat";
m_threadURL = "http://pc.2ch.net/test/read.cgi/linux/1022744633/";
+ m_threadURL_k2ch = "k2ch://pc.2ch.net/test/read.cgi/linux/1022744633/";
m_threadURL2 = "http://pc.2ch.net/test/read.cgi/linux/1022744633";
m_subjectURL = "http://pc.2ch.net/linux/subject.txt";
m_boardURL = "http://pc.2ch.net/linux/";
void URLConvertTest::testDatToThread()
{
CPPUNIT_ASSERT_EQUAL( m_threadURL, Kita::datToThread( m_datURL ) );
+ CPPUNIT_ASSERT_EQUAL( m_threadURL_k2ch, Kita::datToThread( m_datURL_k2ch ) );
}
void URLConvertTest::testThreadToDat()
void URLConvertTest::testBoardToSubject()
{
CPPUNIT_ASSERT_EQUAL( m_subjectURL, Kita::boardToSubject( m_boardURL ) );
- CPPUNIT_ASSERT_EQUAL( m_subjectURL, Kita::boardToSubject( m_boardURL ) );
}
void URLConvertTest::testSubjectToBoard()