40 #include <QtCore/QDir>
41 #include <QtCore/QMutableStringListIterator>
42 #include <QtCore/QRegExp>
43 #include <QtCore/QMimeData>
44 #include <QtCore/QTextCodec>
47 static int kurlDebugArea() {
static int s_area =
KDebug::registerArea(
"kdecore (KUrl)");
return s_area; }
55 if (QFileInfo(_path).isRelative())
60 int len = path.length();
65 if (path.indexOf(encodedDot, 0, Qt::CaseInsensitive) != -1)
68 path.replace(encodedDot,
QString(QLatin1Char(
'.')));
69 path.replace(encodedDOT,
QString(QLatin1Char(
'.')));
74 const bool slash = (len && path[len-1] == QLatin1Char(
'/')) ||
75 (len > 1 && path[len-2] == QLatin1Char(
'/') && path[len-1] == QLatin1Char(
'.'));
84 int cdUp, orig_pos, pos;
88 while ( pos && (pos = path.lastIndexOf(QLatin1Char(
'/'),--pos)) != -1 )
90 len = orig_pos - pos - 1;
91 if ( len == 2 && path[pos+1] == QLatin1Char(
'.') && path[pos+2] == QLatin1Char(
'.') )
97 if ( (len || !cleanDirSeparator) &&
98 (len != 1 || path[pos+1] != QLatin1Char(
'.') ) )
101 result.prepend(path.mid(pos, len+1));
109 #ifdef Q_WS_WIN // prepend drive letter if exists (js)
110 if (orig_pos >= 2 && path[0].isLetter() && path[1] == QLatin1Char(
':') ) {
111 result.prepend(
QString(path[0]) + QLatin1Char(
':') );
115 if ( result.isEmpty() )
116 result = QLatin1Char(
'/');
117 else if ( slash && result[result.length()-1] != QLatin1Char(
'/') )
118 result.append(QLatin1Char(
'/'));
126 #define IS_DRIVE_OR_DOUBLESLASH(isletter, char1, char2, colon, slash) \
127 ((isletter && char2 == colon) || (char1 == slash && char2 == slash))
135 const int len = str.length();
136 if (str[0]==QLatin1Char(
'f')) {
137 if ( len > 10 && str.startsWith( QLatin1String(
"file:///" ) )
139 return QUrl::fromPercentEncoding( str.toLatin1() ).mid(8);
140 else if ( len > 9 && str.startsWith( QLatin1String(
"file://" ) )
142 return QUrl::fromPercentEncoding( str.toLatin1() ).mid(7);
143 else if ( len > 8 && str.startsWith( QLatin1String(
"file:/" ) )
145 return QUrl::fromPercentEncoding( str.toLatin1() ).mid(6);
150 if ( len > 2 && str[0] == QLatin1Char(
'/')
154 else if ( len >= 2 &&
IS_DRIVE_OR_DOUBLESLASH(str[0].isLetter(), str[0], str[1], QLatin1Char(
':'), QLatin1Char(
'/')) )
162 int len = _url.length();
163 if (!len)
return true;
164 const QChar *str = _url.unicode();
167 if (!
isalpha(str[0].toLatin1()))
170 for(
int i = 1; i < len; i++)
172 char c = str[i].toLatin1();
196 foreach(
const QUrl&
url, list) {
203 for (QStringList::ConstIterator it = list.begin();
219 for(KUrl::List::ConstIterator it = constBegin();
220 it != constEnd(); ++it) {
221 lst.append(it->url(trailing));
229 KUrl::List::ConstIterator uit = urls.constBegin();
230 const KUrl::List::ConstIterator uEnd = urls.constEnd();
231 for (; uit != uEnd ; ++uit) {
234 urlStringList.append((*uit).toMimeDataString().toLatin1());
238 for (
int i = 0, n = urlStringList.count(); i < n; ++i) {
239 uriListData += urlStringList.at(i);
241 uriListData +=
"\r\n";
252 mimeData->setData(QString::fromLatin1(
"text/uri-list"),
uriListData(*
this));
257 KUrl::List::ConstIterator uit = constBegin();
258 const KUrl::List::ConstIterator uEnd = constEnd();
259 for ( ; uit != uEnd ; ++uit ) {
260 QString prettyURL = (*uit).prettyUrl();
261 if ( (*uit).protocol() == QLatin1String(
"mailto") ) {
262 prettyURL = (*uit).path();
264 prettyURLsList.append( prettyURL );
267 QByteArray plainTextData = prettyURLsList.join(
QString(QLatin1Char(
'\n'))).toLocal8Bit();
269 plainTextData.append(
"\n" );
270 mimeData->setData( QString::fromLatin1(
"text/plain"), plainTextData );
273 if ( !metaData.isEmpty() )
275 QByteArray metaDataData;
276 for( KUrl::MetaDataMap::const_iterator it = metaData.begin(); it != metaData.end(); ++it )
278 metaDataData += it.key().toUtf8();
279 metaDataData +=
"$@@$";
280 metaDataData += it.value().toUtf8();
281 metaDataData +=
"$@@$";
283 mimeData->setData( QString::fromLatin1(
"application/x-kio-metadata"), metaDataData );
301 return mimeData->hasFormat(QString::fromLatin1(
"text/uri-list")) ||
318 const char* secondMimeType =
"text/uri-list";
319 if (decodeOptions == PreferLocalUrls) {
320 qSwap(firstMimeType, secondMimeType);
322 QByteArray payload = mimeData->data(QString::fromLatin1(firstMimeType));
323 if (payload.isEmpty())
324 payload = mimeData->data(QString::fromLatin1(secondMimeType));
325 if ( !payload.isEmpty() ) {
327 const char* d = payload.constData();
328 while ( c < payload.size() && d[c] ) {
331 while (c < payload.size() && d[c] && d[c]!=
'\r'
334 QByteArray s( d+f, c-f );
338 while ( c < payload.size() && d[c] &&
339 ( d[c] ==
'\n' || d[c] ==
'\r' ) )
345 const QByteArray metaDataPayload = mimeData->data(QLatin1String(
"application/x-kio-metadata"));
346 if ( !metaDataPayload.isEmpty() )
348 QString str = QString::fromUtf8( metaDataPayload );
349 Q_ASSERT(str.endsWith(QLatin1String(
"$@@$")));
350 str.truncate( str.length() - 4 );
351 const QStringList lst = str.split(QLatin1String(
"$@@$"));
352 QStringList::ConstIterator it = lst.begin();
353 bool readingKey =
true;
355 for ( ; it != lst.end(); ++it ) {
359 metaData->insert( key, *it );
360 readingKey = !readingKey;
362 Q_ASSERT( readingKey );
371 return fromMimeData(mimeData, PreferKdeUrls, metaData);
376 return qVariantFromValue(*
this);
382 foreach(
const KUrl&
url, *
this) {
403 if ( !str.isEmpty() ) {
406 kDebug(kurlDebugArea()) <<
"KUrl::KUrl ( const QString &str = " << str.toLatin1().data() <<
" )";
411 if (!str.startsWith(QLatin1String(
"file://")))
413 if ( !pathToSet.isEmpty() ) {
416 int index = pathToSet.lastIndexOf(QLatin1Char(
'?'));
420 setPath( pathToSet.left( index ) );
421 _setQuery( pathToSet.mid( index + 1 ) );
426 if ( str[0] == QLatin1Char(
'/') || str[0] == QLatin1Char(
'~') )
429 _setEncodedUrl( str.toUtf8() );
439 #define IS_LETTER(c) \
440 ((c >= QLatin1Char('A') && c <= QLatin1Char('Z')) || (c >= QLatin1Char('a') && c <= QLatin1Char('z')))
443 #define IS_SLASH_AND_DRIVE_OR_DOUBLESLASH_0 \
444 ( QLatin1Char(str[0]) == QLatin1Char('/') && IS_DRIVE_OR_DOUBLESLASH(IS_LETTER(QLatin1Char(str[1])), QLatin1Char(str[1]), QLatin1Char(str[2]), QLatin1Char(':'), QLatin1Char('/')) )
447 #define IS_DRIVE_OR_DOUBLESLASH_0 \
448 ( IS_DRIVE_OR_DOUBLESLASH(IS_LETTER(QLatin1Char(str[0])), QLatin1Char(str[0]), QLatin1Char(str[1]), QLatin1Char(':'), QLatin1Char('/')) )
450 #if defined(DEBUG_KURL)
451 kDebug(kurlDebugArea()) <<
"KUrl::KUrl " <<
" " << str;
453 if ( str && str[0] && str[1] && str[2] ) {
455 setPath( QString::fromUtf8( str+1 ) );
457 setPath( QString::fromUtf8( str ) );
460 if ( str && str[0] ) {
461 if ( str[0] ==
'/' || str[0] ==
'~' )
462 setPath( QString::fromUtf8( str ) );
464 _setEncodedUrl( str );
471 if ( !str.isEmpty() ) {
474 kDebug(kurlDebugArea()) <<
"KUrl::KUrl " <<
" " << str.data();
477 setPath( QString::fromUtf8( str.mid( 1 ) ) );
479 setPath( QString::fromUtf8( str ) );
481 if ( str[0] ==
'/' || str[0] ==
'~' )
482 setPath( QString::fromUtf8( str ) );
485 _setEncodedUrl( str );
492 #if defined(Q_WS_WIN) && defined(DEBUG_KURL)
493 kDebug(kurlDebugArea()) <<
"KUrl::KUrl(KUrl) " <<
" path " << _u.
path() <<
" toLocalFile " << _u.
toLocalFile();
500 #if defined(Q_WS_WIN) && defined(DEBUG_KURL)
501 kDebug(kurlDebugArea()) <<
"KUrl::KUrl(Qurl) " <<
" path " << u.path() <<
" toLocalFile " << u.toLocalFile();
508 #if defined(Q_WS_WIN) && defined(DEBUG_KURL)
509 kDebug(kurlDebugArea()) <<
"KUrl::KUrl(KUrl,QString rel_url) " <<
" path " << _u.
path() <<
" toLocalFile " << _u.
toLocalFile();
515 KUrl u(lst.last(), _rel_url);
516 lst.erase( --lst.end() );
527 const int len = _u.scheme().length();
528 if ( !_u.host().isEmpty() && !rUrl.isEmpty() &&
529 rUrl.indexOf( _u.scheme(), 0, Qt::CaseInsensitive ) == 0 &&
530 rUrl[len] == QLatin1Char(
':') && (rUrl[len+1] != QLatin1Char(
'/') ||
531 (rUrl[len+1] == QLatin1Char(
'/') && rUrl[len+2] != QLatin1Char(
'/'))) )
533 rUrl.remove( 0, rUrl.indexOf( QLatin1Char(
':') ) + 1 );
537 if ( rUrl.isEmpty() )
541 else if ( rUrl[0] == QLatin1Char(
'#') )
544 QByteArray strRef_encoded = rUrl.mid(1).toLatin1();
545 if ( strRef_encoded.isNull() )
546 setFragment(QString::fromLatin1(
""));
548 setFragment(QUrl::fromPercentEncoding(strRef_encoded));
554 setEncodedQuery( QByteArray() );
556 if ( rUrl[0] == QLatin1Char(
'/') )
558 if ((rUrl.length() > 1) && (rUrl[1] == QLatin1Char(
'/')))
568 else if ( rUrl[0] != QLatin1Char(
'?') )
570 const int pos = strPath.lastIndexOf( QLatin1Char(
'/') );
572 strPath.truncate(pos);
573 strPath += QLatin1Char(
'/');
577 if ( strPath.isEmpty() )
578 strPath = QLatin1Char(
'/');
589 const KUrl tmp( rUrl );
593 if (!_u.userInfo().isEmpty() && userInfo().isEmpty()
594 && (_u.host() == host()) && (_u.scheme() == scheme()))
596 setUserInfo( _u.userInfo() );
604 QUrl::operator=( _u );
616 return ( *
this == u );
621 return qVariantFromValue(*
this);
624 #ifndef KDE_NO_DEPRECATED
633 if ( !isValid() || !_u.isValid() )
642 if (path1 == QLatin1String(
"/"))
644 if (path2 == QLatin1String(
"/"))
651 if ( !bLocal1 && bLocal2 || bLocal1 && !bLocal2 )
654 if ( bLocal1 && bLocal2 && 0 != QString::compare( path1, path2, Qt::CaseInsensitive ) )
657 if ( path1 != path2 )
660 if ( scheme() == _u.scheme() &&
661 authority() == _u.authority() &&
662 encodedQuery() == _u.encodedQuery() &&
669 return ( *
this == _u );
674 return scheme().toLower();
694 return !userName().isEmpty();
709 return !password().isEmpty();
714 return !host().isEmpty();
719 return !
path().isEmpty();
733 while( i < _txt.length() && _txt[i] == QLatin1Char(
'/') )
735 QString tmp = i ? _txt.mid( i ) : _txt;
738 if ( path.isEmpty() )
740 path =
isLocalFile() ? QDir::rootPath() : QLatin1String(
"/");
742 path = QDir::rootPath();
746 int lastSlash = path.lastIndexOf( QLatin1Char(
'/') );
747 if ( lastSlash == -1)
749 else if ( !path.endsWith( QLatin1Char(
'/') ) )
750 path.truncate( lastSlash+1 );
763 if (
path() != newPath )
779 int len = result.length();
780 if ((len > 0) && (result[ len - 1 ] != QLatin1Char(
'/')))
781 result += QLatin1Char(
'/');
786 if ( result == QLatin1String(
"/") )
788 int len = result.length();
789 while (len > 1 && result[ len - 1 ] == QLatin1Char(
'/'))
793 result.truncate( len );
805 if (!m_strPath_encoded.isEmpty())
807 m_strPath_encoded =
trailingSlash( _trailing, m_strPath_encoded );
811 if (
path() != newPath )
824 encodedPath = QString::fromLatin1(QUrl::toPercentEncoding(encodedPath,
"!$&'()*+,;=:@/"));
826 encodedPath =
trailingSlash(trailing, QString::fromLatin1(QUrl::encodedPath()));
829 encodedPath =
trailingSlash(trailing, QString::fromLatin1(QUrl::encodedPath()));
833 encodedPath.append(QLatin1Char(
'/'));
837 return encodedPath + QLatin1Char(
'?') + QString::fromLatin1(encodedQuery());
844 void KUrl::setEncodedPath(
const QString& _txt,
int encoding_hint )
846 m_strPath_encoded = _txt;
848 decode( m_strPath_encoded, m_strPath, m_strPath_encoded, encoding_hint );
850 if (m_strProtocol ==
"file")
851 m_strPath_encoded.clear();
853 if ( m_iUriMode == Auto )
860 const int pos = _txt.indexOf(QLatin1Char(
'?'));
863 setPath( QUrl::fromPercentEncoding( _txt.toLatin1() ) );
864 setEncodedQuery( QByteArray() );
868 setPath( QUrl::fromPercentEncoding(_txt.toLatin1().left(pos)) );
869 _setQuery( _txt.right( _txt.length() - pos - 1 ) );
877 kWarning() << (
isLocalFile() ?
"converted to local file - the related call should be converted to toLocalFile()" :
"") << QUrl::path();
888 KUrl urlWithoutHost(*
this);
889 urlWithoutHost.setHost(
QString());
893 #warning FIXME: Remove #ifdef below once upstream bug, QTBUG-20322, is fixed. Also see BR# 194746.
907 if ( url.scheme().compare(QLatin1String(
"file"), Qt::CaseInsensitive) != 0 ||
hasSubUrl( url ) )
910 if (url.host().isEmpty() || (url.host() == QLatin1String(
"localhost")))
913 char hostname[ 256 ];
914 hostname[ 0 ] =
'\0';
915 if (!gethostname( hostname, 255 ))
916 hostname[
sizeof(hostname)-1] =
'\0';
918 for(
char *p = hostname; *p; p++)
921 return (url.host() == QString::fromLatin1( hostname ));
936 if (!q.isEmpty() && q[0] == QLatin1Char(
'?'))
939 QStringList args = q.split(QLatin1Char(
'&'), QString::SkipEmptyParts);
940 for(QStringList::Iterator it = args.begin();
943 QString s = QUrl::fromPercentEncoding( (*it).toLatin1() );
944 if (s.startsWith(QLatin1String(
"charset=")))
949 if (!encoding.isEmpty())
950 args.append(QLatin1String(
"charset=") + QString::fromLatin1(QUrl::toPercentEncoding(encoding)));
955 _setQuery(args.join(
QString(QLatin1Char(
'&'))));
968 if (q[0] == QLatin1Char(
'?'))
971 const QStringList args = q.split(QLatin1Char(
'&'), QString::SkipEmptyParts);
972 for(QStringList::ConstIterator it = args.begin();
976 QString s = QUrl::fromPercentEncoding((*it).toLatin1());
977 if (s.startsWith(QLatin1String(
"charset=")))
987 const QString scheme = url.scheme();
988 if ( scheme.isEmpty() )
993 switch (
ref.at(0).unicode() ) {
995 if (
ref.startsWith(QLatin1String(
"gzip:")) )
999 if (
ref.startsWith(QLatin1String(
"bzip:")) ||
ref.startsWith(QLatin1String(
"bzip2:")) )
1003 if (
ref.startsWith(QLatin1String(
"lzma:")) )
1007 if (
ref.startsWith(QLatin1String(
"xz:")) )
1011 if (
ref.startsWith(QLatin1String(
"tar:")) )
1015 if (
ref.startsWith(QLatin1String(
"ar:")) )
1019 if (
ref.startsWith(QLatin1String(
"zip:")) )
1025 if ( scheme == QLatin1String(
"error") )
1037 if (QString::compare(scheme(), QLatin1String(
"mailto"), Qt::CaseInsensitive) == 0) {
1045 QUrl newUrl( *
this );
1046 newUrl.setPath(
path() + QLatin1Char(
'/') );
1047 return QString::fromLatin1(newUrl.toEncoded());
1051 if (cleanedPath == QLatin1String(
"/")) {
1052 if (
path() != QLatin1String(
"/")) {
1053 QUrl fixedUrl = *
this;
1054 fixedUrl.setPath(cleanedPath);
1055 return QLatin1String(fixedUrl.toEncoded(
None));
1057 return QLatin1String(toEncoded(
None));
1066 result.reserve(input.length());
1067 for (
int i = 0; i < input.length(); ++i) {
1068 const QChar c = input.at(i);
1069 register ushort u = c.unicode();
1071 || (!forFragment && u ==
'?')
1072 || u ==
'#' || u ==
'%'
1073 || (u ==
' ' && (i+1 == input.length() || input.at(i+1).unicode() ==
' '))) {
1074 static const char hexdigits[] =
"0123456789ABCDEF";
1075 result += QLatin1Char(
'%');
1076 result += QLatin1Char(hexdigits[(u & 0xf0) >> 4]);
1077 result += QLatin1Char(hexdigits[u & 0xf]);
1098 if (!result.isEmpty())
1100 if (!authority().isEmpty() || result == QLatin1String(
"file") ||
path().isEmpty())
1101 result += QLatin1String(
"://");
1103 result += QLatin1Char(
':');
1107 if (!tmp.isEmpty()) {
1108 result += QString::fromLatin1(QUrl::toPercentEncoding(tmp));
1109 result += QLatin1Char(
'@');
1114 if (tmp.contains(QLatin1Char(
':')))
1115 result += QLatin1Char(
'[') + tmp + QLatin1Char(
']');
1120 result += QLatin1Char(
':');
1121 result += QString::number(port());
1127 tmp.prepend(QLatin1Char(
'/'));
1133 result += QLatin1Char(
'/');
1134 else if (trailing ==
RemoveTrailingSlash && tmp.length() > 1 && tmp.endsWith(QLatin1Char(
'/')))
1138 result += QLatin1Char(
'?');
1139 result += QString::fromLatin1(encodedQuery());
1142 if (hasFragment()) {
1143 result += QLatin1Char(
'#');
1154 if (_flags & StripFileProtocol && u.startsWith(
"file://")) {
1157 return QDir::convertSeparators(u);
1171 if (
isLocalFile() && fragment().isNull() && encodedQuery().isNull() ) {
1190 if( !s.startsWith( QLatin1String (
"file://" ) ))
1193 if ( gethostname( hostname, 255 ) == 0 )
1195 hostname[256] =
'\0';
1196 return QString(
"file://" ) + hostname + s.mid( 5 );
1203 KUrl safeUrl(*
this);
1204 safeUrl.setPassword(
QString());
1205 return safeUrl.
url();
1212 if ( str.startsWith(
"file:" ) )
1232 url =
KUrl(url.fragment());
1236 ref = url.fragment();
1237 hasRef = url.hasFragment();
1245 KUrl::List::Iterator it;
1246 for( it = lst.begin() ; it != lst.end(); ++it )
1248 (*it).setFragment( ref );
1262 if (lst.isEmpty())
return KUrl();
1266 QListIterator<KUrl> it(lst);
1268 while (it.hasPrevious())
1270 KUrl u(it.previous());
1272 u.setEncodedFragment(tmp.
url().toLatin1() );
1284 Q_ASSERT( options != 0 );
1288 return list.last().fileName(options);
1292 int len = path.length();
1298 while ( len >= 1 && path[ len - 1 ] == QLatin1Char(
'/') )
1301 else if ( path[ len - 1 ] == QLatin1Char(
'/') )
1305 if ( len == 1 && path[ 0 ] == QLatin1Char(
'/') )
1311 if (!m_strPath_encoded.isEmpty())
1316 int i = m_strPath_encoded.lastIndexOf( QLatin1Char(
'/'), len - 1 );
1317 QString fileName_encoded = m_strPath_encoded.mid(i+1);
1318 n += fileName_encoded.count(
"%2f", Qt::CaseInsensitive);
1323 i = path.lastIndexOf( QLatin1Char(
'/'), i - 1 );
1325 while (--n && (i > 0));
1330 if ( len == (
int)path.length() )
1334 fname = path.left( len );
1338 fname = path.mid( i + 1, len - i - 1 );
1348 KUrl &u = lst.last();
1350 *
this =
join( lst );
1356 if ( _txt.isEmpty() )
1361 int len = strPath.length();
1363 if ( _txt[0] != QLatin1Char(
'/') && ( len == 0 || strPath[ len - 1 ] != QLatin1Char(
'/') ) )
1364 strPath += QLatin1Char(
'/');
1368 const int _txtlen = _txt.length();
1369 if ( strPath.endsWith( QLatin1Char(
'/') ) )
1371 while ( ( i < _txtlen ) && ( _txt[i] == QLatin1Char(
'/') ) )
1375 setPath( strPath + _txt.mid( i ) );
1381 Q_ASSERT( options != 0 );
1386 if ( result.isEmpty() || result == QLatin1String (
"/" ) )
1389 int i = result.lastIndexOf( QLatin1Char(
'/') );
1397 return QString(QLatin1Char(
'/'));
1401 if ( i == 2 && result[1] == QLatin1Char(
':') )
1403 return result.left(3);
1408 result = result.left( i + 1 );
1410 result = result.left( i );
1421 if ( _dir.isEmpty() || !isValid() )
1427 KUrl &u = lst.last();
1429 *
this =
join( lst );
1435 if ( !QFileInfo(_dir).isRelative() )
1437 if ( _dir[0] == QLatin1Char(
'/') )
1443 setEncodedQuery( QByteArray() );
1448 if (_dir[0] == QLatin1Char(
'~') && scheme() == QLatin1String (
"file"))
1451 QString strPath = QDir::homePath();
1452 strPath += QLatin1Char(
'/');
1453 strPath += _dir.right( strPath.length() - 1 );
1456 setEncodedQuery( QByteArray() );
1471 setEncodedQuery( QByteArray() );
1478 if (!isValid() || isRelative())
1481 if (!encodedQuery().isEmpty())
1484 u.setEncodedQuery(QByteArray());
1491 u.
cd(QLatin1String(
"../"));
1501 KUrl &u = lst.last();
1503 u.
cd(QLatin1String(
"../"));
1504 if (u.
path() != old)
1506 if (lst.count() == 1)
1521 return (*lst.begin()).fragment();
1532 return (*lst.begin()).
ref();
1539 setFragment( _ref );
1545 (*lst.begin()).setFragment( _ref );
1547 *
this =
join( lst );
1558 return (*lst.begin()).
hasRef();
1563 if ( dir.endsWith(QLatin1Char(
'/')))
1566 setPath(dir + QLatin1Char(
'/'));
1571 if (!_txt.isEmpty() && _txt[0] == QLatin1Char(
'?'))
1572 _setQuery( _txt.length() > 1 ? _txt.mid(1) : QString::fromLatin1(
"") );
1577 void KUrl::_setQuery(
const QString& query )
1579 if ( query.isNull() ) {
1580 setEncodedQuery( QByteArray() );
1581 }
else if ( query.isEmpty() ) {
1582 setEncodedQuery(
"");
1584 setEncodedQuery( query.toLatin1() );
1593 return QString(QLatin1Char(
'?')) + QString::fromLatin1(encodedQuery());
1596 void KUrl::_setEncodedUrl(
const QByteArray& url)
1598 setEncodedUrl(url, QUrl::TolerantMode);
1600 setUrl(QString::fromUtf8(url), QUrl::TolerantMode);
1603 #ifndef KDE_NO_DEPRECATED
1606 return QUrl( _url1, QUrl::TolerantMode ) ==
QUrl( _url2, QUrl::TolerantMode );
1609 if ( _url1.isEmpty() && _url2.isEmpty() )
1612 if ( _url1.isEmpty() || _url2.isEmpty() )
1619 if ( list1.isEmpty() || list2.isEmpty() )
1622 return ( list1 == list2 );
1627 #ifndef KDE_NO_DEPRECATED
1631 if (_url1.isEmpty() && _url2.isEmpty())
1634 if (_url1.isEmpty() || _url2.isEmpty())
1639 return u1.
equals(u2, _options);
1641 #if 0 // kde3 code that supported nested urls
1647 if ( list1.isEmpty() || list2.isEmpty() )
1650 int size = list1.count();
1651 if ( list2.count() != size )
1656 (*list1.begin()).setRef(
QString());
1657 (*list2.begin()).setRef(
QString());
1660 KUrl::List::Iterator it1 = list1.begin();
1661 KUrl::List::Iterator it2 = list2.begin();
1662 for( ; it1 != list1.end() ; ++it1, ++it2 )
1663 if ( !(*it1).equals( *it2, _ignore_trailing ) )
1671 #ifndef KDE_NO_DEPRECATED
1675 if ( !text.isEmpty() )
1677 if (!QDir::isRelativePath(text) || text[0] == QLatin1Char(
'~'))
1689 QString _base_dir(QDir::cleanPath(base_dir));
1690 QString _path(QDir::cleanPath(path.isEmpty() || QDir::isRelativePath(path) ? _base_dir+QLatin1Char(
'/')+path : path));
1692 if (_base_dir.isEmpty())
1695 if (_base_dir[_base_dir.length()-1] != QLatin1Char(
'/'))
1696 _base_dir.append(QLatin1Char(
'/') );
1698 const QStringList list1 = _base_dir.split(QLatin1Char(
'/'), QString::SkipEmptyParts);
1699 const QStringList list2 = _path.split(QLatin1Char(
'/'), QString::SkipEmptyParts);
1703 int maxLevel = qMin(list1.count(), list2.count());
1704 while((level < maxLevel) && (list1[level] == list2[level])) level++;
1708 for(
int i = level; i < list1.count(); i++)
1709 result.append(QLatin1String(
"../"));
1712 for(
int i = level; i < list2.count(); i++)
1713 result.append(list2[i]).append(QLatin1Char(
'/'));
1715 if ((level < list2.count()) && (path[path.length()-1] != QLatin1Char(
'/')))
1716 result.truncate(result.length()-1);
1718 isParent = (level == list1.count());
1725 bool parent =
false;
1728 result.prepend(QLatin1String(
"./"));
1740 (url.host() != base_url.host()) ||
1741 (url.port() && url.port() != base_url.port()) ||
1754 static const char s_pathExcludeChars[] =
"!$&'()*+,;=:@/";
1755 relURL = QString::fromLatin1(QUrl::toPercentEncoding(
_relativePath(basePath, url.
path(), dummy), s_pathExcludeChars));
1756 relURL += url.
query();
1761 relURL += QLatin1Char(
'#');
1762 relURL += url.
ref();
1765 if ( relURL.isEmpty() )
1766 return QLatin1String(
"./");
1773 #if defined(Q_WS_WIN) && defined(DEBUG_KURL)
1774 kDebug(kurlDebugArea()) <<
"KUrl::setPath " <<
" " << _path.toLatin1().data();
1776 if ( scheme().isEmpty() )
1777 setScheme( QLatin1String(
"file" ) );
1782 const int len = path.length();
1783 if( len == 2 &&
IS_LETTER(path[0]) && path[1] == QLatin1Char(
':') )
1784 path += QLatin1Char(
'/');
1789 if( len > 0 && path[0] != QLatin1Char(
'/') && scheme() == QLatin1String(
"file" ) )
1790 path = QLatin1Char(
'/') +
path;
1792 QUrl::setPath( path );
1795 #if 0 // this would be if we didn't decode '+' into ' '
1800 Q_FOREACH( item, items ) {
1801 result.insert( options &
CaseInsensitiveKeys ? item.first.toLower() : item.first, item.second );
1809 const QString strQueryEncoded = QString::fromLatin1(encodedQuery());
1810 if ( strQueryEncoded.isEmpty() )
1814 const QStringList items = strQueryEncoded.split( QLatin1Char(
'&'), QString::SkipEmptyParts );
1815 for ( QStringList::const_iterator it = items.begin() ; it != items.end() ; ++it ) {
1816 const int equal_pos = (*it).indexOf(QLatin1Char(
'='));
1817 if ( equal_pos > 0 ) {
1818 QString name = (*it).left( equal_pos );
1820 name = name.toLower();
1821 QString value = (*it).mid( equal_pos + 1 );
1822 if ( value.isEmpty() )
1823 result.insert( name, QString::fromLatin1(
"") );
1826 value.replace( QLatin1Char(
'+'), QLatin1Char(
' ') );
1827 result.insert( name, QUrl::fromPercentEncoding( value.toLatin1() ) );
1829 }
else if ( equal_pos < 0 ) {
1832 name = name.toLower();
1833 result.insert( name,
QString() );
1842 const QString strQueryEncoded = QString::fromLatin1(encodedQuery());
1843 const QString item = _item + QLatin1Char(
'=');
1844 if ( strQueryEncoded.length() <= 1 )
1847 const QStringList items = strQueryEncoded.split(
QString(QLatin1Char(
'&')), QString::SkipEmptyParts );
1848 const int _len = item.length();
1849 for ( QStringList::ConstIterator it = items.begin(); it != items.end(); ++it )
1851 if ( (*it).startsWith( item ) )
1853 if ( (*it).length() > _len )
1855 QString str = (*it).mid( _len );
1856 str.replace( QLatin1Char(
'+'), QLatin1Char(
' ') );
1857 return QUrl::fromPercentEncoding( str.toLatin1() );
1860 return QString::fromLatin1(
"");
1869 QString item = _item + QLatin1Char(
'=');
1870 QString value = QString::fromLatin1(QUrl::toPercentEncoding(_value));
1872 QString strQueryEncoded = QString::fromLatin1(encodedQuery());
1873 if (!strQueryEncoded.isEmpty())
1874 strQueryEncoded += QLatin1Char(
'&');
1875 strQueryEncoded += item + value;
1876 setEncodedQuery( strQueryEncoded.toLatin1() );
1889 return hasFragment();
1894 if ( fragment.isEmpty() )
1895 setFragment( fragment );
1897 setFragment( QUrl::fromPercentEncoding( fragment.toLatin1() ) );
1902 if ( !hasFragment() )
1905 return QString::fromLatin1( encodedFragment() );