plptools
Loading...
Searching...
No Matches
pathutils.h
Go to the documentation of this file.
1/*
2 * This file is part of plptools.
3 *
4 * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
5 * Copyright (C) 1999-2002 Fritz Elfert <felfert@to.com>
6 * Copyright (C) 2006-2025 Reuben Thomas <rrt@sc3d.org>
7 * Copyright (C) 2026 Jason Morley <hello@jbmorley.co.uk>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * along with this program; if not, see <https://www.gnu.org/licenses/>.
21 *
22 */
23#pragma once
24
25#include "config.h"
26
27#include <string>
28#include <vector>
29
36namespace pathutils {
37
38enum class PathFormat {
39 kPOSIX = 0,
40 kWindows = 1,
41
42#if defined(_WIN32)
44#else
45 kHost = kPOSIX,
46#endif
48};
49
50extern char path_separator(const PathFormat format);
51
57extern std::string epoc_basename(std::string path);
58
62extern char *epoc_dirname(const char *path);
63
69extern char *resolve_epoc_path(const char *path, const char *initialPath);
70
85extern std::vector<std::string> split(const std::string &path, const PathFormat format);
86
102extern std::string join(const std::vector<std::string> &components, const PathFormat format);
103
115extern bool is_absolute(const std::string &path, const PathFormat format);
116
127extern std::string appending_components(const std::string &path,
128 const std::vector<std::string> &components,
129 const PathFormat format);
130
136extern std::string resolve_path(const std::string &path, const std::string &startingPath, const PathFormat format);
137
138};
Conveniences for working with paths.
Definition: pathutils.h:36
char path_separator(const PathFormat format)
Definition: pathutils.cc:74
char * epoc_dirname(const char *path)
Compute parent directory of an EPOC directory.
Definition: pathutils.cc:91
bool is_absolute(const std::string &path, const PathFormat format)
Check if a path is absolute.
Definition: pathutils.cc:223
std::vector< std::string > split(const std::string &path, const PathFormat format)
Split a path, path, into its components, using the path separator, separator.
Definition: pathutils.cc:142
char * resolve_epoc_path(const char *path, const char *initialPath)
Returns a new absolute EPOC path, determined by resolving path relative to initialPath.
Definition: pathutils.cc:116
std::string appending_components(const std::string &path, const std::vector< std::string > &components, const PathFormat format)
Convenience wrapper for join that returns a new path resulting from appending path components,...
Definition: pathutils.cc:215
std::string resolve_path(const std::string &path, const std::string &startingPath, const PathFormat format)
Returns a path by resolving a relative or absolute path against a starting path.
Definition: pathutils.cc:262
std::string epoc_basename(std::string path)
Returns the last path component of an EPOC path.
Definition: pathutils.cc:83
std::string join(const std::vector< std::string > &components, const PathFormat format)
Return a new path by joining the path components, components, with path separator,...
Definition: pathutils.cc:179