From ebabd34385feb629b759216c1f7d85edc20bf2fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sat, 30 Jul 2022 03:14:13 +0200 Subject: Add wstring_owner, replacing std::wstring. std::basic_string is nice, but it is not very ergonomic if everything you really need is to automatically free C strings at end of scope. I suppose I could have used std::unique_ptr for this, but I suspect the ergonomics would be worse. --- c/pl.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'c/pl.cpp') diff --git a/c/pl.cpp b/c/pl.cpp index 665fe3a..1255609 100644 --- a/c/pl.cpp +++ b/c/pl.cpp @@ -90,10 +90,11 @@ int Query::NextSolution() } /* Convert Prolog term to wide characters. */ -int PlString(const term_t t, std::wstring* const pWs, const int iFlags) +wstring_owner PlString(const term_t t, const int iFlags) { char* sz; - int r = PL_get_chars(t, &sz, iFlags); - if (r) *pWs = WsFromSz(sz); - return r; + if (PL_get_chars(t, &sz, iFlags)) + return {WsoFromSz(sz)}; + else + return {}; } -- cgit v1.2.3