kurl.h

来自「将konqueror浏览器移植到ARM9 2410中」· C头文件 代码 · 共 575 行 · 第 1/2 页

H
575
字号
/* This file is part of the KDE libraries *  Copyright (C) 1999 Torben Weis <weis@kde.org> * *  This library is free software; you can redistribute it and/or *  modify it under the terms of the GNU Library General Public *  License as published by the Free Software Foundation; either *  version 2 of the License, or (at your option) any later version. * *  This library is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *  Library General Public License for more details. * *  You should have received a copy of the GNU Library General Public License *  along with this library; see the file COPYING.LIB.  If not, write to *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330, *  Boston, MA 02111-1307, USA. **/#ifndef __kurl_h__#define __kurl_h__ "$Id: kurl.h,v 1.76 2001/07/19 07:42:41 hausmann Exp $"#include <qstring.h>#include <qvaluelist.h>class QUrl;class QStringList;struct KURLPrivate;/** * Represent and parse a URL. * * A prototypical URL looks like: * <pre> *   protocol:/user:password@hostname:port/path/to/file.ext#reference * </pre> * *  @ref KURL has some restrictions regarding the path * encoding. @ref KURL works internally with the decoded path and * and encoded query. For example, * <pre> * http://localhost/cgi-bin/test%20me.pl?cmd=Hello%20you * </pre> * would result in a decoded path "/cgi-bin/test me.pl" * and in the encoded query "?cmd=Hello%20you". * Since path is internally always encoded you may @em not use * "%00" in the path, although this is OK for the query. * *  @author  Torben Weis <weis@kde.org> */class KURL{public:  class List : public QValueList<KURL>  {  public:      List() { }      List(const QStringList &);      QStringList toStringList() const;  };  /**   * Construct an empty URL.   */  KURL();  /**   * destruktor   */  ~KURL();  /**   * Usual constructor, to construct from a string.   * @param url A URL, not a filename. If the URL does not have a protocol   *             part, "file:" is assumed.   *             It is dangerous to feed unix filenames into this function,   *             this will work most of the time but not always.   *             For example "/home/Torben%20Weis" will be considered a URL   *             pointing to the file "/home/Torben Weis" instead of to the   *             file "/home/Torben%20Weis".   *             This means that if you have a usual UNIX like path you   *             should not use this constructor.   *             Instead create an empty url and set the path by using   *             @ref setPath().   * @param encoding_hint Reserved, should be 0.   */  KURL( const QString& url, int encoding_hint = 0 );  /**   * Constructor taking a char * @p url, which is an _encoded_ representation   * of the URL, exactly like the usual constructor. This is useful when   * then URL, in its encoded form, is strictly ascii.   */  KURL( const char * url, int encoding_hint = 0 );  /**   * Copy constructor   */  KURL( const KURL& u );  /**   * Convert from a @ref QUrl.   */  KURL( const QUrl &u );  /**   * Constructor allowing relative URLs.   *   * @param _baseurl The base url.   * @param _rel_url A relative or absolute URL.   * If this is an absolute URL then @p _baseurl will be ignored.   * If this is a relative URL it will be combined with @p _baseurl.   * Note that _rel_url should be encoded too, in any case.   * So do NOT pass a path here (use setPath or addPath instead).   * @param encoding_hint Reserved, should be 0.   */  KURL( const KURL& _baseurl, const QString& _rel_url, int encoding_hint=0 );  /**   * Retrieve the protocol for the URL (i.e., file, http, etc.).   **/  QString protocol() const { return m_bIsMalformed ? QString::null : m_strProtocol; }  /**   * Set the protocol for the URL (i.e., file, http, etc.)   **/  void setProtocol( const QString& _txt );  /**   * Retrieve the decoded user name (login, user id, ...) included in the URL.   **/  QString user() const { return m_strUser; }  /**   * Set the user name (login, user id, ...) included the URL.   *   * Special characters in the user name will appear encoded in the URL.   **/  void setUser( const QString& _txt );  /**   * Test to see if this URL has a user name included in it.   **/  bool hasUser() const { return !m_strUser.isEmpty(); }  /**   * Retrieve the decoded password (corresponding to @ref user()) included in the URL.   **/  QString pass() const { return m_strPass; }  /**   * Set the password (corresponding to @ref user()) included in the URL.   *   * Special characters in the password will appear encoded in the URL.   **/  void setPass( const QString& _txt );  /**   * Test to see if this URL has a password included in it.   **/  bool hasPass() const { return !m_strPass.isEmpty(); }  /**   * Retrieve the decoded hostname included in the URL.   **/  QString host() const { return m_strHost; }  /**   * Set the hostname included in the URL.   *   * Special characters in the hostname will appear encoded in the URL.   **/  void setHost( const QString& _txt );  /**   * Test to see if this URL has a hostname included in it.   **/  bool hasHost() const { return !m_strHost.isEmpty(); }  /**   * Retrieve the port number included in the URL.   * If there is no port number specified in the URL, returns 0.   **/  unsigned short int port() const { return m_iPort; }  /**   * Set the port number included in the URL.   **/  void setPort( unsigned short int _p );  /**   * @return The current decoded path. This does @em not include the query.   *   */  QString path() const  { return m_strPath; }  /**   * @param _trailing May be ( -1, 0 +1 ). -1 strips a trailing '/', +1 adds   *                  a trailing '/' if there is none yet and 0 returns the   *                  path unchanged. If the URL has no path, then no '/' is added   *                  anyway. And on the other side: If the path is "/", then this   *                  character won't be stripped. Reason: "ftp://weis@host" means something   *                  completely different than "ftp://weis@host/". So adding or stripping   *                  the '/' would really alter the URL, while "ftp://host/path" and   *                  "ftp://host/path/" mean the same directory.   *   * @return The current decoded path. This does not include the query.   */  QString path( int _trailing ) const;  /**   * path This is considered to be decoded. This means: %3f does not become decoded   *      and the ? does not indicate the start of the query part.   *      The query is not changed by this function.   */  void setPath( const QString& path );  /**   * Test to see if this URL has a path is included in it.   **/  bool hasPath() const { return !m_strPath.isEmpty(); }  /** Removes all multiple directory separators ('/') and   * resolves any "." or ".." found in the path.   * Calls @ref QDir::cleanDirPath but saves the trailing slash if any.   */  void cleanPath();     /**   * Same as above except it takes a flag that allows you   * to ignore the clean up of the multiple directory separators.   *    * Some servers seem not to like the removal of extra '/'    * eventhough it is against the specification in RFC 2396.   */     void cleanPath(bool cleanDirSeparator);  /**   * This is useful for HTTP. It looks first for '?' and decodes then.   * The encoded path is the concatenation of the current path and the query.   * @param encoding_hint Reserved, should be 0.   */  void setEncodedPathAndQuery( const QString& _txt, int encoding_hint = 0 );  /**   * @return The concatenation if the encoded path , '?' and the encoded query.   *   * @param _no_empty_path If set to true then an empty path is substituted by "/".   * @param encoding_hint Reserved, should be 0.   */  QString encodedPathAndQuery( int _trailing = 0, bool _no_empty_path = false, int encoding_hint = 0) const;  /**   * @param _txt This is considered to be encoded. This has a good reason:   * The query may contain the 0 character.   *   * The query should start with a '?'. If it doesn't '?' is prepended.   * @param encoding_hint Reserved, should be 0.   */  void setQuery( const QString& _txt, int encoding_hint = 0);  /**   * @return The encoded query.   * This has a good reason: The query may contain the 0 character.   * If a query is present it always starts with a '?'.   * A single '?' means an empty query.   * An empty string means no query.   */  QString query() const { return m_strQuery_encoded; }  /**   * The reference is @em never decoded automatically.   */  QString ref() const { return m_strRef_encoded; }  /**   * Set the reference part (everything after '#').   * @param _txt is considered encoded.   */  void setRef( const QString& _txt ) { m_strRef_encoded = _txt; }  /**   * @return @p true if the reference part of the URL is not empty. In a URL like   *         http://www.kde.org/kdebase.tar#tar:/README it would return @p true, too.   */  bool hasRef() const { return !m_strRef_encoded.isEmpty(); }  /**   * @return The HTML-style reference.   */  QString htmlRef() const;  /**   * @return The HTML-style reference in its original form.   */  QString encodedHtmlRef() const;  /**   * Set the HTML-style reference.   *   * @param _ref This is considered to be @em not encoded in contrast to @ref setRef()

⌨️ 快捷键说明

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