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 systemPathMakeAbsolutePath
110 Append a relative path to a base path
112 @param pustrBasePath [in] a system
113 path that will be considered as
115 pustrBasePath must not be NULL
117 @param pustrRelPath [in] a system path
118 that will be considered as
120 pustrBasePath must not be NULL
122 @param ppustrAbsolutePath [out] the
123 resulting path which is a
124 concatination of the base and
126 if base path is empty the
127 resulting absolute path is the
129 if relative path is empty the
130 resulting absolute path is the
132 if base and relative path are
133 empty the resulting absolute
135 ppustrAbsolutePath must not be
136 NULL and *ppustrAbsolutePath
137 must be 0 or point to a valid
140 *****************************************/
142 inline void systemPathMakeAbsolutePath(
143 const rtl::OUString
& BasePath
,
144 const rtl::OUString
& RelPath
,
145 rtl::OUString
& AbsolutePath
)
147 osl_systemPathMakeAbsolutePath(
148 BasePath
.pData
, RelPath
.pData
, &AbsolutePath
.pData
);
151 /*****************************************
152 systemPathGetFileOrLastDirectoryPart
153 Returns the file or the directory part
156 @param pustrPath [in] a system path,
159 @param ppustrFileOrDirPart [out] on
160 return receives the last part
161 of the given directory or the
163 if pustrPath is the root path
164 '/' an empty string will be
166 if pustrPath has a trailing
167 '/' the last part before the
168 '/' will be returned else
169 the part after the last '/'
174 ****************************************/
176 inline void systemPathGetFileNameOrLastDirectoryPart(
177 const rtl::OUString
& Path
,
178 rtl::OUString
& FileNameOrLastDirPart
)
180 osl_systemPathGetFileNameOrLastDirectoryPart(
181 Path
.pData
, &FileNameOrLastDirPart
.pData
);
185 /********************************************
186 systemPathIsHiddenFileOrDirectoryEntry
187 Returns sal_True if the last part of
188 given system path is not '.' or '..'
189 alone and starts with a '.'
191 @param pustrPath [in] a system path,
194 @returns sal_True if the last part of
195 the given system path starts
196 with '.' or sal_False the last
197 part is '.' or '..' alone or
198 doesn't start with a dot
200 *********************************************/
202 inline bool systemPathIsHiddenFileOrDirectoryEntry(
203 const rtl::OUString
& Path
)
205 return osl_systemPathIsHiddenFileOrDirectoryEntry(Path
.pData
);
209 /************************************************
210 systemPathIsLocalOrParentDirectoryEntry
211 Returns sal_True if the last part of the given
212 system path is the local directory entry '.'
213 or the parent directory entry '..'
215 @param pustrPath [in] a system path,
218 @returns sal_True if the last part of the
219 given system path is '.' or '..'
222 ************************************************/
224 inline bool systemPathIsLocalOrParentDirectoryEntry(
225 const rtl::OUString
& Path
)
227 return osl_systemPathIsLocalOrParentDirectoryEntry(Path
.pData
);
230 /************************************************
232 ***********************************************/
234 inline bool searchPath(
235 const rtl::OUString
& ustrFilePath
,
236 const rtl::OUString
& ustrSearchPathList
,
237 rtl::OUString
& ustrPathFound
)
239 return osl_searchPath(
241 ustrSearchPathList
.pData
,
242 &ustrPathFound
.pData
);
249 #endif /* #ifndef _OSL_PATH_HELPER_HXX_ */