kurl.h

来自「konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版」· C头文件 代码 · 共 1,829 行 · 第 1/4 页

H
1,829 行
字号
  /**   * @brief Tests if this URL is equal to the given one   *   * Tests each member for equality unless one of the URLs is invalid   * in which case they are not considered equal (even if both are invalid).   *   * Same as equals() when used with @p ignore_trailing set to   * @c false (default)   *   * @param _u the URL to compare to   *   * @return @c true if equal and neither this URL nor @p _u is malformed.   *         Otherwise @c false   *   * @see equals()   * @see isValid()   * @see operator!=()   * @see operator<()   */  bool operator==( const KURL& _u ) const;  /**   * @brief Tests if this URL is equal to the one given as a string   *   * Creates a KURL instance for @p _u and compares with that using   * the equality operator for two KURLs.   *   * See the respective constructor for known limitations.   *   * @param _u the string to compare to   *   * @return @c true if equal and neither this URL nor @p _u is malformed.   *         Otherwise @c false   *   * @see KURL(const QString &, int)   * @see operator==(const KURL &)   * @see equals()   * @see isValid()   * @see operator!=()   * @see operator<()   */  bool operator==( const QString& _u ) const;  /**   * @brief Tests if this URL is different from the given one   *   * Tests by negating the result of operator==()   *   * @param _u the URL to compare to   *   * @return the negated result of operator==()   *   * @see operator==()   * @see operator<()   */  bool operator!=( const KURL& _u ) const { return !( *this == _u ); }  /**   * @brief Tests if this URL is different from the one given as a string   *   * Tests by negating the result of operator==(const QString &)   *   * @param _u the URL to compare to   *   * @return the negated result of operator==(const QString &)   *   * @see operator==(const QString &)   * @see operator<()   */  bool operator!=( const QString& _u ) const { return !( *this == _u ); }  /**   * @brief Compares this URL with another one   *   * The same as equals(), just with a less obvious name.   *   * @param u the URL to compare this one with   * @param ignore_trailing set to @c true to ignore trailing @c '/' characters   *   * @return @c true if both URLs are the same   *   * @see operator==. This function should be used if you want to   *      ignore trailing @c '/' characters   *   * @deprecated Use equals() instead.   */  bool cmp( const KURL &u, bool ignore_trailing = false ) const KDE_DEPRECATED;  /**   * @brief Compares this URL with another one   *   * @param u the URL to compare this one with   * @param ignore_trailing set to @c true to ignore trailing @c '/' characters   *   * @return @c true if both urls are the same   *   * @see operator==. This function should be used if you want to   *      ignore trailing @c '/' characters   *   * @since 3.1   */  bool equals( const KURL &u, bool ignore_trailing = false ) const; // TODO KDE4: add bool _ignore_ref = false  /**   * @brief Tests if the given URL is parent of this URL   *   * For instance, <tt>"ftp://host/dir/"</tt> is a parent of   * <tt>"ftp://host/dir/subdir/subsubdir/"</tt>.   *   * @return @c true if this URL is a parent of @p u (or the same URL as @p u)   *   * @see equals()   * @see cd()   */  bool isParentOf( const KURL& u ) const;  /**   * @brief Splits nested URLs into a list of URLs   *   * Example for a nested URL:   * @code   * file:///home/weis/kde.tgz#gzip:/#tar:/kdebase   * @endcode   * A URL like <tt>"http://www.kde.org#tar:/kde/README.hml#ref1"</tt> will be   * split in <tt>"http://www.kde.org#ref1"</tt> and   * <tt>"tar:/kde/README.html#ref1"</tt>.   *   * That means in turn that @c "#ref1" is an HTML-style reference and not a   * new sub URL. Since HTML-style references mark a certain position in a   * document this reference is appended to every URL.   *   * The idea behind this is that browsers, for example, only look at the first   * URL while the rest is not of interest to them.   *   * @param _url the URL that has to be split   *   * @return an empty list on error or the list of split URLs   *   * @see hasSubURL()   * @see KURL(const QString&, int)   * @see join()   */  static List split( const QString& _url );  /**   * @brief Splits nested URLs into a list of URLs   *   * Example for a nested URL:   * @code   * file:///home/weis/kde.tgz#gzip:/#tar:/kdebase   * @endcode   * A URL like <tt>"http://www.kde.org#tar:/kde/README.hml#ref1"</tt> will be   * split in <tt>"http://www.kde.org#ref1"</tt> and   * <tt>"tar:/kde/README.html#ref1"</tt>.   *   * That means in turn that @c "#ref1" is an HTML-style reference and not a   * new sub URL. Since HTML-style references mark a certain position in a   * document this reference is appended to every URL.   *   * The idea behind this is that browsers, for example, only look at the first   * URL while the rest is not of interest to them.   *   * @param _url the URL that has to be split   *   * @return an empty list on error or the list of split URLs   *   * @see hasSubURL()   * @see join()   */  static List split( const KURL& _url );  /**   * @brief Joins a list of URLs into a single URL with sub URLs   *   * Reverses split(). Only the first URL may have a reference. This reference   * is considered to be HTML-like and is appended at the end of the resulting   * joined URL.   *   * @param _list the list to join   *   * @return the joined URL or an invalid URL if the list is empty   *   * @see split()   */  static KURL join( const List& _list );  /**   * @brief Creates a KURL object from a QString representing either an   *        absolute path or a real URL   *   * Use this method instead of   * @code   * QString someDir = ...   * KURL url = someDir;   * @endcode   *   * Otherwise some characters (e.g. the '#') won't be encoded properly.   *   * @param text the string representation of the URL to convert   *   * @return the new KURL   *   * @see pathOrURL()   * @see KURL(const QString&, int)   *   * @since 3.1   */  static KURL fromPathOrURL( const QString& text );  /**   * @brief Encodes a string for use in URLs   *   * Convenience function.   *   * Convert unicoded string to local encoding and use %%-style   * encoding for all common delimiters / non-ascii characters.   *   * @param str the string to encode (can be @c QString::null)   * @param encoding_hint MIB of encoding to use.   *        See QTextCodec::mibEnum()   *   * @return the encoded string   *   * @see encode_string_no_slash()   * @see decode_string()   */  static QString encode_string(const QString &str, int encoding_hint = 0);  /**   * @brief Encodes a string for use in URLs   *   * Convenience function.   *   * Convert unicoded string to local encoding and use %%-style   * encoding for all common delimiters and non-ascii characters   * as well as the slash @c '/'.   *   * @param str the string to encode (can be @c QString::null)   * @param encoding_hint MIB of encoding to use.   *        See QTextCodec::mibEnum()   *   * @see encode_string()   * @see decode_string()   */  static QString encode_string_no_slash(const QString &str, int encoding_hint = 0);  /**   * @brief Decodes a string as used in URLs   *   * Convenience function.   *   * Decode %-style encoding and convert from local encoding to unicode.   *   * Reverse of encode_string()   *   * @param str the string to decode (can be @c QString::null)   * @param encoding_hint MIB of original encoding of @p str .   *        See QTextCodec::mibEnum()   *   * @return the decoded string   *   * @see encode_string()   * @see encode_string_no_slash()   */  static QString decode_string(const QString &str, int encoding_hint = 0);  /**   * @brief Tests if a given URL is a relative as opposed to an absolute URL   *   * Convenience function.   *   * Returns whether @p _url is likely to be a "relative" URL instead of   * an "absolute" URL.   *   * @param _url the URL to examine   * @return @c true when the URL is likely to be "relative",   *         @c false otherwise   *   * @see relativeURL()   */  static bool isRelativeURL(const QString &_url);  /**   * @brief Creates an URL relative to a base URL for a given input URL   *   * Convenience function   *   * Returns a "relative URL" based on @p base_url that points to @p url.   *   * If no "relative URL" can be created, e.g. because the protocol   * and/or hostname differ between @p base_url and @p url an absolute   * URL is returned.   *   * @note if @p base_url represents a directory, it should contain   *       a trailing slash   *   * @param base_url the URL to derive from   * @param url the URL to point to relatively from @p base_url   * @param encoding_hint MIB of original encoding of @p str .   *        See QTextCodec::mibEnum()   *   * @see isRelativeURL()   * @see relativePath()   * @see adjustPath()   */  static QString relativeURL(const KURL &base_url, const KURL &url, int encoding_hint = 0);  /**   * @brief Creates a path relative to a base path for a given input path   *   * Convenience function   *   * Returns a relative path based on @p base_dir that points to @p path.   *   * @param base_dir the base directory to derive from   * @param path the new target directory   * @param isParent an optional pointer to a boolean which, if provided, will   *        be set to reflect whether @p path has @p base_dir as a parent dir   *   * @see relativeURL()   */  static QString relativePath(const QString &base_dir, const QString &path, bool *isParent=0);  /**   * @brief Determines which URI mode is suitable for processing URIs of a   *        given protocol   *   * @param protocol the protocol name. See protocol()   *   * @return the URIMode suitable for the given protocol   *   * @see uriMode()   *   * @since 3.2   */  static URIMode uriModeForProtocol(const QString& protocol);#ifdef KDE_NO_COMPATprivate:#endif  /**   * @deprecated change code to call fileName()   */	QString filename( bool _ignore_trailing_slash_in_path = true ) const  {    return fileName(_ignore_trailing_slash_in_path);  }protected:  /**   * @brief Resets the members to their "null" state   *   * All QString members get reset to @c QString::null, the port to @c 0   * the URIMode to @c Auto and the URL becomes invalid.   *   * This is like assigning a null URL, but more efficient as it doesn't   * require the temporary object.   *   * Called by constructors, assignment operators and the parse methods in case   * of a parsing error.   *   * @see isValid()   * @see isEmpty()   */  void reset();    /**   * @brief Parses the given string and fills the URL's values on success   *   * Treats the string as an URL.   *   * @param _url the string to parse   * @param encoding_hint MIB of original encoding of @p str .   *        See QTextCodec::mibEnum()   */  void parseURL( const QString& _url, int encoding_hint = 0 );  /**   * @brief Parses the given string and fills the URL's values on success   *   * Treats the string as a generic URI.   *   * @param _url the string to parse   * @param encoding_hint MIB of original encoding of @p str .   *        See QTextCodec::mibEnum()   */  void parseRawURI( const QString& _url, int encoding_hint = 0 );  /**   * @brief Parses the given string and fills the URL's values on success   *   * Treats the string as a @c "mailto:" URI.   *   * @param _url the string to parse   * @param encoding_hint MIB of original encoding of @p str .   *        See QTextCodec::mibEnum()   */  void parseMailto( const QString& _url, int encoding_hint = 0 );  /**   * @brief Parses the given string and fills the URL's values on success   *   * @param _url the string to parse   * @param encoding_hint MIB of original encoding of @p str .   *        See QTextCodec::mibEnum()   */  void parse( const QString& _url, int encoding_hint = 0 );private:  void _setQuery( const QString& _txt, int encoding_hint = 0);  QString m_strProtocol;  QString m_strUser;  QString m_strPass;  QString m_strHost;  QString m_strPath;  QString m_strRef_encoded;  QString m_strQuery_encoded;  bool m_bIsMalformed : 1;  enum URIMode m_iUriMode : 3;  uint freeForUse     : 4;  unsigned short int m_iPort;  QString m_strPath_encoded;  friend KDECORE_EXPORT QDataStream & operator<< (QDataStream & s, const KURL & a);  friend KDECORE_EXPORT QDataStream & operator>> (QDataStream & s, KURL & a);private:  KURLPrivate* d;};/** * \relates KURL * Compares URLs. They are parsed, split and compared. * Two malformed URLs with the same string representation * are nevertheless considered to be unequal. * That means no malformed URL equals anything else. */KDECORE_EXPORT bool urlcmp( const QString& _url1, const QString& _url2 );/** * \relates KURL * Compares URLs. They are parsed, split and compared. * Two malformed URLs with the same string representation * are nevertheless considered to be unequal. * That means no malformed URL equals anything else. * * @param _url1 A reference URL * @param _url2 A URL that will be compared with the reference URL * @param _ignore_trailing Described in KURL::cmp * @param _ignore_ref If true, disables comparison of HTML-style references. */KDECORE_EXPORT bool urlcmp( const QString& _url1, const QString& _url2, bool _ignore_trailing, bool _ignore_ref );KDECORE_EXPORT QDataStream & operator<< (QDataStream & s, const KURL & a);KDECORE_EXPORT QDataStream & operator>> (QDataStream & s, KURL & a);#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?