From 4e6bb2d5a104b61cd0b0505e20ceecb447519d4e Mon Sep 17 00:00:00 2001 From: katsuhisa yuasa Date: Tue, 21 Sep 2021 00:57:39 +0900 Subject: [PATCH] =?UTF-8?q?SonarCloud=20=E3=81=AE=20Code=20Smells=20?= =?UTF-8?q?=E6=95=B0=E3=82=92=E6=B8=9B=E3=82=89=E3=81=99=E7=82=BA=E3=81=AE?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sakura_core/charset/icu4c/CharsetDetector.cpp | 6 ++---- sakura_core/charset/icu4c/CharsetDetector.h | 2 +- sakura_core/extmodule/CUchardet.cpp | 2 +- sakura_core/extmodule/CUchardet.h | 12 ++++++------ 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/sakura_core/charset/icu4c/CharsetDetector.cpp b/sakura_core/charset/icu4c/CharsetDetector.cpp index 50bb01bad9..cc13b813ff 100644 --- a/sakura_core/charset/icu4c/CharsetDetector.cpp +++ b/sakura_core/charset/icu4c/CharsetDetector.cpp @@ -28,7 +28,6 @@ CharsetDetector::CharsetDetector() noexcept : _icuin() , _csd(nullptr) - , _ud(nullptr) { _icuin.InitDll(); _uchardet.InitDll(); @@ -97,14 +96,13 @@ ECodeType CharsetDetector::Detect(const std::string_view& bytes) if (!_ud) { return CODE_ERROR; } - int ret = _uchardet.uchardet_handle_data(_ud, bytes.data(), bytes.length()); - if (ret != 0) { + _uchardet.uchardet_reset(_ud); + if (_uchardet.uchardet_handle_data(_ud, bytes.data(), bytes.length()) != 0) { return CODE_ERROR; } _uchardet.uchardet_data_end(_ud); std::string_view name = _uchardet.uchardet_get_charset(_ud); auto code = name2code(name); - _uchardet.uchardet_reset(_ud); return code; } return CODE_ERROR; diff --git a/sakura_core/charset/icu4c/CharsetDetector.h b/sakura_core/charset/icu4c/CharsetDetector.h index 1f36ff7d47..4e8171a162 100644 --- a/sakura_core/charset/icu4c/CharsetDetector.h +++ b/sakura_core/charset/icu4c/CharsetDetector.h @@ -40,7 +40,7 @@ class CharsetDetector final UCharsetDetector* _csd; CUchardet _uchardet; - uchardet_t _ud; + uchardet_t _ud = nullptr; public: CharsetDetector() noexcept; diff --git a/sakura_core/extmodule/CUchardet.cpp b/sakura_core/extmodule/CUchardet.cpp index 5bcac38612..149b8ccb20 100644 --- a/sakura_core/extmodule/CUchardet.cpp +++ b/sakura_core/extmodule/CUchardet.cpp @@ -51,7 +51,7 @@ bool CUchardet::InitDllImp() { &_uchardet_data_end, "uchardet_data_end" }, { &_uchardet_reset, "uchardet_reset" }, { &_uchardet_get_charset, "uchardet_get_charset" }, - { NULL, 0 } + { nullptr, 0 } }; return RegisterEntries(table); } diff --git a/sakura_core/extmodule/CUchardet.h b/sakura_core/extmodule/CUchardet.h index 7ffb0661d1..c73c1e972e 100644 --- a/sakura_core/extmodule/CUchardet.h +++ b/sakura_core/extmodule/CUchardet.h @@ -48,11 +48,11 @@ class CUchardet final : public CDllImp bool InitDllImp() override; public: - uchardet_t uchardet_new(void) { return _uchardet_new(); } - void uchardet_delete(uchardet_t ud) { _uchardet_delete(ud); } - int uchardet_handle_data(uchardet_t ud, const char * data, size_t len) { return _uchardet_handle_data(ud, data, len); } - void uchardet_data_end(uchardet_t ud) { _uchardet_data_end(ud); } - void uchardet_reset(uchardet_t ud) { _uchardet_reset(ud); } - const char * uchardet_get_charset(uchardet_t ud) { return _uchardet_get_charset(ud); } + uchardet_t uchardet_new(void) const { return _uchardet_new(); } + void uchardet_delete(uchardet_t ud) const { _uchardet_delete(ud); } + int uchardet_handle_data(uchardet_t ud, const char * data, size_t len) const { return _uchardet_handle_data(ud, data, len); } + void uchardet_data_end(uchardet_t ud) const { _uchardet_data_end(ud); } + void uchardet_reset(uchardet_t ud) const { _uchardet_reset(ud); } + const char * uchardet_get_charset(uchardet_t ud) const { return _uchardet_get_charset(ud); } };