1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: file_path_helper.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _OSL_FILE_PATH_HELPER_HXX_
32 #define _OSL_FILE_PATH_HELPER_HXX_
35 #ifndef _OSL_FILE_PATH_HELPER_H_
36 #include "file_path_helper.h"
39 #include <rtl/ustring.hxx>
45 /*******************************************
46 systemPathRemoveSeparator
47 Removes the last separator from the
48 given system path if any and if the path
49 is not the root path '/'
51 @param ppustrPath [inout] a system path
52 if the path is not the root path
53 and the last character is a
54 path separator it will be cut off
55 ppustrPath must not be NULL and
56 must point to a valid rtl_uString
60 ******************************************/
62 inline void systemPathRemoveSeparator(/*inout*/ rtl::OUString
& Path
)
64 osl_systemPathRemoveSeparator(Path
.pData
);
67 /*******************************************
68 systemPathEnsureSeparator
69 Adds a trailing path separator to the
70 given system path if not already there
71 and if the path is not the root path '/'
73 @param pustrPath [inout] a system path
74 if the path is not the root path
75 '/' and has no trailing separator
76 a separator will be added
77 ppustrPath must not be NULL and
78 must point to a valid rtl_uString
82 ******************************************/
84 inline void systemPathEnsureSeparator(/*inout*/ rtl::OUString
& Path
)
86 osl_systemPathEnsureSeparator(&Path
.pData
);
89 /*******************************************
90 systemPathIsRelativePath
91 Returns true if the given path is a
92 relative path and so starts not with '/'
94 @param pustrPath [in] a system path
95 pustrPath must not be NULL
97 @returns sal_True if the given path
98 doesn't start with a separator
99 else sal_False will be returned
101 ******************************************/
103 inline bool systemPathIsRelativePath(const rtl::OUString
& Path
)
105 return osl_systemPathIsRelativePath(Path
.pData
);
108 /******************************************
109 systemPathIsAbsolutePath
110 Returns true if the given path is an
111 absolute path and so starts with a '/'
113 @param pustrPath [in] a system path
114 pustrPath must not be NULL
116 @returns sal_True if the given path
117 start's with a separator else
118 sal_False will be returned
120 *****************************************/
122 inline bool systemPathIsAbsolutePath(const rtl::OUString
& Path
)
124 return osl_systemPathIsAbsolutePath(Path
.pData
);
127 /******************************************
128 systemPathMakeAbsolutePath
129 Append a relative path to a base path
131 @param pustrBasePath [in] a system
132 path that will be considered as
134 pustrBasePath must not be NULL
136 @param pustrRelPath [in] a system path
137 that will be considered as
139 pustrBasePath must not be NULL
141 @param ppustrAbsolutePath [out] the
142 resulting path which is a
143 concatination of the base and
145 if base path is empty the
146 resulting absolute path is the
148 if relative path is empty the
149 resulting absolute path is the
151 if base and relative path are
152 empty the resulting absolute
154 ppustrAbsolutePath must not be
155 NULL and *ppustrAbsolutePath
156 must be 0 or point to a valid
159 *****************************************/
161 inline void systemPathMakeAbsolutePath(
162 const rtl::OUString
& BasePath
,
163 const rtl::OUString
& RelPath
,
164 rtl::OUString
& AbsolutePath
)
166 osl_systemPathMakeAbsolutePath(
167 BasePath
.pData
, RelPath
.pData
, &AbsolutePath
.pData
);
170 /*****************************************
172 Replaces the last occurrance of a path
173 separator with '\0' and returns the
174 position where the '/' was replaced
176 @param pustrPath [inout] a system
177 path, the last separator of
178 this path will be replaced by
180 if the path is the root path
181 '/' or the path is considered
182 as to have no parent, e.g.
183 '/NoParent' or 'NoParent' or
185 replacement will be made
186 pustrPath must not be NULL
188 @returns the position of the last path
189 separator that was replaced
190 or 0 if no replacement took
193 ****************************************/
195 inline sal_Int32
systemPathGetParent(/*inout*/ rtl::OUString
& Path
)
197 return osl_systemPathGetParent(Path
.pData
);
200 /*****************************************
201 systemPathGetFileOrLastDirectoryPart
202 Returns the file or the directory part
205 @param pustrPath [in] a system path,
208 @param ppustrFileOrDirPart [out] on
209 return receives the last part
210 of the given directory or the
212 if pustrPath is the root path
213 '/' an empty string will be
215 if pustrPath has a trailing
216 '/' the last part before the
217 '/' will be returned else
218 the part after the last '/'
223 ****************************************/
225 inline void systemPathGetFileNameOrLastDirectoryPart(
226 const rtl::OUString
& Path
,
227 rtl::OUString
& FileNameOrLastDirPart
)
229 osl_systemPathGetFileNameOrLastDirectoryPart(
230 Path
.pData
, &FileNameOrLastDirPart
.pData
);
234 /********************************************
235 systemPathIsHiddenFileOrDirectoryEntry
236 Returns sal_True if the last part of
237 given system path is not '.' or '..'
238 alone and starts with a '.'
240 @param pustrPath [in] a system path,
243 @returns sal_True if the last part of
244 the given system path starts
245 with '.' or sal_False the last
246 part is '.' or '..' alone or
247 doesn't start with a dot
249 *********************************************/
251 inline bool systemPathIsHiddenFileOrDirectoryEntry(
252 const rtl::OUString
& Path
)
254 return osl_systemPathIsHiddenFileOrDirectoryEntry(Path
.pData
);
258 /************************************************
259 systemPathIsLocalOrParentDirectoryEntry
260 Returns sal_True if the last part of the given
261 system path is the local directory entry '.'
262 or the parent directory entry '..'
264 @param pustrPath [in] a system path,
267 @returns sal_True if the last part of the
268 given system path is '.' or '..'
271 ************************************************/
273 inline bool systemPathIsLocalOrParentDirectoryEntry(
274 const rtl::OUString
& Path
)
276 return osl_systemPathIsLocalOrParentDirectoryEntry(Path
.pData
);
279 /************************************************
281 ***********************************************/
283 inline bool searchPath(
284 const rtl::OUString
& ustrFilePath
,
285 const rtl::OUString
& ustrSearchPathList
,
286 rtl::OUString
& ustrPathFound
)
288 return osl_searchPath(
290 ustrSearchPathList
.pData
,
291 &ustrPathFound
.pData
);
298 #endif /* #ifndef _OSL_PATH_HELPER_HXX_ */