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,2006 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (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 GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************* 00022 * $Id: FXPath.h,v 1.11 2006/01/23 06:03:15 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXPATH_H 00025 #define FXPATH_H 00026 00027 00028 namespace FX { 00029 00030 00031 namespace FXPath { 00032 00033 /** 00034 * Return root of absolute path; on Unix, this is just "/". On 00035 * Windows, this is "\\" or "C:\". Returns the empty string 00036 * if the given path is not absolute. 00037 */ 00038 FXString FXAPI root(const FXString& file); 00039 00040 /** 00041 * Return the directory part of the path name. 00042 * Note that directory("/bla/bla/") is "/bla/bla" and NOT "/bla". 00043 * However, directory("/bla/bla") is "/bla" as we expect! 00044 */ 00045 FXString FXAPI directory(const FXString& file); 00046 00047 /** 00048 * Return name and extension part of the path name. 00049 * Note that name("/bla/bla/") is "" and NOT "bla". 00050 * However, name("/bla/bla") is "bla" as we expect! 00051 */ 00052 FXString FXAPI name(const FXString& file); 00053 00054 /// Return file title, i.e. document name only 00055 FXString FXAPI title(const FXString& file); 00056 00057 /// Return extension part of the file name 00058 FXString FXAPI extension(const FXString& file); 00059 00060 /// Return file name less the extension 00061 FXString FXAPI stripExtension(const FXString& file); 00062 00063 /// Return the drive letter prefixing this file name (if any). 00064 FXString FXAPI drive(const FXString& file); 00065 00066 /// Perform tilde or environment variable expansion 00067 FXString FXAPI expand(const FXString& file); 00068 00069 /// Contract path based on user name and environment variable 00070 FXString FXAPI contract(const FXString& file,const FXString& user=FXString::null,const FXString& var=FXString::null); 00071 00072 /** 00073 * Simplify a file path; the path will remain relative if it was relative, 00074 * or absolute if it was absolute. Also, a trailing "/" will be preserved 00075 * as this is important in other functions. 00076 * For example, simplify("..//aaa/./bbb//../c/") becomes "../aaa/c/". 00077 */ 00078 FXString FXAPI simplify(const FXString& file); 00079 00080 /// Return absolute path from current directory and file name 00081 FXString FXAPI absolute(const FXString& file); 00082 00083 /// Return absolute path from base directory and file name 00084 FXString FXAPI absolute(const FXString& base,const FXString& file); 00085 00086 /// Return relative path of file to the current directory 00087 FXString FXAPI relative(const FXString& file); 00088 00089 /// Return relative path of file to given base directory 00090 FXString FXAPI relative(const FXString& base,const FXString& file); 00091 00092 /// Return path following local path separator conventions 00093 FXString FXAPI convert(const FXString& path); 00094 00095 /// Return path to directory above input directory name 00096 FXString FXAPI upLevel(const FXString& file); 00097 00098 /// Return true if file name is absolute 00099 bool FXAPI isAbsolute(const FXString& file); 00100 00101 /// Return true if input directory is a top-level directory 00102 bool FXAPI isTopDirectory(const FXString& file); 00103 00104 /// Return true if input path is a file share 00105 bool FXAPI isShare(const FXString& file); 00106 00107 /// Enquote filename to make safe for shell 00108 FXString FXAPI enquote(const FXString& file,bool forcequotes=false); 00109 00110 /// Dequote filename to get original again 00111 FXString FXAPI dequote(const FXString& file); 00112 00113 /** 00114 * Perform wildcard match of a filename against a wildcard pattern. 00115 * The wildcard pattern may comprise ordinary characters or special 00116 * matching characters, as given below: 00117 * 00118 * ? Any single character. 00119 * * Zero or more of any character. 00120 * [abc] Any character from the set {a,b,c}. 00121 * [^abc] Any character BUT the ones from the set {a,b,c}. 00122 * [!abc] Ditto. 00123 * [a-zA-Z] Matches single character, which must be one of a-z or A-Z. 00124 * [^a-zA-Z] Matches single character, which must be anything other than a-z or A-Z. 00125 * [!a-zA-Z] Ditto. 00126 * pat1|pat2 Match sub-pattern pat1 or pat2. 00127 * pat1,pat2 Ditto. 00128 * (pat1|pat2) Match sub-pattern pat1 or pat2; patterns may be nested. 00129 * (pat1,pat2) Ditto. 00130 * 00131 * The special characters may be escaped to treat them as ordinary characters. 00132 * Matching may be influenced by a number of flags: 00133 * 00134 * FILEMATCH_FILE_NAME No wildcard can ever match / 00135 * FILEMATCH_NOESCAPE Backslashes don't quote special chars 00136 * FILEMATCH_PERIOD Leading . is matched only explicitly 00137 * FILEMATCH_LEADING_DIR Ignore /... after a match 00138 * FILEMATCH_CASEFOLD Compare without regard to case 00139 */ 00140 bool FXAPI match(const FXString& pattern,const FXString& file,FXuint flags=(FILEMATCH_NOESCAPE|FILEMATCH_FILE_NAME)); 00141 00142 /** 00143 * Generate unique filename of the form pathnameXXX.ext, where 00144 * pathname.ext is the original input file, and XXX is a number, 00145 * possibly empty, that makes the file unique. 00146 */ 00147 FXString FXAPI unique(const FXString& file); 00148 00149 /** 00150 * Search path list for this file, return full path name for first occurrence. 00151 */ 00152 FXString FXAPI search(const FXString& pathlist,const FXString& file); 00153 00154 } 00155 00156 } 00157 00158 #endif
Copyright © 1997-2005 Jeroen van der Zijp |