📄 kurl.cpp
字号:
if (isRelativeURL(m_strRef_encoded)) return false; return true;}// BCI: Should be removed, and the other one should have '= 0' for both args.QString KURL::url( int _trailing ) const{ return url( _trailing, 0 );}QString KURL::url( int _trailing, int encoding_hint ) const{ if( m_bIsMalformed ) { // Return the whole url even when the url is // malformed. Under such conditions the url // is stored in m_strProtocol. return m_strProtocol; } QString u = m_strProtocol.copy(); if ( hasHost() ) { u += "://"; if ( hasUser() ) { u += encode(m_strUser, true, encoding_hint); if ( hasPass() ) { u += ":"; u += encode(m_strPass, true, encoding_hint); } u += "@"; } u += encode(m_strHost, true, encoding_hint); if ( m_iPort != 0 ) { QString buffer; buffer.sprintf( ":%u", m_iPort ); u += buffer; } } else u += ":"; u += encodedPathAndQuery( _trailing, false, encoding_hint ); if ( hasRef() ) { u += "#"; u += m_strRef_encoded; } return u;}QString KURL::prettyURL( int _trailing ) const{ if( m_bIsMalformed ) { // Return the whole url even when the url is // malformed. Under such conditions the url // is stored in m_strProtocol. return m_strProtocol; } QString u = m_strProtocol.copy(); if ( hasHost() ) { u += "://"; if ( hasUser() ) { u += lazy_encode(m_strUser); // Don't show password! u += "@"; } u += lazy_encode(m_strHost); if ( m_iPort != 0 ) { QString buffer; buffer.sprintf( ":%u", m_iPort ); u += buffer; } } else { u += ":"; } u += trailingSlash( _trailing, lazy_encode( m_strPath ) ); u += m_strQuery_encoded; if ( hasRef() ) { u += "#"; u += m_strRef_encoded; } return u;}KURL::List KURL::split( const KURL& _url ){ QString ref; KURL::List lst; KURL url = _url; while(true) { KURL u = url; u.m_strRef_encoded = QString::null; lst.append(u); if (url.hasSubURL()) { url = KURL(url.m_strRef_encoded); } else { ref = url.m_strRef_encoded; break; } } // Set HTML ref in all URLs. KURL::List::Iterator it; for( it = lst.begin() ; it != lst.end(); ++it ) { (*it).m_strRef_encoded = ref; } return lst;}KURL::List KURL::split( const QString& _url ){ return split(KURL(_url));}KURL KURL::join( const KURL::List & lst ){ if (lst.isEmpty()) return KURL(); KURL tmp; KURL::List::ConstIterator first = lst.fromLast(); for( KURL::List::ConstIterator it = first; it != lst.end(); --it ) { KURL u(*it); if (it != first) { u.m_strRef_encoded = tmp.url(); } tmp = u; } return tmp;}QString KURL::fileName( bool _strip_trailing_slash ) const{ QString fname; int len = m_strPath.length(); if ( len == 0 ) return fname; if ( _strip_trailing_slash ) { while ( len >= 1 && m_strPath[ len - 1 ] == '/' ) len--; } else if ( m_strPath[ len - 1 ] == '/' ) return fname; // Does the path only consist of '/' characters ? if ( len == 1 && m_strPath[ 1 ] == '/' ) return fname; int i = m_strPath.findRev( '/', len - 1 ); // If ( i == -1 ) => The first character is not a '/' ??? // This looks like an error to me. if ( i == -1 ) return fname; fname = m_strPath.mid( i + 1, len - i - 1 ); // TO CHECK // fname.assign( m_strPath, i + 1, len - i - 1 ); return fname;}void KURL::addPath( const QString& _txt ){ m_strPath_encoded = QString::null; if ( _txt.isEmpty() ) return; int i = 0; int len = m_strPath.length(); // NB: avoid three '/' when building a new path from nothing if ( len == 0 ) { while( _txt[i] == '/' ) ++i; } // Add the trailing '/' if it is missing else if ( _txt[0] != '/' && ( len == 0 || m_strPath[ len - 1 ] != '/' ) ) m_strPath += "/"; // No double '/' characters i = 0; if ( len != 0 && m_strPath[ len - 1 ] == '/' ) { while( _txt[i] == '/' ) ++i; } m_strPath += _txt.mid( i );}QString KURL::directory( bool _strip_trailing_slash_from_result, bool _ignore_trailing_slash_in_path ) const{ QString result; if ( _ignore_trailing_slash_in_path ) result = path( -1 ); else result = m_strPath; if ( result.isEmpty() || result == "/" ) return result; int i = result.findRev( "/" ); if ( i == -1 ) return result; if ( i == 0 ) { result = "/"; return result; } if ( _strip_trailing_slash_from_result ) result = m_strPath.left( i ); else result = m_strPath.left( i + 1 ); return result;}// implemented by David, faure@kde.org// Modified by Torben, weis@kde.orgbool KURL::cd( const QString& _dir ){ if ( _dir.isEmpty() || m_bIsMalformed ) return false; if (hasSubURL()) { KURL::List lst = split( *this ); KURL &u = lst.last(); u.cd(_dir); *this = join( lst ); return true; } // absolute path ? if ( _dir[0] == '/' ) { m_strPath_encoded = QString::null; m_strPath = _dir; setHTMLRef( QString::null ); return true; } // Users home directory on the local disk ? if ( ( _dir[0] == '~' ) && ( m_strProtocol == "file" )) { m_strPath_encoded = QString::null; m_strPath = QDir::homeDirPath().copy(); m_strPath += "/"; m_strPath += _dir.right(m_strPath.length() - 1); setHTMLRef( QString::null ); return true; } // relative path // we always work on the past of the first url. // Sub URLs are not touched. // append '/' if necessary QString p = path(1); p += _dir; p = QDir::cleanDirPath( p ); setPath( p ); setHTMLRef( QString::null ); return true;}KURL KURL::upURL( ) const{ if (!hasSubURL()) { KURL u(*this); u.cd("../"); return u; } // We have a subURL. KURL::List lst = split( *this ); if (lst.isEmpty()) return KURL(); // Huh? while (true) { KURL &u = lst.last(); QString old = u.path(); u.cd("../"); if (u.path() != old) break; // Finshed. if (lst.count() == 1) break; // Finished. lst.remove(lst.fromLast()); } return join( lst );}QString KURL::htmlRef() const{ if ( !hasSubURL() ) { return decode( ref() ); } List lst = split( *this ); return decode( (*lst.begin()).ref() );}void KURL::setHTMLRef( const QString& _ref ){ if ( !hasSubURL() ) { m_strRef_encoded = encode( _ref, true, 0 /*?*/); return; } List lst = split( *this ); (*lst.begin()).setRef( encode( _ref, true, 0 /*?*/) ); *this = join( lst );}bool KURL::hasHTMLRef() const{ if ( !hasSubURL() ) { return hasRef(); } List lst = split( *this ); return (*lst.begin()).hasRef();}voidKURL::setProtocol( const QString& _txt ){ m_strProtocol = _txt; m_bIsMalformed = false;}voidKURL::setUser( const QString& _txt ){ m_strUser = _txt;}voidKURL::setPass( const QString& _txt ){ m_strPass = _txt;}voidKURL::setHost( const QString& _txt ){ m_strHost = _txt;}voidKURL::setPort( unsigned short int _p ){ m_iPort = _p;}void KURL::setPath( const QString & path ){ if (isEmpty()) m_bIsMalformed = false; if (m_strProtocol.isEmpty()) m_strProtocol = "file"; m_strPath = path; m_strPath_encoded = QString::null;}void KURL::setQuery( const QString &_txt, int ){ if (_txt.length() && (_txt[0] !='?')) m_strQuery_encoded = "?" + _txt; else m_strQuery_encoded = _txt;}QString KURL::decode_string(const QString &str, int encoding_hint){ return decode(str, 0, encoding_hint);}QString KURL::encode_string(const QString &str, int encoding_hint){ return encode(str, false, encoding_hint);}QString KURL::encode_string_no_slash(const QString &str, int encoding_hint){ return encode(str, true, encoding_hint);}bool urlcmp( const QString& _url1, const QString& _url2 ){ // Both empty ? if ( _url1.isEmpty() && _url2.isEmpty() ) return true; // Only one empty ? if ( _url1.isEmpty() || _url2.isEmpty() ) return false; KURL::List list1 = KURL::split( _url1 ); KURL::List list2 = KURL::split( _url2 ); // Malformed ? if ( list1.isEmpty() || list2.isEmpty() ) return false; return ( list1 == list2 );}bool urlcmp( const QString& _url1, const QString& _url2, bool _ignore_trailing, bool _ignore_ref ){ // Both empty ? if ( _url1.isEmpty() && _url2.isEmpty() ) return true; // Only one empty ? if ( _url1.isEmpty() || _url2.isEmpty() ) return false; KURL::List list1 = KURL::split( _url1 ); KURL::List list2 = KURL::split( _url2 ); // Malformed ? if ( list1.isEmpty() || list2.isEmpty() ) return false; unsigned int size = list1.count(); if ( list2.count() != size ) return false; if ( _ignore_ref ) { (*list1.begin()).setRef(QString::null); (*list2.begin()).setRef(QString::null); } KURL::List::Iterator it1 = list1.begin(); KURL::List::Iterator it2 = list2.begin(); for( ; it1 != list1.end() ; ++it1, ++it2 ) if ( !(*it1).cmp( *it2, _ignore_trailing ) ) return false; return true;}//to get an unsigned char URL for requesting image from net void uncharURL(DOM::DOMString& url, DOM::DOMString& baseUrl, unsigned char u[]){// unsigned char u[256]; char surl[256],sbase[256]; strcpy (surl,url.string()); strcpy (sbase,baseUrl.string()); KURL kubase((const char*)sbase,0); KURL curl ( kubase, url.string()); if(kubase.isLocalFile()) strncpy((char *)u,(char*)curl.url().latin1()+5,255); else strncpy((char *)u,(char*)curl.url().latin1(),255);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -