1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 _OSL_FILE_PATH_HELPER_HXX_
21 #define _OSL_FILE_PATH_HELPER_HXX_
24 #include "file_path_helper.h"
26 #include <rtl/ustring.hxx>
32 /*******************************************
33 systemPathRemoveSeparator
34 Removes the last separator from the
35 given system path if any and if the path
36 is not the root path '/'
38 @param ppustrPath [inout] a system path
39 if the path is not the root path
40 and the last character is a
41 path separator it will be cut off
42 ppustrPath must not be NULL and
43 must point to a valid rtl_uString
47 ******************************************/
49 inline void systemPathRemoveSeparator(/*inout*/ rtl::OUString
& Path
)
51 osl_systemPathRemoveSeparator(Path
.pData
);
54 /*******************************************
55 systemPathEnsureSeparator
56 Adds a trailing path separator to the
57 given system path if not already there
58 and if the path is not the root path '/'
60 @param pustrPath [inout] a system path
61 if the path is not the root path
62 '/' and has no trailing separator
63 a separator will be added
64 ppustrPath must not be NULL and
65 must point to a valid rtl_uString
69 ******************************************/
71 inline void systemPathEnsureSeparator(/*inout*/ rtl::OUString
& Path
)
73 osl_systemPathEnsureSeparator(&Path
.pData
);
76 /*******************************************
77 systemPathIsRelativePath
78 Returns true if the given path is a
79 relative path and so starts not with '/'
81 @param pustrPath [in] a system path
82 pustrPath must not be NULL
84 @returns sal_True if the given path
85 doesn't start with a separator
86 else sal_False will be returned
88 ******************************************/
90 inline bool systemPathIsRelativePath(const rtl::OUString
& Path
)
92 return osl_systemPathIsRelativePath(Path
.pData
);
95 /******************************************
96 systemPathMakeAbsolutePath
97 Append a relative path to a base path
99 @param pustrBasePath [in] a system
100 path that will be considered as
102 pustrBasePath must not be NULL
104 @param pustrRelPath [in] a system path
105 that will be considered as
107 pustrBasePath must not be NULL
109 @param ppustrAbsolutePath [out] the
110 resulting path which is a
111 concatination of the base and
113 if base path is empty the
114 resulting absolute path is the
116 if relative path is empty the
117 resulting absolute path is the
119 if base and relative path are
120 empty the resulting absolute
122 ppustrAbsolutePath must not be
123 NULL and *ppustrAbsolutePath
124 must be 0 or point to a valid
127 *****************************************/
129 inline void systemPathMakeAbsolutePath(
130 const rtl::OUString
& BasePath
,
131 const rtl::OUString
& RelPath
,
132 rtl::OUString
& AbsolutePath
)
134 osl_systemPathMakeAbsolutePath(
135 BasePath
.pData
, RelPath
.pData
, &AbsolutePath
.pData
);
138 /*****************************************
139 systemPathGetFileOrLastDirectoryPart
140 Returns the file or the directory part
143 @param pustrPath [in] a system path,
146 @param ppustrFileOrDirPart [out] on
147 return receives the last part
148 of the given directory or the
150 if pustrPath is the root path
151 '/' an empty string will be
153 if pustrPath has a trailing
154 '/' the last part before the
155 '/' will be returned else
156 the part after the last '/'
161 ****************************************/
163 inline void systemPathGetFileNameOrLastDirectoryPart(
164 const rtl::OUString
& Path
,
165 rtl::OUString
& FileNameOrLastDirPart
)
167 osl_systemPathGetFileNameOrLastDirectoryPart(
168 Path
.pData
, &FileNameOrLastDirPart
.pData
);
172 /********************************************
173 systemPathIsHiddenFileOrDirectoryEntry
174 Returns sal_True if the last part of
175 given system path is not '.' or '..'
176 alone and starts with a '.'
178 @param pustrPath [in] a system path,
181 @returns sal_True if the last part of
182 the given system path starts
183 with '.' or sal_False the last
184 part is '.' or '..' alone or
185 doesn't start with a dot
187 *********************************************/
189 inline bool systemPathIsHiddenFileOrDirectoryEntry(
190 const rtl::OUString
& Path
)
192 return osl_systemPathIsHiddenFileOrDirectoryEntry(Path
.pData
);
196 /************************************************
197 systemPathIsLocalOrParentDirectoryEntry
198 Returns sal_True if the last part of the given
199 system path is the local directory entry '.'
200 or the parent directory entry '..'
202 @param pustrPath [in] a system path,
205 @returns sal_True if the last part of the
206 given system path is '.' or '..'
209 ************************************************/
211 inline bool systemPathIsLocalOrParentDirectoryEntry(
212 const rtl::OUString
& Path
)
214 return osl_systemPathIsLocalOrParentDirectoryEntry(Path
.pData
);
217 /************************************************
219 ***********************************************/
221 inline bool searchPath(
222 const rtl::OUString
& ustrFilePath
,
223 const rtl::OUString
& ustrSearchPathList
,
224 rtl::OUString
& ustrPathFound
)
226 return osl_searchPath(
228 ustrSearchPathList
.pData
,
229 &ustrPathFound
.pData
);
236 #endif /* #ifndef _OSL_PATH_HELPER_HXX_ */
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */