Skip to content

Commit 7d00a0b

Browse files
committed
get operators from string
#improvement
1 parent c7f58b1 commit 7d00a0b

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

include/mrdocs/Metadata/Info/Function.hpp

+12
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ std::string_view
4646
getShortOperatorName(
4747
OperatorKind kind) noexcept;
4848

49+
/** Return the short name of an operator as a string.
50+
*/
51+
MRDOCS_DECL
52+
OperatorKind
53+
getOperatorKind(std::string_view name) noexcept;
54+
55+
/** Return the short name of an operator as a string.
56+
*/
57+
MRDOCS_DECL
58+
OperatorKind
59+
getOperatorKindFromSuffix(std::string_view suffix) noexcept;
60+
4961
/** Return the safe name of an operator as a string.
5062
5163
@param kind The kind of operator.

src/lib/Metadata/Info/Function.cpp

+37-1
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,47 @@ getOperatorName(
106106
// remove "operator"
107107
full.remove_prefix(8);
108108
// remove the space, if any
109-
if(full.front() == ' ')
109+
if (full.front() == ' ')
110+
{
110111
full.remove_prefix(1);
112+
}
111113
return full;
112114
}
113115

116+
OperatorKind
117+
getOperatorKind(std::string_view name) noexcept
118+
{
119+
for(auto const& item : Table)
120+
{
121+
if(name == item.name)
122+
{
123+
return item.kind;
124+
}
125+
}
126+
return OperatorKind::None;
127+
}
128+
129+
OperatorKind
130+
getOperatorKindFromSuffix(std::string_view suffix) noexcept
131+
{
132+
for(auto const& item : Table)
133+
{
134+
std::string_view itemSuffix = item.name;
135+
if (!itemSuffix.starts_with("operator"))
136+
{
137+
continue;
138+
}
139+
itemSuffix.remove_prefix(8);
140+
itemSuffix = ltrim(itemSuffix);
141+
if(suffix == itemSuffix)
142+
{
143+
return item.kind;
144+
}
145+
}
146+
return OperatorKind::None;
147+
}
148+
149+
114150
std::string_view
115151
getShortOperatorName(
116152
OperatorKind kind) noexcept

0 commit comments

Comments
 (0)