Skip to content

Commit 66aedd6

Browse files
committed
feat: add Path APIs
1 parent 7a218f4 commit 66aedd6

File tree

3 files changed

+68
-5
lines changed

3 files changed

+68
-5
lines changed

include/mrdox/Support/Path.hpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
3+
// See https://llvm.org/LICENSE.txt for license information.
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
//
6+
// Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com)
7+
//
8+
// Official repository: https://github.com/cppalliance/mrdox
9+
//
10+
11+
#ifndef MRDOX_SUPPORT_PATH_HPP
12+
#define MRDOX_SUPPORT_PATH_HPP
13+
14+
#include <mrdox/Platform.hpp>
15+
#include <string>
16+
#include <string_view>
17+
18+
namespace clang {
19+
namespace mrdox {
20+
21+
/** Return a full path from a possibly relative path.
22+
*/
23+
std::string
24+
makeFullPath(
25+
std::string_view pathName,
26+
std::string_view workingDir);
27+
28+
} // mrdox
29+
} // clang
30+
31+
#endif

source/Support/Path.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,40 @@
1010
//
1111

1212
#include "Path.hpp"
13+
#include <llvm/Support/FileSystem.h>
14+
#include <llvm/Support/Path.h>
1315

1416
namespace clang {
1517
namespace mrdox {
1618

19+
//------------------------------------------------
20+
21+
std::string
22+
makeFullPath(
23+
std::string_view pathName,
24+
std::string_view workingDir)
25+
{
26+
namespace path = llvm::sys::path;
27+
28+
llvm::SmallString<0> result;
29+
30+
if(! path::is_absolute(pathName))
31+
{
32+
result = workingDir;
33+
path::append(result, path::Style::posix, pathName);
34+
path::remove_dots(result, true, path::Style::posix);
35+
return std::string(result);
36+
}
37+
38+
result = pathName;
39+
path::remove_dots(result, true);
40+
convert_to_slash(result);
41+
return std::string(result);
42+
}
43+
44+
45+
//------------------------------------------------
46+
1747
llvm::StringRef
1848
convert_to_slash(
1949
llvm::SmallVectorImpl<char> &path,

source/Support/Path.hpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
namespace clang {
2020
namespace mrdox {
2121

22-
/// Replaces backslashes with slashes if Windows in place.
23-
///
24-
/// @param path A path that is transformed to native format.
25-
/// On Unix, this function is a no-op because backslashes
26-
/// are valid path chracters.
22+
/** Replaces backslashes with slashes if Windows in place.
23+
24+
@param path A path that is transformed to native format.
25+
26+
On Unix, this function is a no-op because backslashes
27+
are valid path chracters.
28+
*/
2729
llvm::StringRef
2830
convert_to_slash(
2931
llvm::SmallVectorImpl<char> &path,

0 commit comments

Comments
 (0)