diff options
author | John Ankarström <john@ankarstrom.se> | 2022-07-31 19:56:53 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-07-31 19:58:54 +0200 |
commit | d9e1caa37e53c7dbc42b1fc652efc23a40c47c42 (patch) | |
tree | d2a1608a3c88fef98af9a356a116af3551ea5680 /c/common.cpp | |
parent | d9bafcecfd60f38f98bca8a1705f6007b39e18a2 (diff) | |
download | EpisodeBrowser-d9e1caa37e53c7dbc42b1fc652efc23a40c47c42.tar.gz |
Limit use of Hungarian notation.
I don't hate Hungarian notation. It has some very nice qualities. But
it also adds a lot of typing.
That said, not using it feels a bit... unsafe. I might go back on this
decision. We'll see.
Diffstat (limited to 'c/common.cpp')
-rw-r--r-- | c/common.cpp | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/c/common.cpp b/c/common.cpp index 7ce1372..3ed2b73 100644 --- a/c/common.cpp +++ b/c/common.cpp @@ -6,22 +6,22 @@ wstring_owner::wstring_owner() {} -wstring_owner::wstring_owner(wchar_t* const wsz) : p(wsz) {} +wstring_owner::wstring_owner(wchar_t* const s) : p(s) {} -wstring_owner& wstring_owner::operator=(wchar_t* const wsz) +wstring_owner& wstring_owner::operator=(wchar_t* const s) { - if (p != wsz) { + if (p != s) { delete p; - p = wsz; + p = s; } return *this; } -wstring_owner::wstring_owner(wstring_owner&& wso) noexcept : p(std::exchange(wso.p, nullptr)) {} +wstring_owner::wstring_owner(wstring_owner&& other) noexcept : p(std::exchange(other.p, nullptr)) {} -wstring_owner& wstring_owner::operator=(wstring_owner&& wso) noexcept +wstring_owner& wstring_owner::operator=(wstring_owner&& other) noexcept { - std::swap(p, wso.p); + std::swap(p, other.p); return *this; } @@ -43,16 +43,16 @@ wstring_owner::~wstring_owner() delete p; } -wstring_owner WsoFromSz(const char* const sz, const int iCp) +wstring_owner WsoFromSz(const char* const src, const int cp) { - int cbMultiByte = strlen(sz)+1; - int cchWideChar = MultiByteToWideChar(iCp, 0, sz, cbMultiByte, NULL, 0); - wchar_t* wsz = new wchar_t[cchWideChar]; - if (!MultiByteToWideChar(iCp, 0, sz, cbMultiByte, wsz, cchWideChar)) { - delete wsz; + int cbMultiByte = strlen(src)+1; + int cchWideChar = MultiByteToWideChar(cp, 0, src, cbMultiByte, NULL, 0); + wchar_t* dst = new wchar_t[cchWideChar]; + if (!MultiByteToWideChar(cp, 0, src, cbMultiByte, dst, cchWideChar)) { + delete dst; throw Win32Error(); } - return wsz; + return dst; } wstring_owner WsoCopy(const wchar_t* const src) @@ -65,8 +65,8 @@ wstring_owner WsoCopy(const wchar_t* const src) /* Win32Error: Exception for Windows API errors. */ -Win32Error::Win32Error() : dwErr(GetLastError()) {} -Win32Error::Win32Error(const DWORD dwErr) : dwErr(dwErr) {} +Win32Error::Win32Error() : code(GetLastError()) {} +Win32Error::Win32Error(const DWORD code) : code(code) {} Win32Error::~Win32Error() { @@ -82,7 +82,7 @@ const char* Win32Error::what() const noexcept FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, - dwErr, + code, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (char*)&m_szMsg, 0, NULL); @@ -95,7 +95,7 @@ const wchar_t* Win32Error::WhatW() const noexcept FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, - dwErr, + code, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (wchar_t*)&m_wszMsg, 0, NULL); @@ -104,9 +104,9 @@ const wchar_t* Win32Error::WhatW() const noexcept /* Library: Wrapper for loading and freeing dynamically linked libraries. */ -Library::Library(const wchar_t* const wszLibrary) +Library::Library(const wchar_t* const lib) { - m_hModule = LoadLibrary(wszLibrary); + m_hModule = LoadLibrary(lib); if (!m_hModule) throw Win32Error(); } |