From 288f4c294ac1be89b151a3f96eb9d5cb9d91055f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sun, 31 Jul 2022 20:03:54 +0200 Subject: Make WsoFromSz and WsoCopy static member functions of wstring_owner. --- c/common.cpp | 4 ++-- c/common.h | 4 ++-- c/main.cpp | 6 +++--- c/pl.cpp | 2 +- c/pl.h | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/c/common.cpp b/c/common.cpp index 3ed2b73..2e16c59 100644 --- a/c/common.cpp +++ b/c/common.cpp @@ -43,7 +43,7 @@ wstring_owner::~wstring_owner() delete p; } -wstring_owner WsoFromSz(const char* const src, const int cp) +wstring_owner wstring_owner::from_narrow(const char* const src, const int cp) { int cbMultiByte = strlen(src)+1; int cchWideChar = MultiByteToWideChar(cp, 0, src, cbMultiByte, NULL, 0); @@ -55,7 +55,7 @@ wstring_owner WsoFromSz(const char* const src, const int cp) return dst; } -wstring_owner WsoCopy(const wchar_t* const src) +wstring_owner wstring_owner::copy(const wchar_t* const src) { const int cb = wcslen(src)+1; wchar_t* dst = new wchar_t[cb]; diff --git a/c/common.h b/c/common.h index 39fa9b8..6dfd782 100644 --- a/c/common.h +++ b/c/common.h @@ -13,6 +13,8 @@ struct wstring_owner { + static wstring_owner from_narrow(const char* buf, int cp = CP_UTF8); + static wstring_owner copy(const wchar_t* s); wstring_owner(); wstring_owner(wchar_t* s); wstring_owner& operator=(wchar_t* s); @@ -26,9 +28,7 @@ struct wstring_owner wchar_t* p = nullptr; }; -wstring_owner WsoFromSz(const char* buf, int cp = CP_UTF8); int EBMessageBox(const wchar_t* wszText, const wchar_t* wszCaption, unsigned uType); -wstring_owner WsoCopy(const wchar_t* s); struct Win32Error : public std::exception { diff --git a/c/main.cpp b/c/main.cpp index f896ef3..ebce3a6 100644 --- a/c/main.cpp +++ b/c/main.cpp @@ -56,9 +56,9 @@ void OnTerminate() noexcept try { why = PlString(t); } catch (...) {} } catch (const Win32Error& e) { what = L"a Windows error"; - try { why = WsoCopy(e.WhatW()); } catch (...) {} + try { why = wstring_owner::copy(e.WhatW()); } catch (...) {} } catch (const std::exception& e) { - try { why = WsoFromSz(e.what()); } catch (...) {} + try { why = wstring_owner::from_narrow(e.what()); } catch (...) {} } catch (...) {} wchar_t msg[256] = {0}; @@ -502,7 +502,7 @@ void WaitFor(const char* mod, const char* pred) Plx(mod,"thread_create",pred,&aThread); SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(1,0), (LPARAM)L"."); if (prefer(iTimer = SetTimer(NULL, -1, 500, proc))) { - activePred = WsoFromSz(pred); + activePred = wstring_owner::from_narrow(pred); bActive = 1; } } diff --git a/c/pl.cpp b/c/pl.cpp index e0c7971..1dc22fb 100644 --- a/c/pl.cpp +++ b/c/pl.cpp @@ -94,7 +94,7 @@ wstring_owner PlString(const term_t t, const int flags) { char* s; if (PL_get_chars(t, &s, flags)) - return {WsoFromSz(s)}; + return {wstring_owner::from_narrow(s)}; else return {}; } diff --git a/c/pl.h b/c/pl.h index 0a65c96..1c526a0 100644 --- a/c/pl.h +++ b/c/pl.h @@ -71,7 +71,7 @@ inline int PlGet(term_t t, wstring_owner* x) { Mark m; char* s; if (!PlGet(t, &s)) return 0; - *x = WsoFromSz(s); + *x = wstring_owner::from_narrow(s); return 1; /* or catch potential exception from BstrFromSz? */ } -- cgit v1.2.3