Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

C++

#C++ GloballyGlobally, your c++ seems good enought

In argvw_of_cmdline you don't have to wrap your second part in a else since you returns in the if.

You can remove a lot of things in current_exe_directory:

std::wstring current_exe_directory(void) {
 HMODULE h_module = GetModuleHandleW(nullptr);
 WCHAR path[MAX_PATH];
 memset(path, 0, sizeof(path)); 
 GetModuleFileNameW(h_module, path, MAX_PATH);
 std::wstring_view w_path(path);
 return std::wstring{ws.begin(), ws.find_last_not_of(L'\\')};
}

(note: you can improve it, but it's already kinda simplified)

You can simplify your escape_string(...) function:

std::wstring escape_string(std::wstring ws) {
 const auto esc = std::wstring{L"\\\""};
 for (size_t index = 0; (index = ws.find_first_of(esc, index)) != std::wstring::npos; index += 2) {
 ws.insert(index, 1, L'\\');
 }
 return ws;
}

Note that I didn't tested theses codes, but it should work :)

#C++ Globally, your c++ seems good enought

In argvw_of_cmdline you don't have to wrap your second part in a else since you returns in the if.

You can remove a lot of things in current_exe_directory:

std::wstring current_exe_directory(void) {
 HMODULE h_module = GetModuleHandleW(nullptr);
 WCHAR path[MAX_PATH];
 memset(path, 0, sizeof(path)); 
 GetModuleFileNameW(h_module, path, MAX_PATH);
 std::wstring_view w_path(path);
 return std::wstring{ws.begin(), ws.find_last_not_of(L'\\')};
}

(note: you can improve it, but it's already kinda simplified)

You can simplify your escape_string(...) function:

std::wstring escape_string(std::wstring ws) {
 const auto esc = std::wstring{L"\\\""};
 for (size_t index = 0; (index = ws.find_first_of(esc, index)) != std::wstring::npos; index += 2) {
 ws.insert(index, 1, L'\\');
 }
 return ws;
}

Note that I didn't tested theses codes, but it should work :)

C++

Globally, your c++ seems good enought

In argvw_of_cmdline you don't have to wrap your second part in a else since you returns in the if.

You can remove a lot of things in current_exe_directory:

std::wstring current_exe_directory(void) {
 HMODULE h_module = GetModuleHandleW(nullptr);
 WCHAR path[MAX_PATH];
 memset(path, 0, sizeof(path)); 
 GetModuleFileNameW(h_module, path, MAX_PATH);
 std::wstring_view w_path(path);
 return std::wstring{ws.begin(), ws.find_last_not_of(L'\\')};
}

(note: you can improve it, but it's already kinda simplified)

You can simplify your escape_string(...) function:

std::wstring escape_string(std::wstring ws) {
 const auto esc = std::wstring{L"\\\""};
 for (size_t index = 0; (index = ws.find_first_of(esc, index)) != std::wstring::npos; index += 2) {
 ws.insert(index, 1, L'\\');
 }
 return ws;
}

Note that I didn't tested theses codes, but it should work :)

Bounty Awarded with 150 reputation awarded by Greg Nisbet
Source Link
Calak
  • 2.4k
  • 11
  • 19

#C++ Globally, your c++ seems good enought

In argvw_of_cmdline you don't have to wrap your second part in a else since you returns in the if.

You can remove a lot of things in current_exe_directory:

std::wstring current_exe_directory(void) {
 HMODULE h_module = GetModuleHandleW(nullptr);
 WCHAR path[MAX_PATH];
 memset(path, 0, sizeof(path)); 
 GetModuleFileNameW(h_module, path, MAX_PATH);
 std::wstring_view w_path(path);
 return std::wstring{ws.begin(), ws.find_last_not_of(L'\\')};
}

(note: you can improve it, but it's already kinda simplified)

You can simplify your escape_string(...) function:

std::wstring escape_string(std::wstring ws) {
 const auto esc = std::wstring{L"\\\""};
 for (size_t index = 0; (index = ws.find_first_of(esc, index)) != std::wstring::npos; index += 2) {
 ws.insert(index, 1, L'\\');
 }
 return ws;
}

Note that I didn't tested theses codes, but it should work :)

default

AltStyle によって変換されたページ (->オリジナル) /