fix: use new way to manage iconv token.
- use new way to manage iconv token, instead of std::unique_ptr which cause template error (no viable sizeof) in pycodec. - fix the wrong name in pycodec. - remove useless code.
This commit is contained in:
@ -397,14 +397,6 @@ namespace yycc::carton::pycodec {
|
||||
|
||||
#pragma region Char -> UTF8
|
||||
|
||||
// CharToUtf8::CharToUtf8(const EncodingName& name) :
|
||||
// #if defined(YYCC_PYCODEC_WIN32_BACKEND)
|
||||
// code_page(fetch)
|
||||
// #else
|
||||
// inner(fetch_iconv_name())
|
||||
// #endif
|
||||
// {}
|
||||
|
||||
CharToUtf8::CharToUtf8(const EncodingName& name) : inner(std::nullopt) {
|
||||
#if defined(YYCC_PYCODEC_WIN32_BACKEND)
|
||||
auto rv = fetch_code_page(name);
|
||||
@ -436,7 +428,7 @@ namespace yycc::carton::pycodec {
|
||||
if (rv.has_value()) inner = rv.value();
|
||||
#else
|
||||
auto rv = fetch_iconv_name(name);
|
||||
if (rv.has_value()) inner = YYCC_PYCODEC_BACKEND_NS::CharToUtf8(rv.value());
|
||||
if (rv.has_value()) inner = YYCC_PYCODEC_BACKEND_NS::Utf8ToChar(rv.value());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -71,11 +71,11 @@ namespace yycc::encoding::iconv {
|
||||
that_iconv_close(this->inner);
|
||||
}
|
||||
}
|
||||
PrivToken(PrivToken&& rhs) : inner(rhs.inner) {
|
||||
PrivToken(PrivToken&& rhs) noexcept : inner(rhs.inner) {
|
||||
// Reset rhs inner
|
||||
rhs.inner = INVALID_ICONV_TOKEN;
|
||||
}
|
||||
PrivToken& operator=(PrivToken&& rhs) {
|
||||
PrivToken& operator=(PrivToken&& rhs) noexcept {
|
||||
// Free self first
|
||||
if (this->inner != INVALID_ICONV_TOKEN) {
|
||||
that_iconv_close(this->inner);
|
||||
@ -99,16 +99,32 @@ namespace yycc::encoding::iconv {
|
||||
|
||||
#pragma region Token
|
||||
|
||||
Token::Token(const CodeName& from_code, const CodeName& to_code) : inner(std::make_unique<PrivToken>(from_code, to_code)) {}
|
||||
Token::Token(const CodeName& from_code, const CodeName& to_code) : inner(nullptr) {
|
||||
this->inner = new PrivToken(from_code, to_code);
|
||||
}
|
||||
|
||||
Token::~Token() {}
|
||||
Token::~Token() {
|
||||
if (this->inner != nullptr) {
|
||||
delete this->inner;
|
||||
}
|
||||
}
|
||||
|
||||
Token::Token(Token&& rhs) noexcept : inner(rhs.inner) {
|
||||
rhs.inner = nullptr;
|
||||
}
|
||||
|
||||
Token& Token::operator=(Token&& rhs) noexcept {
|
||||
this->inner = rhs.inner;
|
||||
rhs.inner = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Token::is_valid() const {
|
||||
return this->inner->is_valid();
|
||||
}
|
||||
|
||||
PrivToken* Token::get_inner() const {
|
||||
return this->inner.get();
|
||||
return this->inner;
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <expected>
|
||||
#include <memory>
|
||||
|
||||
namespace yycc::encoding::iconv {
|
||||
|
||||
@ -25,14 +24,15 @@ namespace yycc::encoding::iconv {
|
||||
public:
|
||||
Token(const CodeName& from_code, const CodeName& to_code);
|
||||
~Token();
|
||||
Token(Token&& rhs) noexcept;
|
||||
Token& operator=(Token&& rhs) noexcept;
|
||||
YYCC_DELETE_COPY(Token)
|
||||
YYCC_DEFAULT_MOVE(Token)
|
||||
|
||||
bool is_valid() const;
|
||||
PrivToken* get_inner() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<PrivToken> inner;
|
||||
PrivToken* inner;
|
||||
};
|
||||
|
||||
/// @brief The possible error occurs in this module.
|
||||
|
Reference in New Issue
Block a user