mirror of
https://github.com/transmission/transmission
synced 2025-03-04 18:48:06 +00:00
Fix clang-tidy issue in iconv
2nd argument helper (#4520)
Since operators were intentionally implicit and we don't want to add more `NOLINT` comments than necessary, rework the approach to deduce the argument type instead and cast to it.
This commit is contained in:
parent
eb27220662
commit
105d23c09e
1 changed files with 11 additions and 20 deletions
|
@ -19,6 +19,7 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
#include <tuple>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -307,28 +308,17 @@ namespace
|
||||||
namespace tr_strvUtf8Clean_impl
|
namespace tr_strvUtf8Clean_impl
|
||||||
{
|
{
|
||||||
|
|
||||||
class SecondIconvArg
|
template<std::size_t N, typename F>
|
||||||
|
struct ArgTypeImpl;
|
||||||
|
|
||||||
|
template<std::size_t N, typename R, typename... ArgTs>
|
||||||
|
struct ArgTypeImpl<N, R (*)(ArgTs...)> : std::tuple_element<1, std::tuple<ArgTs...>>
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
explicit SecondIconvArg(char const* arg)
|
|
||||||
: arg_(arg)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
operator char**() &&
|
|
||||||
{
|
|
||||||
return const_cast<char**>(&arg_);
|
|
||||||
}
|
|
||||||
|
|
||||||
operator char const**() &&
|
|
||||||
{
|
|
||||||
return &arg_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
char const* arg_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<std::size_t N, typename F>
|
||||||
|
using ArgType = typename ArgTypeImpl<N, F>::type;
|
||||||
|
|
||||||
bool validateUtf8(std::string_view sv, char const** good_end)
|
bool validateUtf8(std::string_view sv, char const** good_end)
|
||||||
{
|
{
|
||||||
auto const* begin = std::data(sv);
|
auto const* begin = std::data(sv);
|
||||||
|
@ -381,10 +371,11 @@ std::string to_utf8(std::string_view sv)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto const* inbuf = std::data(sv);
|
||||||
size_t inbytesleft = std::size(sv);
|
size_t inbytesleft = std::size(sv);
|
||||||
char* out = std::data(buf);
|
char* out = std::data(buf);
|
||||||
size_t outbytesleft = std::size(buf);
|
size_t outbytesleft = std::size(buf);
|
||||||
auto const rv = iconv(cd, SecondIconvArg(std::data(sv)), &inbytesleft, &out, &outbytesleft);
|
auto const rv = iconv(cd, const_cast<ArgType<1, decltype(&iconv)>>(&inbuf), &inbytesleft, &out, &outbytesleft);
|
||||||
iconv_close(cd);
|
iconv_close(cd);
|
||||||
if (rv != size_t(-1))
|
if (rv != size_t(-1))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue