~ubuntu-branches/ubuntu/intrepid/kdesdk/intrepid-updates

« back to all changes in this revision

Viewing changes to umbrello/umbrello/codeimport/kdevcppparser/urlutil.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-28 10:11:43 UTC
  • mto: This revision was merged to the branch mainline in revision 37.
  • Revision ID: james.westby@ubuntu.com-20080528101143-gzc3styjz1b70zxu
Tags: upstream-4.0.80
ImportĀ upstreamĀ versionĀ 4.0.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 
15
15
   You should have received a copy of the GNU Library General Public License
16
16
   along with this library; see the file COPYING.LIB.  If not, write to
17
 
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
 
   Boston, MA 02111-1307, USA.
 
17
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
   Boston, MA 02110-1301, USA.
19
19
*/
20
20
 
21
21
#ifndef _URLUTIL_H_
22
22
#define _URLUTIL_H_
23
23
 
24
 
#include <qstring.h>
25
 
#include <qvaluelist.h>
 
24
#include <QtCore/QString>
26
25
#include <kurl.h>
27
26
 
28
27
namespace URLUtil
29
28
{
30
 
  enum SlashesPosition { SLASH_PREFIX = 1, SLASH_SUFFIX = 2 };
31
 
 
32
 
  /**
33
 
   * Returns the filename part of a pathname (i.e. everything past the last slash)
34
 
   */
35
 
  QString filename(const QString & pathName);
36
 
  /**
37
 
   * Returns the directory part of a path (i.e. everything up to but not including the last slash)
38
 
   */
39
 
  QString directory(const QString & pathName);
40
 
  /**
41
 
   * Returns the relative path between a parent and child URL, or blank if the specified child is not a child of parent
42
 
   */
43
 
  QString relativePath(const KURL & parent, const KURL & child, uint slashPolicy = SLASH_PREFIX);
44
 
  /**
45
 
   * Returns the relative path between a parent and child URL, or blank if the specified child is not a child of parent
46
 
   */
47
 
  QString relativePath(const QString & parent, const QString & child, uint slashPolicy = SLASH_PREFIX);
48
 
  /**
49
 
   * Returns the relative path between a directory and file. Should never return empty path.
50
 
   *  Example:
51
 
   *   dirUrl:  /home/test/src
52
 
   *   fileUrl: /home/test/lib/mylib.cpp
53
 
   *  returns:  ../lib/mylib.cpp
54
 
   */
55
 
  QString relativePathToFile( const QString & dirUrl, const QString & fileUrl );
56
 
  /**
57
 
   *Returns the path 'up one level' - the opposite of what filename returns
58
 
   */
59
 
  QString upDir(const QString & path, bool slashSuffix = false);
60
 
  /**
61
 
   * 'Merges' URLs - changes a URL that starts with dest to start with source instead
62
 
   *   Example:
63
 
   *     source is /home/me/
64
 
   *     dest is /home/you/
65
 
   *     child is /home/you/dir1/file1
66
 
   *   returns /home/me/dir1/fil1
67
 
   */
68
 
  KURL mergeURL(const KURL & source, const KURL & dest, const KURL & child);
69
 
  /**
70
 
   * Returns the file extension for a filename or path
71
 
   */
72
 
  QString getExtension(const QString & path);
73
 
 
74
 
  /**
75
 
  * Given a base directory url in @p baseDirUrl and the url referring to a date sub-directory or file,
76
 
  * it will return the path relative to @p baseDirUrl.
77
 
  * If baseDirUrl == url.path() then it will return ".".
78
 
  * <code>
79
 
  * KURL baseUrl, dirUrl;
80
 
  * baseUrl.setPath( "/home/mario/src/kdevelop/" );
81
 
  * dirUrl.setPath( "/home/mario/src/kdevelop/parts/cvs/" );
82
 
  * QString relPathName = extractDirPathRelative( baseUrl, url ); // == "parts/cvs/"
83
 
  * QString absPathName = extractDirPathAbsolute( url ); // == "/home/mario/src/kdevelop/parts/cvs/"
84
 
  * </code>
85
 
  * Note that if you pass a file name in @p url (instead of a directory) or the @p baseUrl is not contained
86
 
  * in @p url then the function will return "" (void string).
87
 
  */
88
 
  QString extractPathNameRelative(const KURL &baseDirUrl, const KURL &url );
89
 
  QString extractPathNameRelative(const QString &basePath, const KURL &url );
90
 
  QString extractPathNameRelative(const QString &basePath, const QString &absFilePath );
91
 
 
92
 
  /**
93
 
  * Will return the absolute path name referred in @p url.
94
 
  * Look at above for an example.
95
 
  */
96
 
  QString extractPathNameAbsolute( const KURL &url );
97
 
 
98
 
  /**
99
 
  * Returns a QStringList of relative (to @p baseDir) paths from a list of KURLs in @p urls
100
 
  */
101
 
  QStringList toRelativePaths( const QString &baseDir, const KURL::List &urls);
102
 
 
103
 
  /**
104
 
  * If @p url is a directory will return true, false otherwise.
105
 
  */
106
 
  bool isDirectory( const KURL &url );
107
 
  bool isDirectory( const QString &absFilePath );
108
 
 
109
 
  /**
110
 
  * Will dump the list of KURL @p urls on standard output, eventually printing @ aMessage if it
111
 
  * is not null.
112
 
  */
113
 
  void dump( const KURL::List &urls, const QString &aMessage = QString::null );
114
 
 
115
 
  /**
116
 
   * Same as QDir::canonicalPath in later versions of QT. Earlier versions of QT
117
 
   * had this broken, so it's reproduced here.
118
 
   */
119
 
  QString canonicalPath( const QString & path );
120
 
 
121
 
    /**
122
 
     * Performs environment variable expansion on @p variable.
123
 
     *
124
 
     * @param variable the string with the environment variable to expand.
125
 
     * @return the expanded environment variable value. if the variable
126
 
     *         cannot be expanded, @p variable itself is returned.
127
 
     */
128
 
    QString envExpand ( const QString &variable );
 
29
 
 
30
enum SlashesPosition { SLASH_PREFIX = 1, SLASH_SUFFIX = 2 };
 
31
 
 
32
/**
 
33
 * Returns the filename part of a pathname (i.e. everything past the last slash)
 
34
 */
 
35
QString filename(const QString & pathName);
 
36
/**
 
37
 * Returns the directory part of a path (i.e. everything up to but not including the last slash)
 
38
 */
 
39
QString directory(const QString & pathName);
 
40
/**
 
41
 * Returns the relative path between a parent and child URL, or blank if the specified child is not a child of parent
 
42
 */
 
43
QString relativePath(const KUrl & parent, const KUrl & child, uint slashPolicy = SLASH_PREFIX);
 
44
/**
 
45
 * Returns the relative path between a parent and child URL, or blank if the specified child is not a child of parent
 
46
 */
 
47
QString relativePath(const QString & parent, const QString & child, uint slashPolicy = SLASH_PREFIX);
 
48
/**
 
49
 * Returns the relative path between a directory and file. Should never return empty path.
 
50
 *  Example:
 
51
 *   dirUrl:  /home/test/src
 
52
 *   fileUrl: /home/test/lib/mylib.cpp
 
53
 *  returns:  ../lib/mylib.cpp
 
54
 */
 
55
QString relativePathToFile(const QString & dirUrl, const QString & fileUrl);
 
56
/**
 
57
 * Returns the path 'up one level' - the opposite of what filename returns
 
58
 */
 
59
QString upDir(const QString & path, bool slashSuffix = false);
 
60
/**
 
61
 * 'Merges' URLs - changes a URL that starts with dest to start with source instead
 
62
 *   Example:
 
63
 *     source is /home/me/
 
64
 *     dest is /home/you/
 
65
 *     child is /home/you/dir1/file1
 
66
 *   returns /home/me/dir1/fil1
 
67
 */
 
68
KUrl mergeURL(const KUrl & source, const KUrl & dest, const KUrl & child);
 
69
/**
 
70
 * Returns the file extension for a filename or path
 
71
 */
 
72
QString getExtension(const QString & path);
 
73
 
 
74
/**
 
75
 * Given a base directory url in @p baseDirUrl and the url referring to a date sub-directory or file,
 
76
 * it will return the path relative to @p baseDirUrl.
 
77
 * If baseDirUrl == url.path() then it will return ".".
 
78
 * <code>
 
79
 * KUrl baseUrl, dirUrl;
 
80
 * baseUrl.setPath( "/home/mario/src/kdevelop/" );
 
81
 * dirUrl.setPath( "/home/mario/src/kdevelop/parts/cvs/" );
 
82
 * QString relPathName = extractDirPathRelative( baseUrl, url ); // == "parts/cvs/"
 
83
 * QString absPathName = extractDirPathAbsolute( url ); // == "/home/mario/src/kdevelop/parts/cvs/"
 
84
 * </code>
 
85
 * Note that if you pass a file name in @p url (instead of a directory) or the @p baseUrl is not contained
 
86
 * in @p url then the function will return "" (void string).
 
87
 */
 
88
QString extractPathNameRelative(const KUrl &baseDirUrl, const KUrl &url);
 
89
QString extractPathNameRelative(const QString &basePath, const KUrl &url);
 
90
QString extractPathNameRelative(const QString &basePath, const QString &absFilePath);
 
91
 
 
92
/**
 
93
 * Will return the absolute path name referred in @p url.
 
94
 * Look at above for an example.
 
95
 */
 
96
QString extractPathNameAbsolute(const KUrl &url);
 
97
 
 
98
/**
 
99
 * Returns a QStringList of relative (to @p baseDir) paths from a list of KURLs in @p urls
 
100
 */
 
101
QStringList toRelativePaths(const QString &baseDir, const KUrl::List &urls);
 
102
 
 
103
/**
 
104
 * If @p url is a directory will return true, false otherwise.
 
105
 */
 
106
bool isDirectory(const KUrl &url);
 
107
bool isDirectory(const QString &absFilePath);
 
108
 
 
109
/**
 
110
 * Will dump the list of KUrl @p urls on standard output, eventually printing @ aMessage if it
 
111
 * is not null.
 
112
 */
 
113
void dump(const KUrl::List &urls, const QString &aMessage = QString());
 
114
 
 
115
/**
 
116
 * Same as QDir::canonicalPath in later versions of QT. Earlier versions of QT
 
117
 * had this broken, so it's reproduced here.
 
118
 */
 
119
QString canonicalPath(const QString & path);
 
120
 
 
121
/**
 
122
 * Performs environment variable expansion on @p variable.
 
123
 *
 
124
 * @param variable the string with the environment variable to expand.
 
125
 * @return the expanded environment variable value. if the variable
 
126
 *         cannot be expanded, @p variable itself is returned.
 
127
 */
 
128
QString envExpand(const QString &variable);
129
129
 
130
130
}
131
131