1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _OSL_FILE_PATH_HELPER_HXX_ 25 #define _OSL_FILE_PATH_HELPER_HXX_ 26 27 28 #ifndef _OSL_FILE_PATH_HELPER_H_ 29 #include "file_path_helper.h" 30 #endif 31 32 #include <rtl/ustring.hxx> 33 34 35 namespace osl 36 { 37 38 /******************************************* 39 systemPathRemoveSeparator 40 Removes the last separator from the 41 given system path if any and if the path 42 is not the root path '/' 43 44 @param ppustrPath [inout] a system path 45 if the path is not the root path 46 and the last character is a 47 path separator it will be cut off 48 ppustrPath must not be NULL and 49 must point to a valid rtl_uString 50 51 @returns nothing 52 53 ******************************************/ 54 55 inline void systemPathRemoveSeparator(/*inout*/ rtl::OUString& Path) 56 { 57 osl_systemPathRemoveSeparator(Path.pData); 58 } 59 60 /******************************************* 61 systemPathEnsureSeparator 62 Adds a trailing path separator to the 63 given system path if not already there 64 and if the path is not the root path '/' 65 66 @param pustrPath [inout] a system path 67 if the path is not the root path 68 '/' and has no trailing separator 69 a separator will be added 70 ppustrPath must not be NULL and 71 must point to a valid rtl_uString 72 73 @returns nothing 74 75 ******************************************/ 76 77 inline void systemPathEnsureSeparator(/*inout*/ rtl::OUString& Path) 78 { 79 osl_systemPathEnsureSeparator(&Path.pData); 80 } 81 82 /******************************************* 83 systemPathIsRelativePath 84 Returns true if the given path is a 85 relative path and so starts not with '/' 86 87 @param pustrPath [in] a system path 88 pustrPath must not be NULL 89 90 @returns sal_True if the given path 91 doesn't start with a separator 92 else sal_False will be returned 93 94 ******************************************/ 95 96 inline bool systemPathIsRelativePath(const rtl::OUString& Path) 97 { 98 return osl_systemPathIsRelativePath(Path.pData); 99 } 100 101 /****************************************** 102 systemPathIsAbsolutePath 103 Returns true if the given path is an 104 absolute path and so starts with a '/' 105 106 @param pustrPath [in] a system path 107 pustrPath must not be NULL 108 109 @returns sal_True if the given path 110 start's with a separator else 111 sal_False will be returned 112 113 *****************************************/ 114 115 inline bool systemPathIsAbsolutePath(const rtl::OUString& Path) 116 { 117 return osl_systemPathIsAbsolutePath(Path.pData); 118 } 119 120 /****************************************** 121 systemPathMakeAbsolutePath 122 Append a relative path to a base path 123 124 @param pustrBasePath [in] a system 125 path that will be considered as 126 base path 127 pustrBasePath must not be NULL 128 129 @param pustrRelPath [in] a system path 130 that will be considered as 131 relative path 132 pustrBasePath must not be NULL 133 134 @param ppustrAbsolutePath [out] the 135 resulting path which is a 136 concatination of the base and 137 the relative path 138 if base path is empty the 139 resulting absolute path is the 140 relative path 141 if relative path is empty the 142 resulting absolute path is the 143 base path 144 if base and relative path are 145 empty the resulting absolute 146 path is also empty 147 ppustrAbsolutePath must not be 148 NULL and *ppustrAbsolutePath 149 must be 0 or point to a valid 150 rtl_uString 151 152 *****************************************/ 153 154 inline void systemPathMakeAbsolutePath( 155 const rtl::OUString& BasePath, 156 const rtl::OUString& RelPath, 157 rtl::OUString& AbsolutePath) 158 { 159 osl_systemPathMakeAbsolutePath( 160 BasePath.pData, RelPath.pData, &AbsolutePath.pData); 161 } 162 163 /***************************************** 164 systemPathGetParent 165 Replaces the last occurrance of a path 166 separator with '\0' and returns the 167 position where the '/' was replaced 168 169 @param pustrPath [inout] a system 170 path, the last separator of 171 this path will be replaced by 172 a '\0' 173 if the path is the root path 174 '/' or the path is considered 175 as to have no parent, e.g. 176 '/NoParent' or 'NoParent' or 177 the path is empty no 178 replacement will be made 179 pustrPath must not be NULL 180 181 @returns the position of the last path 182 separator that was replaced 183 or 0 if no replacement took 184 place 185 186 ****************************************/ 187 188 inline sal_Int32 systemPathGetParent(/*inout*/ rtl::OUString& Path) 189 { 190 return osl_systemPathGetParent(Path.pData); 191 } 192 193 /***************************************** 194 systemPathGetFileOrLastDirectoryPart 195 Returns the file or the directory part 196 of the given path 197 198 @param pustrPath [in] a system path, 199 must not be NULL 200 201 @param ppustrFileOrDirPart [out] on 202 return receives the last part 203 of the given directory or the 204 file name 205 if pustrPath is the root path 206 '/' an empty string will be 207 returned 208 if pustrPath has a trailing 209 '/' the last part before the 210 '/' will be returned else 211 the part after the last '/' 212 will be returned 213 214 @returns nothing 215 216 ****************************************/ 217 218 inline void systemPathGetFileNameOrLastDirectoryPart( 219 const rtl::OUString& Path, 220 rtl::OUString& FileNameOrLastDirPart) 221 { 222 osl_systemPathGetFileNameOrLastDirectoryPart( 223 Path.pData, &FileNameOrLastDirPart.pData); 224 } 225 226 227 /******************************************** 228 systemPathIsHiddenFileOrDirectoryEntry 229 Returns sal_True if the last part of 230 given system path is not '.' or '..' 231 alone and starts with a '.' 232 233 @param pustrPath [in] a system path, 234 must not be NULL 235 236 @returns sal_True if the last part of 237 the given system path starts 238 with '.' or sal_False the last 239 part is '.' or '..' alone or 240 doesn't start with a dot 241 242 *********************************************/ 243 244 inline bool systemPathIsHiddenFileOrDirectoryEntry( 245 const rtl::OUString& Path) 246 { 247 return osl_systemPathIsHiddenFileOrDirectoryEntry(Path.pData); 248 } 249 250 251 /************************************************ 252 systemPathIsLocalOrParentDirectoryEntry 253 Returns sal_True if the last part of the given 254 system path is the local directory entry '.' 255 or the parent directory entry '..' 256 257 @param pustrPath [in] a system path, 258 must not be NULL 259 260 @returns sal_True if the last part of the 261 given system path is '.' or '..' 262 else sal_False 263 264 ************************************************/ 265 266 inline bool systemPathIsLocalOrParentDirectoryEntry( 267 const rtl::OUString& Path) 268 { 269 return osl_systemPathIsLocalOrParentDirectoryEntry(Path.pData); 270 } 271 272 /************************************************ 273 searchPath 274 ***********************************************/ 275 276 inline bool searchPath( 277 const rtl::OUString& ustrFilePath, 278 const rtl::OUString& ustrSearchPathList, 279 rtl::OUString& ustrPathFound) 280 { 281 return osl_searchPath( 282 ustrFilePath.pData, 283 ustrSearchPathList.pData, 284 &ustrPathFound.pData); 285 } 286 287 288 } // namespace osl 289 290 291 #endif /* #ifndef _OSL_PATH_HELPER_HXX_ */ 292 293