xref: /AOO41X/main/sal/osl/unx/file_path_helper.hxx (revision 565d668c30d8a6cacc881c774c5068be5401257d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _OSL_FILE_PATH_HELPER_HXX_
25 #define _OSL_FILE_PATH_HELPER_HXX_
26 
27 
28 #ifndef _OSL_FILE_PATH_HELPER_H_
29 #include "file_path_helper.h"
30 #endif
31 
32 #include <rtl/ustring.hxx>
33 
34 
35 namespace osl
36 {
37 
38  /*******************************************
39     systemPathRemoveSeparator
40     Removes the last separator from the
41     given system path if any and if the path
42     is not the root path '/'
43 
44     @param  ppustrPath [inout] a system path
45             if the path is not the root path
46             and the last character is a
47             path separator it will be cut off
48             ppustrPath must not be NULL and
49             must point to a valid rtl_uString
50 
51     @returns nothing
52 
53   ******************************************/
54 
systemPathRemoveSeparator(rtl::OUString & Path)55  inline void systemPathRemoveSeparator(/*inout*/ rtl::OUString& Path)
56  {
57     osl_systemPathRemoveSeparator(Path.pData);
58  }
59 
60  /*******************************************
61     systemPathEnsureSeparator
62     Adds a trailing path separator to the
63     given system path if not already there
64     and if the path is not the root path '/'
65 
66     @param  pustrPath [inout] a system path
67             if the path is not the root path
68             '/' and has no trailing separator
69             a separator will be added
70             ppustrPath must not be NULL and
71             must point to a valid rtl_uString
72 
73     @returns nothing
74 
75   ******************************************/
76 
systemPathEnsureSeparator(rtl::OUString & Path)77  inline void systemPathEnsureSeparator(/*inout*/ rtl::OUString& Path)
78  {
79     osl_systemPathEnsureSeparator(&Path.pData);
80  }
81 
82  /*******************************************
83     systemPathIsRelativePath
84     Returns true if the given path is a
85     relative path and so starts not with '/'
86 
87     @param  pustrPath [in] a system path
88             pustrPath must not be NULL
89 
90     @returns sal_True if the given path
91              doesn't start with a separator
92              else sal_False will be returned
93 
94   ******************************************/
95 
systemPathIsRelativePath(const rtl::OUString & Path)96  inline bool systemPathIsRelativePath(const rtl::OUString& Path)
97  {
98     return osl_systemPathIsRelativePath(Path.pData);
99  }
100 
101  /******************************************
102     systemPathMakeAbsolutePath
103     Append a relative path to a base path
104 
105     @param  pustrBasePath [in] a system
106             path that will be considered as
107             base path
108             pustrBasePath must not be NULL
109 
110     @param  pustrRelPath [in] a system path
111             that will be considered as
112             relative path
113             pustrBasePath must not be NULL
114 
115     @param  ppustrAbsolutePath [out] the
116             resulting path which is a
117             concatination of the base and
118             the relative path
119             if base path is empty the
120             resulting absolute path is the
121             relative path
122             if relative path is empty the
123             resulting absolute path is the
124             base path
125             if base and relative path are
126             empty the resulting absolute
127             path is also empty
128             ppustrAbsolutePath must not be
129             NULL and *ppustrAbsolutePath
130             must be 0 or point to a valid
131             rtl_uString
132 
133   *****************************************/
134 
systemPathMakeAbsolutePath(const rtl::OUString & BasePath,const rtl::OUString & RelPath,rtl::OUString & AbsolutePath)135  inline void systemPathMakeAbsolutePath(
136     const rtl::OUString& BasePath,
137     const rtl::OUString& RelPath,
138     rtl::OUString&       AbsolutePath)
139  {
140     osl_systemPathMakeAbsolutePath(
141         BasePath.pData, RelPath.pData, &AbsolutePath.pData);
142  }
143 
144  /*****************************************
145     systemPathGetFileOrLastDirectoryPart
146     Returns the file or the directory part
147     of the given path
148 
149     @param pustrPath [in] a system path,
150            must not be NULL
151 
152     @param ppustrFileOrDirPart [out] on
153            return receives the last part
154            of the given directory or the
155            file name
156            if pustrPath is the root path
157            '/' an empty string will be
158            returned
159            if pustrPath has a trailing
160            '/' the last part before the
161            '/' will be returned else
162            the part after the last '/'
163            will be returned
164 
165     @returns nothing
166 
167   ****************************************/
168 
systemPathGetFileNameOrLastDirectoryPart(const rtl::OUString & Path,rtl::OUString & FileNameOrLastDirPart)169  inline void systemPathGetFileNameOrLastDirectoryPart(
170     const rtl::OUString& Path,
171     rtl::OUString&       FileNameOrLastDirPart)
172  {
173     osl_systemPathGetFileNameOrLastDirectoryPart(
174         Path.pData, &FileNameOrLastDirPart.pData);
175  }
176 
177 
178  /********************************************
179     systemPathIsHiddenFileOrDirectoryEntry
180     Returns sal_True if the last part of
181     given system path is not '.' or '..'
182     alone and starts with a '.'
183 
184     @param pustrPath [in] a system path,
185            must not be NULL
186 
187     @returns sal_True if the last part of
188              the given system path starts
189              with '.' or sal_False the last
190              part is '.' or '..' alone or
191              doesn't start with a dot
192 
193  *********************************************/
194 
systemPathIsHiddenFileOrDirectoryEntry(const rtl::OUString & Path)195  inline bool systemPathIsHiddenFileOrDirectoryEntry(
196     const rtl::OUString& Path)
197  {
198     return osl_systemPathIsHiddenFileOrDirectoryEntry(Path.pData);
199  }
200 
201 
202  /************************************************
203     systemPathIsLocalOrParentDirectoryEntry
204     Returns sal_True if the last part of the given
205     system path is the local directory entry '.'
206     or the parent directory entry '..'
207 
208     @param pustrPath [in] a system path,
209            must not be NULL
210 
211     @returns sal_True if the last part of the
212              given system path is '.' or '..'
213              else sal_False
214 
215  ************************************************/
216 
systemPathIsLocalOrParentDirectoryEntry(const rtl::OUString & Path)217  inline bool systemPathIsLocalOrParentDirectoryEntry(
218     const rtl::OUString& Path)
219  {
220     return osl_systemPathIsLocalOrParentDirectoryEntry(Path.pData);
221  }
222 
223  /************************************************
224   searchPath
225   ***********************************************/
226 
searchPath(const rtl::OUString & ustrFilePath,const rtl::OUString & ustrSearchPathList,rtl::OUString & ustrPathFound)227  inline bool searchPath(
228     const rtl::OUString& ustrFilePath,
229     const rtl::OUString& ustrSearchPathList,
230     rtl::OUString& ustrPathFound)
231  {
232     return osl_searchPath(
233         ustrFilePath.pData,
234         ustrSearchPathList.pData,
235         &ustrPathFound.pData);
236  }
237 
238 
239  } // namespace osl
240 
241 
242  #endif /* #ifndef _OSL_PATH_HELPER_HXX_ */
243 
244