Skip to content

Commit

Permalink
SonarCloud の Code Smells 数を減らす為の変更
Browse files Browse the repository at this point in the history
  • Loading branch information
beru committed Sep 20, 2021
1 parent 45d1ed6 commit 4e6bb2d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
6 changes: 2 additions & 4 deletions sakura_core/charset/icu4c/CharsetDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
CharsetDetector::CharsetDetector() noexcept
: _icuin()
, _csd(nullptr)
, _ud(nullptr)
{
_icuin.InitDll();
_uchardet.InitDll();
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion sakura_core/charset/icu4c/CharsetDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CharsetDetector final
UCharsetDetector* _csd;

CUchardet _uchardet;
uchardet_t _ud;
uchardet_t _ud = nullptr;

public:
CharsetDetector() noexcept;
Expand Down
2 changes: 1 addition & 1 deletion sakura_core/extmodule/CUchardet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 6 additions & 6 deletions sakura_core/extmodule/CUchardet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
};

0 comments on commit 4e6bb2d

Please sign in to comment.