-
Notifications
You must be signed in to change notification settings - Fork 17
/
SourceFileNames.cpp
44 lines (39 loc) · 1009 Bytes
/
SourceFileNames.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// Licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2023 Vinnie Falco ([email protected])
//
// Official repository: https://github.com/cppalliance/mrdocs
//
/*
This file goes in the root of a repository. We
use the C++ source_location information in order
to the full path to the repository, so that we
can strip this prefix later and generate pretty
source filenames for diagnostic output.
*/
namespace SourceFileNames {
char const*
getFileName(char const* fileName) noexcept
{
auto it = fileName;
auto it0 = fileName;
auto it1 = __FILE__;
while(*it0 && *it1)
{
if(*it0 != *it1)
break;
#ifdef _WIN32
if(*it0++ == '\\')
it = it0;
#else
if(*it0++ == '/')
it = it0;
#endif
++it1;
}
return it;
}
} // SourceFileNames