Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXPath.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * P a t h N a m e M a n i p u l a t i o n *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2000,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXPath.h,v 1.11 2006/01/23 06:03:15 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXPATH_H
25 #define FXPATH_H
26 
27 
28 namespace FX {
29 
30 
31 namespace FXPath {
32 
33  /**
34  * Return root of absolute path; on Unix, this is just "/". On
35  * Windows, this is "\\" or "C:\". Returns the empty string
36  * if the given path is not absolute.
37  */
38  FXString FXAPI root(const FXString& file);
39 
40  /**
41  * Return the directory part of the path name.
42  * Note that directory("/bla/bla/") is "/bla/bla" and NOT "/bla".
43  * However, directory("/bla/bla") is "/bla" as we expect!
44  */
45  FXString FXAPI directory(const FXString& file);
46 
47  /**
48  * Return name and extension part of the path name.
49  * Note that name("/bla/bla/") is "" and NOT "bla".
50  * However, name("/bla/bla") is "bla" as we expect!
51  */
52  FXString FXAPI name(const FXString& file);
53 
54  /// Return file title, i.e. document name only
55  FXString FXAPI title(const FXString& file);
56 
57  /// Return extension part of the file name
58  FXString FXAPI extension(const FXString& file);
59 
60  /// Return file name less the extension
62 
63  /// Return the drive letter prefixing this file name (if any).
64  FXString FXAPI drive(const FXString& file);
65 
66  /// Perform tilde or environment variable expansion
67  FXString FXAPI expand(const FXString& file);
68 
69  /// Contract path based on user name and environment variable
71 
72  /**
73  * Simplify a file path; the path will remain relative if it was relative,
74  * or absolute if it was absolute. Also, a trailing "/" will be preserved
75  * as this is important in other functions.
76  * For example, simplify("..//aaa/./bbb//../c/") becomes "../aaa/c/".
77  */
78  FXString FXAPI simplify(const FXString& file);
79 
80  /// Return absolute path from current directory and file name
81  FXString FXAPI absolute(const FXString& file);
82 
83  /// Return absolute path from base directory and file name
84  FXString FXAPI absolute(const FXString& base,const FXString& file);
85 
86  /// Return relative path of file to the current directory
87  FXString FXAPI relative(const FXString& file);
88 
89  /// Return relative path of file to given base directory
90  FXString FXAPI relative(const FXString& base,const FXString& file);
91 
92  /// Return path following local path separator conventions
93  FXString FXAPI convert(const FXString& path);
94 
95  /// Return path to directory above input directory name
96  FXString FXAPI upLevel(const FXString& file);
97 
98  /// Return true if file name is absolute
99  bool FXAPI isAbsolute(const FXString& file);
100 
101  /// Return true if input directory is a top-level directory
102  bool FXAPI isTopDirectory(const FXString& file);
103 
104  /// Return true if input path is a file share
105  bool FXAPI isShare(const FXString& file);
106 
107  /// Enquote filename to make safe for shell
108  FXString FXAPI enquote(const FXString& file,bool forcequotes=false);
109 
110  /// Dequote filename to get original again
111  FXString FXAPI dequote(const FXString& file);
112 
113  /**
114  * Perform wildcard match of a filename against a wildcard pattern.
115  * The wildcard pattern may comprise ordinary characters or special
116  * matching characters, as given below:
117  *
118  * ? Any single character.
119  * * Zero or more of any character.
120  * [abc] Any character from the set {a,b,c}.
121  * [^abc] Any character BUT the ones from the set {a,b,c}.
122  * [!abc] Ditto.
123  * [a-zA-Z] Matches single character, which must be one of a-z or A-Z.
124  * [^a-zA-Z] Matches single character, which must be anything other than a-z or A-Z.
125  * [!a-zA-Z] Ditto.
126  * pat1|pat2 Match sub-pattern pat1 or pat2.
127  * pat1,pat2 Ditto.
128  * (pat1|pat2) Match sub-pattern pat1 or pat2; patterns may be nested.
129  * (pat1,pat2) Ditto.
130  *
131  * The special characters may be escaped to treat them as ordinary characters.
132  * Matching may be influenced by a number of flags:
133  *
134  * FILEMATCH_FILE_NAME No wildcard can ever match /
135  * FILEMATCH_NOESCAPE Backslashes don't quote special chars
136  * FILEMATCH_PERIOD Leading . is matched only explicitly
137  * FILEMATCH_LEADING_DIR Ignore /... after a match
138  * FILEMATCH_CASEFOLD Compare without regard to case
139  */
140  bool FXAPI match(const FXString& pattern,const FXString& file,FXuint flags=(FILEMATCH_NOESCAPE|FILEMATCH_FILE_NAME));
141 
142  /**
143  * Generate unique filename of the form pathnameXXX.ext, where
144  * pathname.ext is the original input file, and XXX is a number,
145  * possibly empty, that makes the file unique.
146  */
147  FXString FXAPI unique(const FXString& file);
148 
149  /**
150  * Search path list for this file, return full path name for first occurrence.
151  */
152  FXString FXAPI search(const FXString& pathlist,const FXString& file);
153 
154  }
155 
156 }
157 
158 #endif
bool isShare(const FXString &file)
Return true if input path is a file share.
FXString enquote(const FXString &file, bool forcequotes=false)
Enquote filename to make safe for shell.
bool isAbsolute(const FXString &file)
Return true if file name is absolute.
unsigned int FXuint
Definition: fxdefs.h:396
FXString dequote(const FXString &file)
Dequote filename to get original again.
FXString relative(const FXString &file)
Return relative path of file to the current directory.
#define FXAPI
Definition: fxdefs.h:122
FXString title(const FXString &file)
Return file title, i.e. document name only.
FXString name(const FXString &file)
Return name and extension part of the path name.
FXString search(const FXString &pathlist, const FXString &file)
Search path list for this file, return full path name for first occurrence.
FXString contract(const FXString &file, const FXString &user=FXString::null, const FXString &var=FXString::null)
Contract path based on user name and environment variable.
FXString unique(const FXString &file)
Generate unique filename of the form pathnameXXX.ext, where pathname.ext is the original input file...
Backslashes don't quote special chars.
Definition: fxdefs.h:318
FXString root(const FXString &file)
Return root of absolute path; on Unix, this is just "/".
FXString extension(const FXString &file)
Return extension part of the file name.
bool match(const FXString &pattern, const FXString &file, FXuint flags=(FILEMATCH_NOESCAPE|FILEMATCH_FILE_NAME))
Perform wildcard match of a filename against a wildcard pattern.
bool isTopDirectory(const FXString &file)
Return true if input directory is a top-level directory.
Definition: FX4Splitter.h:31
FXString expand(const FXString &file)
Perform tilde or environment variable expansion.
FXString absolute(const FXString &file)
Return absolute path from current directory and file name.
FXuint user()
Get effective user id.
FXString upLevel(const FXString &file)
Return path to directory above input directory name.
static const FXchar null[]
Definition: FXString.h:35
FXString directory(const FXString &file)
Return the directory part of the path name.
FXString drive(const FXString &file)
Return the drive letter prefixing this file name (if any).
FXString simplify(const FXString &file)
Simplify a file path; the path will remain relative if it was relative, or absolute if it was absolut...
No wildcard can ever match `/'.
Definition: fxdefs.h:317
FXString stripExtension(const FXString &file)
Return file name less the extension.
FXString convert(const FXString &path)
Return path following local path separator conventions.
FXString provides essential string manipulation capabilities.
Definition: FXString.h:33

Copyright © 1997-2005 Jeroen van der Zijp