diff options
author | John Ankarström <john@ankarstrom.se> | 2022-07-30 03:14:13 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-07-30 03:14:13 +0200 |
commit | ebabd34385feb629b759216c1f7d85edc20bf2fd (patch) | |
tree | 432e68a6a58bcaf4bc1dd3c5ae438157f09f4d4a /c/pl.cpp | |
parent | d485eb2bf7e0a82702afec9387f21bf0f89c985f (diff) | |
download | EpisodeBrowser-ebabd34385feb629b759216c1f7d85edc20bf2fd.tar.gz |
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.
Diffstat (limited to 'c/pl.cpp')
-rw-r--r-- | c/pl.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -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 {}; } |