1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 #ifndef _OSL_FILE_PATH_HELPER_HXX_
29 #define _OSL_FILE_PATH_HELPER_HXX_
32 #ifndef _OSL_FILE_PATH_HELPER_H_
33 #include "file_path_helper.h"
36 #include <rtl/ustring.hxx>
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 '/'
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
57 ******************************************/
59 inline void systemPathRemoveSeparator(/*inout*/ rtl::OUString
& Path
)
61 osl_systemPathRemoveSeparator(Path
.pData
);
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 '/'
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
79 ******************************************/
81 inline void systemPathEnsureSeparator(/*inout*/ rtl::OUString
& Path
)
83 osl_systemPathEnsureSeparator(&Path
.pData
);
86 /*******************************************
87 systemPathIsRelativePath
88 Returns true if the given path is a
89 relative path and so starts not with '/'
91 @param pustrPath [in] a system path
92 pustrPath must not be NULL
94 @returns sal_True if the given path
95 doesn't start with a separator
96 else sal_False will be returned
98 ******************************************/
100 inline bool systemPathIsRelativePath(const rtl::OUString
& Path
)
102 return osl_systemPathIsRelativePath(Path
.pData
);
105 /******************************************
106 systemPathIsAbsolutePath
107 Returns true if the given path is an
108 absolute path and so starts with a '/'
110 @param pustrPath [in] a system path
111 pustrPath must not be NULL
113 @returns sal_True if the given path
114 start's with a separator else
115 sal_False will be returned
117 *****************************************/
119 inline bool systemPathIsAbsolutePath(const rtl::OUString
& Path
)
121 return osl_systemPathIsAbsolutePath(Path
.pData
);
124 /******************************************
125 systemPathMakeAbsolutePath
126 Append a relative path to a base path
128 @param pustrBasePath [in] a system
129 path that will be considered as
131 pustrBasePath must not be NULL
133 @param pustrRelPath [in] a system path
134 that will be considered as
136 pustrBasePath must not be NULL
138 @param ppustrAbsolutePath [out] the
139 resulting path which is a
140 concatination of the base and
142 if base path is empty the
143 resulting absolute path is the
145 if relative path is empty the
146 resulting absolute path is the
148 if base and relative path are
149 empty the resulting absolute
151 ppustrAbsolutePath must not be
152 NULL and *ppustrAbsolutePath
153 must be 0 or point to a valid
156 *****************************************/
158 inline void systemPathMakeAbsolutePath(
159 const rtl::OUString
& BasePath
,
160 const rtl::OUString
& RelPath
,
161 rtl::OUString
& AbsolutePath
)
163 osl_systemPathMakeAbsolutePath(
164 BasePath
.pData
, RelPath
.pData
, &AbsolutePath
.pData
);
167 /*****************************************
169 Replaces the last occurrance of a path
170 separator with '\0' and returns the
171 position where the '/' was replaced
173 @param pustrPath [inout] a system
174 path, the last separator of
175 this path will be replaced by
177 if the path is the root path
178 '/' or the path is considered
179 as to have no parent, e.g.
180 '/NoParent' or 'NoParent' or
182 replacement will be made
183 pustrPath must not be NULL
185 @returns the position of the last path
186 separator that was replaced
187 or 0 if no replacement took
190 ****************************************/
192 inline sal_Int32
systemPathGetParent(/*inout*/ rtl::OUString
& Path
)
194 return osl_systemPathGetParent(Path
.pData
);
197 /*****************************************
198 systemPathGetFileOrLastDirectoryPart
199 Returns the file or the directory part
202 @param pustrPath [in] a system path,
205 @param ppustrFileOrDirPart [out] on
206 return receives the last part
207 of the given directory or the
209 if pustrPath is the root path
210 '/' an empty string will be
212 if pustrPath has a trailing
213 '/' the last part before the
214 '/' will be returned else
215 the part after the last '/'
220 ****************************************/
222 inline void systemPathGetFileNameOrLastDirectoryPart(
223 const rtl::OUString
& Path
,
224 rtl::OUString
& FileNameOrLastDirPart
)
226 osl_systemPathGetFileNameOrLastDirectoryPart(
227 Path
.pData
, &FileNameOrLastDirPart
.pData
);
231 /********************************************
232 systemPathIsHiddenFileOrDirectoryEntry
233 Returns sal_True if the last part of
234 given system path is not '.' or '..'
235 alone and starts with a '.'
237 @param pustrPath [in] a system path,
240 @returns sal_True if the last part of
241 the given system path starts
242 with '.' or sal_False the last
243 part is '.' or '..' alone or
244 doesn't start with a dot
246 *********************************************/
248 inline bool systemPathIsHiddenFileOrDirectoryEntry(
249 const rtl::OUString
& Path
)
251 return osl_systemPathIsHiddenFileOrDirectoryEntry(Path
.pData
);
255 /************************************************
256 systemPathIsLocalOrParentDirectoryEntry
257 Returns sal_True if the last part of the given
258 system path is the local directory entry '.'
259 or the parent directory entry '..'
261 @param pustrPath [in] a system path,
264 @returns sal_True if the last part of the
265 given system path is '.' or '..'
268 ************************************************/
270 inline bool systemPathIsLocalOrParentDirectoryEntry(
271 const rtl::OUString
& Path
)
273 return osl_systemPathIsLocalOrParentDirectoryEntry(Path
.pData
);
276 /************************************************
278 ***********************************************/
280 inline bool searchPath(
281 const rtl::OUString
& ustrFilePath
,
282 const rtl::OUString
& ustrSearchPathList
,
283 rtl::OUString
& ustrPathFound
)
285 return osl_searchPath(
287 ustrSearchPathList
.pData
,
288 &ustrPathFound
.pData
);
295 #endif /* #ifndef _OSL_PATH_HELPER_HXX_ */