1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _OSL_FILE_PATH_HELPER_HXX_ 29 #define _OSL_FILE_PATH_HELPER_HXX_ 30 31 32 #ifndef _OSL_FILE_PATH_HELPER_H_ 33 #include "file_path_helper.h" 34 #endif 35 36 #include <rtl/ustring.hxx> 37 38 39 namespace osl 40 { 41 42 /******************************************* 43 systemPathRemoveSeparator 44 Removes the last separator from the 45 given system path if any and if the path 46 is not the root path '/' 47 48 @param ppustrPath [inout] a system path 49 if the path is not the root path 50 and the last character is a 51 path separator it will be cut off 52 ppustrPath must not be NULL and 53 must point to a valid rtl_uString 54 55 @returns nothing 56 57 ******************************************/ 58 59 inline void systemPathRemoveSeparator(/*inout*/ rtl::OUString& Path) 60 { 61 osl_systemPathRemoveSeparator(Path.pData); 62 } 63 64 /******************************************* 65 systemPathEnsureSeparator 66 Adds a trailing path separator to the 67 given system path if not already there 68 and if the path is not the root path '/' 69 70 @param pustrPath [inout] a system path 71 if the path is not the root path 72 '/' and has no trailing separator 73 a separator will be added 74 ppustrPath must not be NULL and 75 must point to a valid rtl_uString 76 77 @returns nothing 78 79 ******************************************/ 80 81 inline void systemPathEnsureSeparator(/*inout*/ rtl::OUString& Path) 82 { 83 osl_systemPathEnsureSeparator(&Path.pData); 84 } 85 86 /******************************************* 87 systemPathIsRelativePath 88 Returns true if the given path is a 89 relative path and so starts not with '/' 90 91 @param pustrPath [in] a system path 92 pustrPath must not be NULL 93 94 @returns sal_True if the given path 95 doesn't start with a separator 96 else sal_False will be returned 97 98 ******************************************/ 99 100 inline bool systemPathIsRelativePath(const rtl::OUString& Path) 101 { 102 return osl_systemPathIsRelativePath(Path.pData); 103 } 104 105 /****************************************** 106 systemPathMakeAbsolutePath 107 Append a relative path to a base path 108 109 @param pustrBasePath [in] a system 110 path that will be considered as 111 base path 112 pustrBasePath must not be NULL 113 114 @param pustrRelPath [in] a system path 115 that will be considered as 116 relative path 117 pustrBasePath must not be NULL 118 119 @param ppustrAbsolutePath [out] the 120 resulting path which is a 121 concatination of the base and 122 the relative path 123 if base path is empty the 124 resulting absolute path is the 125 relative path 126 if relative path is empty the 127 resulting absolute path is the 128 base path 129 if base and relative path are 130 empty the resulting absolute 131 path is also empty 132 ppustrAbsolutePath must not be 133 NULL and *ppustrAbsolutePath 134 must be 0 or point to a valid 135 rtl_uString 136 137 *****************************************/ 138 139 inline void systemPathMakeAbsolutePath( 140 const rtl::OUString& BasePath, 141 const rtl::OUString& RelPath, 142 rtl::OUString& AbsolutePath) 143 { 144 osl_systemPathMakeAbsolutePath( 145 BasePath.pData, RelPath.pData, &AbsolutePath.pData); 146 } 147 148 /***************************************** 149 systemPathGetFileOrLastDirectoryPart 150 Returns the file or the directory part 151 of the given path 152 153 @param pustrPath [in] a system path, 154 must not be NULL 155 156 @param ppustrFileOrDirPart [out] on 157 return receives the last part 158 of the given directory or the 159 file name 160 if pustrPath is the root path 161 '/' an empty string will be 162 returned 163 if pustrPath has a trailing 164 '/' the last part before the 165 '/' will be returned else 166 the part after the last '/' 167 will be returned 168 169 @returns nothing 170 171 ****************************************/ 172 173 inline void systemPathGetFileNameOrLastDirectoryPart( 174 const rtl::OUString& Path, 175 rtl::OUString& FileNameOrLastDirPart) 176 { 177 osl_systemPathGetFileNameOrLastDirectoryPart( 178 Path.pData, &FileNameOrLastDirPart.pData); 179 } 180 181 182 /******************************************** 183 systemPathIsHiddenFileOrDirectoryEntry 184 Returns sal_True if the last part of 185 given system path is not '.' or '..' 186 alone and starts with a '.' 187 188 @param pustrPath [in] a system path, 189 must not be NULL 190 191 @returns sal_True if the last part of 192 the given system path starts 193 with '.' or sal_False the last 194 part is '.' or '..' alone or 195 doesn't start with a dot 196 197 *********************************************/ 198 199 inline bool systemPathIsHiddenFileOrDirectoryEntry( 200 const rtl::OUString& Path) 201 { 202 return osl_systemPathIsHiddenFileOrDirectoryEntry(Path.pData); 203 } 204 205 206 /************************************************ 207 systemPathIsLocalOrParentDirectoryEntry 208 Returns sal_True if the last part of the given 209 system path is the local directory entry '.' 210 or the parent directory entry '..' 211 212 @param pustrPath [in] a system path, 213 must not be NULL 214 215 @returns sal_True if the last part of the 216 given system path is '.' or '..' 217 else sal_False 218 219 ************************************************/ 220 221 inline bool systemPathIsLocalOrParentDirectoryEntry( 222 const rtl::OUString& Path) 223 { 224 return osl_systemPathIsLocalOrParentDirectoryEntry(Path.pData); 225 } 226 227 /************************************************ 228 searchPath 229 ***********************************************/ 230 231 inline bool searchPath( 232 const rtl::OUString& ustrFilePath, 233 const rtl::OUString& ustrSearchPathList, 234 rtl::OUString& ustrPathFound) 235 { 236 return osl_searchPath( 237 ustrFilePath.pData, 238 ustrSearchPathList.pData, 239 &ustrPathFound.pData); 240 } 241 242 243 } // namespace osl 244 245 246 #endif /* #ifndef _OSL_PATH_HELPER_HXX_ */ 247 248