lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / sal / osl / unx / file_path_helper.hxx
blob18af761cb310b8694840e297d835d90aeaa97df6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SAL_OSL_UNX_FILE_PATH_HELPER_HXX
21 #define INCLUDED_SAL_OSL_UNX_FILE_PATH_HELPER_HXX
23 #include <sal/types.h>
24 #include <rtl/ustring.h>
25 #include <rtl/ustring.hxx>
27 /**
28 Removes the last separator from the given system path if any and if the path
29 is not the root path '/'
31 @param ppustrPath[inout] a system path if the path is not the root path
32 and the last character is a path separator it
33 will be cut off ppustrPath must not be NULL and
34 must point to a valid rtl_uString
36 @returns nothing
39 void osl_systemPathRemoveSeparator(rtl_uString* pustrPath);
41 /**
42 Adds a trailing path separator to the given system path if not already there
43 and if the path is not the root path '/'
45 @param pustrPath [inout] a system path if the path is not the root path
46 '/' and has no trailing separator a separator
47 will be added ppustrPath must not be NULL and
48 must point to a valid rtl_uString
50 @returns nothing
53 void osl_systemPathEnsureSeparator(rtl_uString** ppustrPath);
55 /**
56 Returns true if the given path is a relative path and so starts not with '/'
58 @param pustrPath [in] a system path - must not be NULL
60 @retval sal_True the given path doesn't start with a separator
61 @retval sal_False the given path starts with a separator
64 bool osl_systemPathIsRelativePath(
65 const rtl_uString* pustrPath);
67 /**
68 Append a relative path to a base path
70 @param pustrBasePath [in] a system path that will be considered as
71 base path pustrBasePath must not be NULL
73 @param pustrRelPath [in] a system path that will be considered as
74 relative path pustrBasePath must not be NULL
76 @param ppustrAbsolutePath [out] the resulting path which is a concatenation
77 of the base and the relative path if base path
78 is empty the resulting absolute path is the
79 relative path if relative path is empty the
80 resulting absolute path is the base path if base
81 and relative path are empty the resulting absolute
82 path is also empty ppustrAbsolutePath must not be
83 NULL and *ppustrAbsolutePath must be 0 or point to
84 a valid rtl_uString
86 void osl_systemPathMakeAbsolutePath(
87 const rtl_uString* pustrBasePath,
88 const rtl_uString* pustrRelPath,
89 rtl_uString** ppustrAbsolutePath);
91 /**
92 Returns the file or the directory part of the given path
94 @param pustrPath [in] a system path, must not be NULL
96 @param ppustrFileOrDirPart [out] on return receives the last part of the
97 given directory or the file name if pustrPath is the
98 root path '/' an empty string will be returned if
99 pustrPath has a trailing '/' the last part before the
100 '/' will be returned else the part after the last '/'
101 will be returned
103 @returns nothing
106 void osl_systemPathGetFileNameOrLastDirectoryPart(
107 const rtl_uString* pustrPath,
108 rtl_uString** ppustrFileNameOrLastDirPart);
111 @param pustrPath [in] a system path, must not be NULL
113 @retval sal_True the last part of the given system path starts with '.'
114 @retval sal_False the last part of the given system path is '.' or '..'
115 alone or doesn't start with a dot
118 bool osl_systemPathIsHiddenFileOrDirectoryEntry(
119 const rtl_uString* pustrPath);
121 /************************************************
122 osl_systemPathIsLocalOrParentDirectoryEntry
123 Returns sal_True if the last part of the given
124 system path is the local directory entry '.'
125 or the parent directory entry '..'
127 @param pustrPath [in] a system path,
128 must not be NULL
130 @returns sal_True if the last part of the
131 given system path is '.' or '..'
132 else sal_False
134 ************************************************/
136 bool osl_systemPathIsLocalOrParentDirectoryEntry(
137 const rtl_uString* pustrPath);
139 /************************************************
140 osl_searchPath
141 Searches for a file name or path name in all
142 directories specified by a given path list.
143 Symbolic links in the resulting path will not be
144 resolved, it's up to the caller to do this.
146 @param pustrFilePath [in] a file name or
147 directory name to search for, the name must
148 be provided as system path not as a file URL
150 @param pustrSearchPathList [in] a ':'
151 separated list of paths in which to search for
152 the file or directory name
154 @param ppustrPathFound [out] on success receives the
155 complete path of the file or directory found
156 as a system path
158 @returns sal_True if the specified file or
159 directory was found else sal_False
160 ***********************************************/
162 bool osl_searchPath(
163 const rtl_uString* pustrFilePath,
164 const rtl_uString* pustrSearchPathList,
165 rtl_uString** ppustrPathFound);
167 namespace osl
170 /*******************************************
171 systemPathRemoveSeparator
172 Removes the last separator from the
173 given system path if any and if the path
174 is not the root path '/'
176 @param ppustrPath [inout] a system path
177 if the path is not the root path
178 and the last character is a
179 path separator it will be cut off
180 ppustrPath must not be NULL and
181 must point to a valid rtl_uString
183 @returns nothing
185 ******************************************/
187 inline void systemPathRemoveSeparator(/*inout*/ OUString& Path)
189 osl_systemPathRemoveSeparator(Path.pData);
192 /*******************************************
193 systemPathEnsureSeparator
194 Adds a trailing path separator to the
195 given system path if not already there
196 and if the path is not the root path '/'
198 @param pustrPath [inout] a system path
199 if the path is not the root path
200 '/' and has no trailing separator
201 a separator will be added
202 ppustrPath must not be NULL and
203 must point to a valid rtl_uString
205 @returns nothing
207 ******************************************/
209 inline void systemPathEnsureSeparator(/*inout*/ OUString& Path)
211 osl_systemPathEnsureSeparator(&Path.pData);
214 /*******************************************
215 systemPathIsRelativePath
216 Returns true if the given path is a
217 relative path and so starts not with '/'
219 @param pustrPath [in] a system path
220 pustrPath must not be NULL
222 @returns sal_True if the given path
223 doesn't start with a separator
224 else sal_False will be returned
226 ******************************************/
228 inline bool systemPathIsRelativePath(const OUString& Path)
230 return osl_systemPathIsRelativePath(Path.pData);
233 /******************************************
234 systemPathMakeAbsolutePath
235 Append a relative path to a base path
237 @param pustrBasePath [in] a system
238 path that will be considered as
239 base path
240 pustrBasePath must not be NULL
242 @param pustrRelPath [in] a system path
243 that will be considered as
244 relative path
245 pustrBasePath must not be NULL
247 @param ppustrAbsolutePath [out] the
248 resulting path which is a
249 concatenation of the base and
250 the relative path
251 if base path is empty the
252 resulting absolute path is the
253 relative path
254 if relative path is empty the
255 resulting absolute path is the
256 base path
257 if base and relative path are
258 empty the resulting absolute
259 path is also empty
260 ppustrAbsolutePath must not be
261 NULL and *ppustrAbsolutePath
262 must be 0 or point to a valid
263 rtl_uString
265 *****************************************/
267 inline void systemPathMakeAbsolutePath(
268 const OUString& BasePath,
269 const OUString& RelPath,
270 OUString& AbsolutePath)
272 osl_systemPathMakeAbsolutePath(
273 BasePath.pData, RelPath.pData, &AbsolutePath.pData);
276 /********************************************
277 systemPathIsHiddenFileOrDirectoryEntry
278 Returns sal_True if the last part of
279 given system path is not '.' or '..'
280 alone and starts with a '.'
282 @param pustrPath [in] a system path,
283 must not be NULL
285 @returns sal_True if the last part of
286 the given system path starts
287 with '.' or sal_False the last
288 part is '.' or '..' alone or
289 doesn't start with a dot
291 *********************************************/
293 inline bool systemPathIsHiddenFileOrDirectoryEntry(
294 const OUString& Path)
296 return osl_systemPathIsHiddenFileOrDirectoryEntry(Path.pData);
299 /************************************************
300 searchPath
301 ***********************************************/
303 inline bool searchPath(
304 const OUString& ustrFilePath,
305 const OUString& ustrSearchPathList,
306 OUString& ustrPathFound)
308 return osl_searchPath(
309 ustrFilePath.pData,
310 ustrSearchPathList.pData,
311 &ustrPathFound.pData);
314 } // namespace osl
316 #endif /* #ifndef _OSL_PATH_HELPER_HXX_ */
318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */