Skip to content

Commit 2e64221

Browse files
committed
javadoc mapping traits
#feat
1 parent e2474cd commit 2e64221

File tree

191 files changed

+3225
-4481
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+3225
-4481
lines changed

include/mrdocs/Metadata/Javadoc.hpp

Lines changed: 783 additions & 12 deletions
Large diffs are not rendered by default.

include/mrdocs/Support/Algorithm.hpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ contains(Range const& range, El const& el)
3232
std::ranges::end(range), el) != std::ranges::end(range);
3333
}
3434

35-
// A second overload where the range is an initializer list
36-
3735
/** Determine if a range contains a specific element.
3836
@param range The range to search.
3937
@param el The element to search for.
@@ -49,6 +47,29 @@ contains(std::initializer_list<T> const& range, U const& el)
4947
std::ranges::end(range), el) != std::ranges::end(range);
5048
}
5149

50+
/** Determine if an element is equal to any of the elements in the specified range.
51+
52+
@param el The element to search for.
53+
@param range The range to search.
54+
@return True if the element is found, false otherwise.
55+
*/
56+
template <class El, std::ranges::range Range>
57+
requires std::equality_comparable_with<std::ranges::range_value_t<Range>, El>
58+
bool
59+
is_one_of(El const& el, Range const& range)
60+
{
61+
return contains(range, el);
62+
}
63+
64+
/// @copydoc is_one_of(El const&, Range const&)
65+
template <class U, class T>
66+
requires std::equality_comparable_with<U, T>
67+
bool
68+
is_one_of(U const& el, std::initializer_list<T> const& range)
69+
{
70+
return contains(range, el);
71+
}
72+
5273
/** Determine if a range contains any of the specified elements.
5374
@param range The range to search.
5475
@param els The elements to search for.

include/mrdocs/Support/Concepts.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ concept polymorphic_storage_for = requires(T const& t)
3838
{ t.operator->() } -> std::convertible_to<Base const*>;
3939
};
4040

41+
/** Determine if a type is dereferenceable
42+
43+
This concept checks if a type can be dereferenced
44+
to a value it represents and converted to a boolean
45+
value that represents if the object is in a valid state.
46+
47+
Examples of such types are std::optional, std::unique_ptr,
48+
std::shared_ptr, Polymorphic, pointers, etc.
49+
*/
4150
template <class T>
4251
concept dereferenceable = requires(T const& t)
4352
{

include/mrdocs/Support/String.hpp

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,58 +17,72 @@
1717
#include <string>
1818
#include <string_view>
1919

20-
namespace clang {
21-
namespace mrdocs {
20+
namespace clang::mrdocs {
21+
22+
/** Return the substring without leading specified characters.
23+
*/
24+
constexpr
25+
std::string_view
26+
ltrim(
27+
std::string_view const s,
28+
std::string_view const chars) noexcept
29+
{
30+
return s.substr(std::min(s.find_first_not_of(chars), s.size()));
31+
}
2232

2333
/** Return the substring without leading horizontal whitespace.
2434
*/
2535
constexpr
2636
std::string_view
27-
ltrim(std::string_view s) noexcept
37+
ltrim(
38+
std::string_view const s) noexcept
2839
{
29-
auto it = s.begin();
30-
for (;; ++it)
40+
return ltrim(s, " \t\n\v\f\r");
41+
}
42+
43+
/** Return the substring without trailing specified characters.
44+
*/
45+
constexpr
46+
std::string_view
47+
rtrim(
48+
std::string_view const s,
49+
std::string_view const chars) noexcept
50+
{
51+
auto const pos = s.find_last_not_of(chars);
52+
if (pos == std::string_view::npos)
3153
{
32-
if (it == s.end())
33-
return {};
34-
if (! std::isspace(*it))
35-
break;
54+
return s.substr(0, 0);
3655
}
37-
return s.substr(it - s.begin());
56+
return s.substr(0, pos + 1);
3857
}
3958

4059
/** Return the substring without trailing horizontal whitespace.
4160
*/
4261
constexpr
4362
std::string_view
44-
rtrim(std::string_view s) noexcept
63+
rtrim(std::string_view const s) noexcept
4564
{
46-
auto it = s.end() - 1;
47-
while(it > s.begin() && std::isspace(*it))
48-
{
49-
--it;
50-
}
51-
return s.substr(0, it - s.begin() + 1);
65+
return rtrim(s, " \t\n\v\f\r");
5266
}
5367

5468
/** Return the substring without leading and trailing horizontal whitespace.
5569
*/
5670
constexpr
5771
std::string_view
58-
trim(std::string_view s) noexcept
72+
trim(std::string_view const s) noexcept
5973
{
60-
auto left = s.begin();
61-
for (;; ++left)
62-
{
63-
if (left == s.end())
64-
return {};
65-
if (!isspace(*left))
66-
break;
67-
}
68-
auto right = s.end() - 1;
69-
while(right > left && std::isspace(*right))
70-
--right;
71-
return std::string_view(&*left, right - left + 1);
74+
return rtrim(ltrim(s));
75+
}
76+
77+
/** Return the substring without leading and trailing specified characters.
78+
*/
79+
constexpr
80+
std::string_view
81+
trim(
82+
std::string_view const s,
83+
std::string_view const chars) noexcept
84+
{
85+
return rtrim(ltrim(s, chars), chars);
7286
}
7387

7488
/** Return the substring without leading and trailing horizontal whitespace.
@@ -86,8 +100,24 @@ isWhitespace(std::string_view s) noexcept
86100
return s.find_first_not_of(" \t\n\v\f\r") == std::string::npos;
87101
}
88102

103+
/** Determine if a string starts with one of the specified characters
104+
*/
105+
constexpr
106+
bool
107+
startsWithOneOf(std::string_view s, std::string_view chars) noexcept
108+
{
109+
return !s.empty() && chars.find(s.front()) != std::string_view::npos;
110+
}
111+
112+
/** Determine if a string ends with one of the specified characters
113+
*/
114+
constexpr
115+
bool
116+
endsWithOneOf(std::string_view s, std::string_view chars) noexcept
117+
{
118+
return !s.empty() && chars.find(s.back()) != std::string_view::npos;
119+
}
89120

90-
} // mrdocs
91-
} // clang
121+
} // clang::mrdocs
92122

93123
#endif
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[{{upper admonish}}]
2+
{{#each children}}{{> javadoc/any-text }}{{/each}}
3+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[,cpp]
2+
----
3+
{{#each children}}{{> javadoc/any-text verbatim=true }}
4+
{{/each}}
5+
----
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{#each .}}{{>javadoc/any-block .}}{{/each}}
2+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
=== {{string}}
3+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{#each children}}{{> javadoc/any-text }}{{/each}}
2+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{{#each items}}* {{> javadoc/block }}
2+
{{/each}}
3+

0 commit comments

Comments
 (0)