Skip to content

Commit

Permalink
uncompleted add -WX compile option
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwillow committed Dec 22, 2024
1 parent fbc99f1 commit 387b71e
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 15 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ project(SmartCharsetConverter)
add_definitions(-DUNICODE -D_UNICODE)

add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options(-WX)

if(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MT")
Expand Down
4 changes: 2 additions & 2 deletions src/Control/TMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void TMenu::InsertItem(int posId, int newItemid, const std::wstring &s) noexcept
menuItemInfo.cbSize = sizeof(MENUITEMINFO);
menuItemInfo.wID = newItemid;
menuItemInfo.fMask = MIIM_ID | MIIM_STRING | MIIM_SUBMENU;
menuItemInfo.cch = s.length() + 1;
menuItemInfo.cch = static_cast<UINT>(s.length() + 1);
menuItemInfo.dwTypeData = const_cast<wchar_t *>(s.c_str());
menuItemInfo.hSubMenu = hMenu;

Expand Down Expand Up @@ -72,7 +72,7 @@ void TMenu::SetItemTextByPositionOrId(bool byPosition, int posOrId, const std::w

menuItemInfo.cbSize = sizeof(MENUITEMINFO);
menuItemInfo.fMask = MIIM_STRING;
menuItemInfo.cch = ws.size();
menuItemInfo.cch = static_cast<UINT>(ws.size());
menuItemInfo.dwTypeData = const_cast<wchar_t *>(ws.data());
BOOL ok = SetMenuItemInfo(hMenu, posOrId, byPosition, &menuItemInfo);
assert(ok);
Expand Down
12 changes: 11 additions & 1 deletion src/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,17 @@ std::u16string Decode(std::string_view src, CharsetCode code) {
ucnv_setToUCallBack(conv.get(), UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &err);
DealWithUCNVError(err);

if (cap > std::numeric_limits<uint32_t>::max()) {
throw MyRuntimeError(MessageId::STRING_LENGTH_OUT_OF_LIMIT);
}

if (src.size() > std::numeric_limits<uint32_t>::max()) {
throw MyRuntimeError(MessageId::STRING_LENGTH_OUT_OF_LIMIT);
}

// 解码
int retLen = ucnv_toUChars(conv.get(), target.data(), cap, src.data(), src.size(), &err);
int retLen = ucnv_toUChars(conv.get(), target.data(), static_cast<uint32_t>(cap), src.data(),
static_cast<uint32_t>(src.size()), &err);
target.resize(retLen);
DealWithUCNVError(err);

Expand All @@ -72,6 +81,7 @@ std::u16string DecodeToLimitBytes(std::string_view src, uint64_t maxInputBytes,
output = Decode(std::string_view(src.data(), use_bytes), code);
break;
} catch (const TruncatedCharFoundError &err) {
(err);
if (use_bytes != src.size()) {
use_bytes--;
continue;
Expand Down
1 change: 1 addition & 0 deletions src/Core/Detect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ std::tuple<CharsetCode, bool> DetectByCED(const char *buf, int len) {
code = ToCharsetCode(string_to_wstring(EncodingName(encoding)));

} catch (const std::runtime_error &err) {
(err);
if (is_reliable) {
throw;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Core/Exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class TruncatedCharFoundError : UCNVError {

class ConvertError : public MyRuntimeError {
public:
ConvertError(std::string content, int position, viet::Encoding srcEncoding, viet::Encoding destEncoding) noexcept
ConvertError(std::string content, std::size_t position, viet::Encoding srcEncoding,
viet::Encoding destEncoding) noexcept
: MyRuntimeError(MessageId::VIETNAMESE_CONVERT_ERROR,
fmt::format(MessageIdToBasicString(MessageId::VIETNAMESE_CONVERT_ERROR),
to_string(srcEncoding), to_string(srcEncoding), position, content)),
Expand All @@ -96,7 +97,7 @@ class ConvertError : public MyRuntimeError {
private:
viet::Encoding srcEncoding;
viet::Encoding destEncoding;
int position;
std::size_t position;
std::string content;
};

Expand Down
2 changes: 1 addition & 1 deletion src/Core/LineBreaks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <stdexcept>

// LineBreaksÀàÐ͵½×Ö·û´®µÄÓ³Éä±í
// LineBreaks类型到字符串的映射表
const doublemap<LineBreaks, std::tstring> lineBreaksMap = {
{LineBreaks::CRLF, TEXT("CRLF")}, {LineBreaks::LF, TEXT("LF")}, {LineBreaks::CR, TEXT("CR")},
{LineBreaks::EMPTY, TEXT("")}, {LineBreaks::MIX, TEXT("N/A(Mixed)")}, {LineBreaks::UNKNOWN, TEXT("Unknown")}};
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Vietnamese.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ void CheckInit() noexcept {
assert(Initialized() && "viet module is not initialized");
}

bool CheckEncoding(const char *str, int len, Encoding encoding) noexcept {
bool CheckEncoding(const char *str, std::size_t len, Encoding encoding) noexcept {
CheckInit();
if (encoding == Encoding::VPS || encoding == Encoding::VISCII) {
const std::unordered_map<char, std::string_view> *dict = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Vietnamese.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ inline Encoding to_encoding(std::string_view sv) noexcept {
*/
void Init() noexcept;

bool CheckEncoding(const char *str, int len, Encoding encoding) noexcept;
bool CheckEncoding(const char *str, std::size_t len, Encoding encoding) noexcept;
bool CheckEncoding(const std::string &str, Encoding encoding) noexcept;

/**
Expand Down
8 changes: 4 additions & 4 deletions src/SmartCharsetConverter/CLIHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ int CLIMain(const std::vector<std::wstring> &args) noexcept {
}

} catch (const std::runtime_error &err) {
MessageBoxA(NULL, err.what(), "Error", MB_OK | MB_ICONERROR);
return -1;
MessageBoxW(NULL, utf8_to_wstring(err.what()).c_str(), L"Error", MB_OK | MB_ICONERROR);
}
});

Expand All @@ -100,7 +99,7 @@ int CLIMain(const std::vector<std::wstring> &args) noexcept {
std::vector<std::wstring> inputPathes;

int state = 0;
for (int i = 1; i < args.size(); ++i) {
for (std::size_t i = 1; i < args.size(); ++i) {
std::wstring arg = args[i];
switch (state) {
case 0:
Expand Down Expand Up @@ -193,6 +192,7 @@ int CLIMain(const std::vector<std::wstring> &args) noexcept {
try {
core.SetOutputCharset(ToCharsetCode(arg));
} catch (const std::runtime_error &err) {
(err);
ssErr << L"错误:未能识别的字符集名称:" << arg << L"\n";
ssErr << L"提示:使用--help charset可以查看支持的字符集名称。\n";
}
Expand Down Expand Up @@ -354,7 +354,7 @@ int CLIMain(const std::vector<std::wstring> &args) noexcept {
}

int success = 0, failed = 0;
int total = inputFileNames.size();
int total = static_cast<int>(inputFileNames.size());
for (int i = 0; i < total; i++) {
AddAndConvertOneFile(i + 1, total, inputFileNames[i], success, failed);
}
Expand Down
2 changes: 2 additions & 0 deletions src/SmartCharsetConverter/DialogMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ DialogMain::DialogMain(const std::vector<std::tstring> &filenames) : inputFilena

languageService = std::make_unique<LanguageService>(option);
} catch (const nlohmann::json::exception &err) {
(err);
throw;
} catch (const std::exception &err) {
(err);
throw;
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/SmartCharsetConverter/DialogMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,13 @@ class DialogMain : public CDialogImpl<DialogMain> {
const int SELECT_LANUAGE_ID_CONST = 20000;
const int SELECT_LANUAGE_ID_START = SELECT_LANUAGE_ID_CONST + 0;
int GetSelectLanguageIdEnd() noexcept {
return SELECT_LANUAGE_ID_START + languageService->GetLanguageArray().size();
return static_cast<int>(SELECT_LANUAGE_ID_START + languageService->GetLanguageArray().size());
}

int LanguageNameToCommandId(const std::string &languageName) noexcept {
return SELECT_LANUAGE_ID_START + std::distance(languageService->GetLanguagesTable().begin(),
languageService->GetLanguagesTable().find(languageName));
return static_cast<int>(SELECT_LANUAGE_ID_START +
std::distance(languageService->GetLanguagesTable().begin(),
languageService->GetLanguagesTable().find(languageName)));
}

std::string CommandIdToLanguageName(int id) noexcept {
Expand Down

0 comments on commit 387b71e

Please sign in to comment.