xref: /aoo41x/main/sal/osl/os2/file_path_helper.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 #ifndef _OSL_FILE_PATH_HELPER_HXX_
29 #define _OSL_FILE_PATH_HELPER_HXX_
30 
31 
32 #ifndef _OSL_FILE_PATH_HELPER_H_
33 #include "file_path_helper.h"
34 #endif
35 
36 #include <rtl/ustring.hxx>
37 
38 
39 namespace osl
40 {
41 
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 '/'
47 
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
54 
55     @returns nothing
56 
57   ******************************************/
58 
59  inline void systemPathRemoveSeparator(/*inout*/ rtl::OUString& Path)
60  {
61  	osl_systemPathRemoveSeparator(Path.pData);
62  }
63 
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 '/'
69 
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
76 
77 	@returns nothing
78 
79   ******************************************/
80 
81  inline void systemPathEnsureSeparator(/*inout*/ rtl::OUString& Path)
82  {
83  	osl_systemPathEnsureSeparator(&Path.pData);
84  }
85 
86  /*******************************************
87     systemPathIsRelativePath
88     Returns true if the given path is a
89 	relative path and so starts not with '/'
90 
91 	@param 	pustrPath [in] a system path
92 			pustrPath must not be NULL
93 
94 	@returns sal_True if the given path
95 			 doesn't start with a separator
96 			 else sal_False will be returned
97 
98   ******************************************/
99 
100  inline bool systemPathIsRelativePath(const rtl::OUString& Path)
101  {
102 	return osl_systemPathIsRelativePath(Path.pData);
103  }
104 
105  /******************************************
106     systemPathIsAbsolutePath
107     Returns true if the given path is an
108     absolute path and so starts with a '/'
109 
110 	@param pustrPath [in] a system path
111 		   pustrPath must not be NULL
112 
113 	@returns sal_True if the given path
114 			 start's with a separator else
115 			 sal_False will be returned
116 
117   *****************************************/
118 
119  inline bool systemPathIsAbsolutePath(const rtl::OUString& Path)
120  {
121  	return osl_systemPathIsAbsolutePath(Path.pData);
122  }
123 
124  /******************************************
125     systemPathMakeAbsolutePath
126     Append a relative path to a base path
127 
128 	@param	pustrBasePath [in] a system
129 			path that will be considered as
130 			base path
131 			pustrBasePath must not be NULL
132 
133 	@param	pustrRelPath [in] a system path
134 			that will be considered as
135 			relative path
136 			pustrBasePath must not be NULL
137 
138 	@param	ppustrAbsolutePath [out] the
139 			resulting path which is a
140 			concatination of the base and
141 			the relative path
142 			if base path is empty the
143 			resulting absolute path is the
144 			relative path
145 			if relative path is empty the
146 			resulting absolute path is the
147 			base path
148 			if base and relative path are
149 			empty the resulting absolute
150 			path is also empty
151 			ppustrAbsolutePath must not be
152 			NULL and *ppustrAbsolutePath
153 			must be 0 or point to a valid
154 			rtl_uString
155 
156   *****************************************/
157 
158  inline void systemPathMakeAbsolutePath(
159  	const rtl::OUString& BasePath,
160 	const rtl::OUString& RelPath,
161 	rtl::OUString& 	     AbsolutePath)
162  {
163 	osl_systemPathMakeAbsolutePath(
164 		BasePath.pData, RelPath.pData, &AbsolutePath.pData);
165  }
166 
167  /*****************************************
168 	systemPathGetParent
169 	Replaces the last occurrance of a path
170 	separator with '\0' and returns the
171 	position where the '/' was replaced
172 
173 	@param	pustrPath [inout] a system
174 			path, the last separator of
175 			this path will be replaced by
176 			a '\0'
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
181 			the path is empty no
182 			replacement will be made
183 			pustrPath must not be NULL
184 
185 	@returns the position of the last path
186 			 separator that was replaced
187 			 or 0 if no replacement took
188 			 place
189 
190   ****************************************/
191 
192  inline sal_Int32 systemPathGetParent(/*inout*/ rtl::OUString& Path)
193  {
194 	return osl_systemPathGetParent(Path.pData);
195  }
196 
197  /*****************************************
198  	systemPathGetFileOrLastDirectoryPart
199 	Returns the file or the directory part
200 	of the given path
201 
202 	@param pustrPath [in] a system path,
203 		   must not be NULL
204 
205 	@param ppustrFileOrDirPart [out] on
206 		   return receives the last part
207 		   of the given directory or the
208 		   file name
209 		   if pustrPath is the root path
210 		   '/' an empty string will be
211 		   returned
212 		   if pustrPath has a trailing
213 		   '/' the last part before the
214 		   '/' will be returned else
215 		   the part after the last '/'
216 		   will be returned
217 
218 	@returns nothing
219 
220   ****************************************/
221 
222  inline void systemPathGetFileNameOrLastDirectoryPart(
223  	const rtl::OUString& Path,
224 	rtl::OUString& 		 FileNameOrLastDirPart)
225  {
226 	osl_systemPathGetFileNameOrLastDirectoryPart(
227 		Path.pData, &FileNameOrLastDirPart.pData);
228  }
229 
230 
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 '.'
236 
237 	@param pustrPath [in] a system path,
238 		   must not be NULL
239 
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
245 
246  *********************************************/
247 
248  inline bool systemPathIsHiddenFileOrDirectoryEntry(
249  	const rtl::OUString& Path)
250  {
251 	return osl_systemPathIsHiddenFileOrDirectoryEntry(Path.pData);
252  }
253 
254 
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 '..'
260 
261 	@param pustrPath [in] a system path,
262 		   must not be NULL
263 
264 	@returns sal_True if the last part of the
265 			 given system path is '.' or '..'
266 			 else sal_False
267 
268  ************************************************/
269 
270  inline bool systemPathIsLocalOrParentDirectoryEntry(
271  	const rtl::OUString& Path)
272  {
273 	return osl_systemPathIsLocalOrParentDirectoryEntry(Path.pData);
274  }
275 
276  /************************************************
277   searchPath
278   ***********************************************/
279 
280  inline bool searchPath(
281  	const rtl::OUString& ustrFilePath,
282 	const rtl::OUString& ustrSearchPathList,
283 	rtl::OUString& ustrPathFound)
284  {
285  	return osl_searchPath(
286 		ustrFilePath.pData,
287 		ustrSearchPathList.pData,
288 		&ustrPathFound.pData);
289  }
290 
291 
292  } // namespace osl
293 
294 
295  #endif /* #ifndef _OSL_PATH_HELPER_HXX_ */
296 
297