24
24
#include < libp2p/multi/multibase_codec/codecs/base58.hpp>
25
25
#include < libp2p/multi/uvarint.hpp>
26
26
27
+ // TODO: CLANG-TIDY TEST
28
+
27
29
// TODO(turuslan): qtils, https://github.com/qdrvm/kagome/issues/1813
28
30
namespace qtils {
29
31
inline std::string_view byte2str (const libp2p::BytesIn &s) {
30
- // NOLINT (cppcoreguidelines-pro-type-reinterpret-cast)
32
+ // NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast)
31
33
return {reinterpret_cast <const char *>(s.data ()), s.size ()};
32
34
}
33
35
} // namespace qtils
34
36
35
37
// https://github.com/multiformats/rust-multiaddr/blob/3c7e813c3b1fdd4187a9ca9ff67e10af0e79231d/src/protocol.rs#L613-L622
36
38
inline void percentEncode (std::string &out, std::string_view str) {
37
- constexpr uint32_t mask[4 ]{0xffffffff , 0xd000802d , 0x00000000 , 0xa8000001 };
38
- for (auto &c : str) {
39
- if ((mask[c / 32 ] & (1 << (c % 32 ))) != 0 ) {
39
+ constexpr std::array<uint32_t , 4 > mask{
40
+ 0xffffffff ,
41
+ 0xd000802d ,
42
+ 0x00000000 ,
43
+ 0xa8000001 ,
44
+ };
45
+ for (const auto &c : str) {
46
+ if (static_cast <unsigned char >(c) > 0x7f
47
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index)
48
+ or (mask[c / 32 ] & (1 << (c % 32 ))) != 0 ) {
40
49
fmt::format_to (std::back_inserter (out), " %{:02X}" , c);
41
50
} else {
42
51
out += c;
@@ -63,12 +72,12 @@ inline std::string percentDecode(std::string_view str) {
63
72
if (str[0 ] == ' %' and str.size () >= 3 ) {
64
73
auto x1 = f (str[1 ]), x2 = f (str[2 ]);
65
74
if (x1 and x2) {
66
- out += ( *x1 << 4 ) | *x2;
75
+ out. push_back (( *x1 << 4 ) | *x2) ;
67
76
str.remove_prefix (3 );
68
77
continue ;
69
78
}
70
79
}
71
- out += str[0 ];
80
+ out. push_back ( str[0 ]) ;
72
81
str.remove_prefix (1 );
73
82
}
74
83
return out;
@@ -228,9 +237,10 @@ namespace libp2p::multi::converters {
228
237
case Protocol::Code::DNS_ADDR: {
229
238
OUTCOME_TRY (data, read_uvar ());
230
239
auto name = qtils::byte2str (data);
231
- auto i = std::find_if_not (name.begin (), name.end (), [](auto c) {
232
- return std::isalnum (c) || c == ' -' || c == ' .' ;
233
- });
240
+ const auto *i =
241
+ std::find_if_not (name.begin (), name.end (), [](auto c) {
242
+ return std::isalnum (c) || c == ' -' || c == ' .' ;
243
+ });
234
244
if (i != name.end ()) {
235
245
return ConversionError::INVALID_ADDRESS;
236
246
}
0 commit comments