📄 kurl.cpp
字号:
***/const char* KURL::path() const{ if (path_part.isNull()) return ""; else { KURL *that = const_cast<KURL*>(this); if (that->path_part_decoded.isNull()) { that->path_part_decoded = path_part.copy(); KURL::decodeURL(that->path_part_decoded); } return path_part_decoded.data(); }}/***** This method will return the path of the URL or NULL is there is none.** Any special characters are left as-is.***/const char* KURL::httpPath() const{ if (path_part.isNull()) return ""; else { return path_part.data(); }}/***** This method will return the search part of the URL or NULL** if there is none.***/const char* KURL::searchPart() const{ if (search_part.isNull()) return 0L; else { return search_part.data(); }}/***** This method will return the protocol part of the URL or NULL** if there is none.***/const char* KURL::protocol() const { if (protocol_part.isNull()) return ""; else return protocol_part.data(); }/***** This method will set the specified protocol part.** No checking is done - the protocol must be correct.***/void KURL::setProtocol( const char* newProto) { protocol_part = newProto; }/***** This method will set the specified search part.** No checking is done - the search must be correct.***/void KURL::setSearchPart( const char* _searchPart) { search_part = _searchPart; }/***** This method will return the reference part of the URL or NULL** if there is none.***/const char* KURL::reference() const { if (ref_part.isNull()) return ""; else return ref_part.data(); }/***** This method will return the user part of the URL or NULL** if there is none.***/const char* KURL::user() const{ if (user_part.isNull()) return ""; else return user_part.data(); }/***** This method will return the port number of the URL. If no** port has been specified, '0' is returned.***/unsigned int KURL::port() const { return port_number;}/***** This method will return the password part of the URL or NULL** if there is none.***/const char* KURL::passwd() const{ if (passwd_part.isNull()) return ""; else return passwd_part.data(); }/***** This method will set the specified path.** No checking is done - the path must be correct.***/void KURL::setPath( const char *newPath ){ path_part = newPath;}/********/void KURL::setHost( const char *newHost ){ host_part = newHost;}/********/void KURL::setPassword( const char *password ){ passwd_part = password;}/********/void KURL::setUser( const char *newUser ){ user_part = newUser;}/********/void KURL::setPort( const unsigned int newPort ){ port_number = newPort;}/********/bool KURL::cdUp( bool zapRef ) { if( zapRef) setReference(""); return cd( "..");}/********/bool KURL::operator==( const KURL &_url) const{ return _url.url() == url();}/********/const char* KURL::directoryURL( bool _trailing ){ QString u = url(); // Calculate only on demand if ( u.right( 1 )[0] == '/' && ( _trailing || u.right(2) == ":/" ) ) dir_part = u.data(); else { if ( !_trailing && u.right( 1 ) == "/" && u.right(2) != ":/" ) u.truncate( u.length() -1 ); int i = u.findRev( "/" ); if ( i == -1 ) // Should never happen dir_part = "/"; else dir_part = u.left( i + 1 ); } return dir_part.data();}/********/QString KURL::url() const{ QString url = protocol_part.copy(); if( !host_part.isEmpty() ) { url += "://"; if ( !user_part.isEmpty() ) { url += user_part.data(); if ( !passwd_part.isEmpty() ) { url += ":"; url += passwd_part.data(); } url += "@"; } url += host_part; if ( port_number != 0 ) { QString tmp(url.data()); url.sprintf("%s:%d",tmp.data(),port_number); } } else url += "://"; if( !path_part.isEmpty() && hasPath() ) url += path_part; if( !search_part.isNull()) { if(path_part.isEmpty() || !hasPath() ) url += "/"; url += "?" + search_part; } if( !ref_part.isEmpty() ) { if(path_part.isEmpty() || !hasPath() ) url += "/"; url += "#" + ref_part; } return url;}/********/const char* KURL::filename(){ if ( path_part.isEmpty() ) return ""; if ( path_part.data() == "/") return ""; if (path_part_decoded.isNull()) { path_part_decoded = path_part.copy(); KURL::decodeURL(path_part_decoded); } int pos = path_part_decoded.findRev( "/" ); return path_part_decoded.data() + pos + 1;} /********/bool KURL::cd( const char* _dir, bool zapRef){ // if NULL passed as directory, just exit if ( !_dir ) return false; // clear the decoded path path_part_decoded = 0; // set the initial bNoPath value bNoPath = ( _dir[0] == 0); // if URL starts with "/file:~", build path with user's HOME directory if (( _dir[0] == '~' ) && ( protocol_part == "file" )) { path_part = getenv( "HOME" ); path_part += "/"; path_part += _dir + 1; } // path_part must contain a webpath else { if ( path_part.right(1)[0] != '/' && _dir[0] != '/' ) path_part += "/"; if ( _dir[0] == '/' ) path_part = _dir; else path_part += _dir; // Enable KURL to correctly resolve relative URLs that // contain query and/or fragment (aka reference) parts - // refer to RFC 2396 section 5. (Dawit A) int srh_loc = path_part.find ("?"); int ref_loc = path_part.find ("#"); if ( srh_loc >= 0 ) { if ( ref_loc > srh_loc && !zapRef ) { search_part = path_part.mid (srh_loc+1, ref_loc); ref_part = path_part.mid (ref_loc+1, path_part.length()); } else search_part = path_part.mid (srh_loc+1, path_part.length()); path_part = path_part.mid (0, srh_loc); } else if ( ref_loc >= 0 && !zapRef ) { ref_part = path_part.mid (ref_loc+1, path_part.length()); path_part = path_part.mid (0, ref_loc); } } if ( zapRef ) setReference( "" ); cleanPath(); return true;}/********/bool KURL::setReference( const char* _ref){ // We cant have a referece if we have no path (other than /) // if( path_part.isNull() || path_part.data()[0] == 0 ) // return false; ref_part = _ref; return true;}/********/KURL& KURL::operator=( const KURL &u){ port_number = u.port_number; malformed = u.malformed; protocol_part = u.protocol_part; host_part = u.host_part; path_part = u.path_part; search_part = u.search_part; ref_part = u.ref_part; bNoPath = u.bNoPath; path_part_decoded = u.path_part_decoded; dir_part = u.dir_part; user_part = u.user_part; passwd_part = u.passwd_part; detach(); return *this;}/********/KURL& KURL::operator=( const char *_url ){ parse( _url ); return *this;}/********/QString KURL::parentURL(){ QRegExp exp( "[a-zA-Z]+:" ); QString str = url(); int i = str.length(); while( ( i = str.findRev( "#", i) ) != -1 ) { if ( exp.match( str.data(), i + 1 ) != -1 ) return QString( str.left( i ) ); i--; } return QString( str.data() );}/********/QString KURL::childURL(){ QRegExp exp( "[a-zA-Z]+:" ); QString str = url(); int i = str.length(); while( ( i = str.findRev( "#", i) ) != -1 ) { if ( exp.match( str.data(), i + 1 ) != -1 ) return QString( str.data() + i + 1 ); i--; } return QString();} /********/QString KURL::nestedURL(){ QString s = childURL(); if ( s.isEmpty() ) return url(); return s;}/********/void KURL::cleanPath(){ if ( path_part.isEmpty() ) return; // Did we have a trailing '/' int len = path_part.length(); bool slash = false; if ( len > 0 && path_part.right(1)[0] == '/' ) slash = true; // commented out .. jsk .. QDir is unimplemented .. please fix // path_part = QDir::cleanDirPath( path_part ); // Restore the trailing '/' len = path_part.length(); if ( len > 0 && path_part.right(1)[0] != '/' && slash ) path_part += "/";}/********/bool KURL::isLocalFile() { if (protocol_part != "file") return false; if (hasSubProtocol()) return false; return host_part.isEmpty();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -