1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef CORE__IO__PATH_TOOLS_H 17 #define CORE__IO__PATH_TOOLS_H 18 19 #include <base/containers/string.h> 20 #include <base/containers/string_view.h> 21 #include <core/namespace.h> 22 23 CORE_BEGIN_NAMESPACE() 24 /** IsRelative 25 * Checks if the path is "absolute". ie. rooted. starts with "/" 26 * @return true if rooted, false if not. 27 */ 28 bool IsRelative(BASE_NS::string_view path); 29 /** ParseUri 30 * Extracts protocol and path from uri. not fully compliant parsing. 31 * @return false if uri has no protocol. 32 */ 33 bool ParseUri(BASE_NS::string_view uri, BASE_NS::string_view& protocol, BASE_NS::string_view& path); 34 /** Normalize Path. 35 * Removes dot segments from "absolute" path. if the path does not start at "/", it is changed accordingly. 36 * @return Path with out dot segments, or empty if more ".." dotsegments than segments. 37 */ 38 BASE_NS::string NormalizePath(BASE_NS::string_view path); 39 /** GetCurrentDirectory 40 * Returns current working directory. 41 * @return string containing current directory 42 */ 43 BASE_NS::string GetCurrentDirectory(); 44 #if _WIN32 45 /** SplitPath. 46 * Splits "pathIn", to it's components. accepts "/C:/" and "C:/". 47 */ 48 void SplitPath(BASE_NS::string_view pathIn, BASE_NS::string_view& drive, BASE_NS::string_view& path, 49 BASE_NS::string_view& filename, BASE_NS::string_view& ext); 50 #endif 51 CORE_END_NAMESPACE() 52 #endif