![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * P a t h N a m e M a n i p u l a t i o n * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 2000,2009 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU Lesser General Public License as published by * 00010 * the Free Software Foundation; either version 3 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public License * 00019 * along with this program. If not, see <http://www.gnu.org/licenses/> * 00020 ********************************************************************************* 00021 * $Id: FXPath.h,v 1.24 2009/01/06 13:07:26 fox Exp $ * 00022 ********************************************************************************/ 00023 #ifndef FXPATH_H 00024 #define FXPATH_H 00025 00026 00027 namespace FX { 00028 00029 00030 namespace FXPath { 00031 00032 /** 00033 * Return root of absolute path; on Unix, this is just "/". On 00034 * Windows, this is "\", "\\Janes PC\" or "C:\". 00035 * Returns the empty string if the given path is not absolute. 00036 */ 00037 extern FXAPI FXString root(const FXString& file); 00038 00039 /** 00040 * Return share name from Windows UNC filename, if any. 00041 * For example, share("\\Janes PC\Janes Documents\Document.doc") 00042 * returns "Janes PC". 00043 */ 00044 extern FXAPI FXString share(const FXString& file); 00045 00046 /** 00047 * Return the directory part of the path name. 00048 * Note that directory("/bla/bla/") is "/bla/bla" and NOT "/bla". 00049 * However, directory("/bla/bla") is "/bla" as we expect! 00050 */ 00051 extern FXAPI FXString directory(const FXString& file); 00052 00053 /** 00054 * Return name and extension part of the path name. 00055 * Note that name("/bla/bla/") is "" and NOT "bla". 00056 * However, name("/bla/bla") is "bla" as we expect! 00057 */ 00058 extern FXAPI FXString name(const FXString& file); 00059 00060 /// Return file title, i.e. document name only 00061 extern FXAPI FXString title(const FXString& file); 00062 00063 /// Return extension part of the file name 00064 extern FXAPI FXString extension(const FXString& file); 00065 00066 /// Return file name less the extension 00067 extern FXAPI FXString stripExtension(const FXString& file); 00068 00069 /// Return the drive letter prefixing this file name (if any). 00070 extern FXAPI FXString drive(const FXString& file); 00071 00072 /// Perform tilde or environment variable expansion 00073 extern FXAPI FXString expand(const FXString& file); 00074 00075 /// Contract path based on user name and environment variable 00076 extern FXAPI FXString contract(const FXString& file,const FXString& user=FXString::null,const FXString& var=FXString::null); 00077 00078 /** 00079 * Simplify a file path; the path will remain relative if it was relative, 00080 * or absolute if it was absolute. Also, a trailing "/" will be preserved 00081 * as this is important in other functions. 00082 * For example, simplify("..//aaa/./bbb//../c/") becomes "../aaa/c/". 00083 */ 00084 extern FXAPI FXString simplify(const FXString& file); 00085 00086 /// Return absolute path from current directory and file name 00087 extern FXAPI FXString absolute(const FXString& file); 00088 00089 /// Return absolute path from base directory and file name 00090 extern FXAPI FXString absolute(const FXString& base,const FXString& file); 00091 00092 /// Return relative path of file to the current directory 00093 extern FXAPI FXString relative(const FXString& file); 00094 00095 /// Return relative path of file to given base directory 00096 extern FXAPI FXString relative(const FXString& base,const FXString& file); 00097 00098 /// Convert path from using 'sepfm' or 'septo' to use only 'septo' path-separators 00099 extern FXAPI FXString convert(const FXString& file,FXchar septo=PATHSEP,FXchar sepfm='/'); 00100 00101 /// Return path to directory above input directory name 00102 extern FXAPI FXString upLevel(const FXString& file); 00103 00104 /// Return true if file positively inside base directory 00105 extern FXAPI FXbool isInside(const FXString& base,const FXString& file); 00106 00107 /// Return true if file name is absolute 00108 extern FXAPI FXbool isAbsolute(const FXString& file); 00109 00110 /// Return true if input directory is a top-level directory 00111 extern FXAPI FXbool isTopDirectory(const FXString& file); 00112 00113 /// Return true if input path is a file share 00114 extern FXAPI FXbool isShare(const FXString& file); 00115 00116 /// Enquote filename to make safe for shell 00117 extern FXAPI FXString enquote(const FXString& file,FXbool forcequotes=false); 00118 00119 /// Dequote filename to get original again 00120 extern FXAPI FXString dequote(const FXString& file); 00121 00122 /** 00123 * Perform wildcard match of a filename against a wildcard pattern. 00124 * The wildcard pattern may comprise ordinary characters or special 00125 * matching characters, as given below: 00126 * 00127 * ? Any single character. 00128 * * Zero or more of any character. 00129 * [abc] Any character from the set {a,b,c}. 00130 * [^abc] Any character BUT the ones from the set {a,b,c}. 00131 * [!abc] Ditto. 00132 * [a-zA-Z] Matches single character, which must be one of a-z or A-Z. 00133 * [^a-zA-Z] Matches single character, which must be anything other than a-z or A-Z. 00134 * [!a-zA-Z] Ditto. 00135 * pat1|pat2 Match sub-pattern pat1 or pat2. 00136 * pat1,pat2 Ditto. 00137 * (pat1|pat2) Match sub-pattern pat1 or pat2; patterns may be nested. 00138 * (pat1,pat2) Ditto. 00139 * 00140 * The special characters may be escaped to treat them as ordinary characters. 00141 * Matching may be influenced by a number of flags: 00142 * 00143 * FILEMATCH_FILE_NAME No wildcard can ever match / 00144 * FILEMATCH_NOESCAPE Backslashes don't quote special chars 00145 * FILEMATCH_PERIOD Leading . is matched only explicitly 00146 * FILEMATCH_LEADING_DIR Ignore /... after a match 00147 * FILEMATCH_CASEFOLD Compare without regard to case 00148 */ 00149 extern FXAPI FXbool match(const FXString& file,const FXString& pattern="*",FXuint flags=(FILEMATCH_NOESCAPE|FILEMATCH_FILE_NAME)); 00150 00151 /** 00152 * Generate unique filename of the form pathnameXXX.ext, where 00153 * pathname.ext is the original input file, and XXX is a number, 00154 * possibly empty, that makes the file unique. 00155 */ 00156 extern FXAPI FXString unique(const FXString& file); 00157 00158 /** 00159 * Search path list for this file, return full path name for first occurrence. 00160 */ 00161 extern FXAPI FXString search(const FXString& pathlist,const FXString& file); 00162 00163 } 00164 00165 } 00166 00167 #endif
![]() |