diff options
author | John Ankarström <john@ankarstrom.se> | 2022-08-06 16:59:56 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-08-06 16:59:56 +0200 |
commit | c92d449f7a055769f518a809487f97d8272c4e9d (patch) | |
tree | 9fd704fe7c5601c42e86724b7b7c07c2fad6b38b | |
parent | 86a0cec08f11de875d25012e5b251a91739ce06c (diff) | |
download | EpisodeBrowser-c92d449f7a055769f518a809487f97d8272c4e9d.tar.gz |
Update Hungarian notation for buffer sizes.
For string lengths EXCLUDING NUL, I use len, whereas cb and cch are
used for string lengths INCLUDING NUL.
cb = byte count = sizeof(a) = narrow string length
cch = character count = sizeof(a)/sizeof(*a) = string length
cb and cch are equivalent for narrow strings. I prefer cch.
-rw-r--r-- | c/episodelistview.cpp | 6 | ||||
-rw-r--r-- | c/wcharptr.cpp | 14 |
2 files changed, 8 insertions, 12 deletions
diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp index 3ecaab1..7cbbcca 100644 --- a/c/episodelistview.cpp +++ b/c/episodelistview.cpp @@ -265,15 +265,11 @@ int CALLBACK EpisodeListView::SortProc(const LPARAM iItem1, const LPARAM iItem2, { Mark m; WcharPtr s1, s2; - int cch, cch1, cch2; if (!Pl("episode_data","episode_title",lvi1.lParam,&s1)) return 0; if (!Pl("episode_data","episode_title",lvi2.lParam,&s2)) return 0; - cch1 = wcslen(s1); - cch2 = wcslen(s2); - cch = cch1 > cch2? cch2: cch1; - return order*_wcsnicmp(s1, s2, cch); + return order*_wcsicmp(s1, s2); } default: return 0; diff --git a/c/wcharptr.cpp b/c/wcharptr.cpp index d1332d5..f36c620 100644 --- a/c/wcharptr.cpp +++ b/c/wcharptr.cpp @@ -6,10 +6,10 @@ WcharPtr WcharPtr::FromNarrow(const char* const src, const int cp) { - int cbMultiByte = strlen(src)+1; - int cchWideChar = MultiByteToWideChar(cp, 0, src, cbMultiByte, nullptr, 0); - wchar_t* dst = new wchar_t[cchWideChar]; - if (!MultiByteToWideChar(cp, 0, src, cbMultiByte, dst, cchWideChar)) { + int cchNarrow = strlen(src)+1; + int cchWide = MultiByteToWideChar(cp, 0, src, cchNarrow, nullptr, 0); + wchar_t* dst = new wchar_t[cchWide]; + if (!MultiByteToWideChar(cp, 0, src, cchNarrow, dst, cchWide)) { delete dst; throw Win32Error(); } @@ -18,9 +18,9 @@ WcharPtr WcharPtr::FromNarrow(const char* const src, const int cp) WcharPtr WcharPtr::Copy(const wchar_t* const src) { - const int cb = wcslen(src)+1; - wchar_t* dst = new wchar_t[cb]; - memcpy(dst, src, cb*sizeof(wchar_t)); + const int cch = wcslen(src)+1; + wchar_t* dst = new wchar_t[cch]; + memcpy(dst, src, cch*sizeof(wchar_t)); return dst; } |