aboutsummaryrefslogtreecommitdiff
path: root/c/pl.cpp
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-30 03:14:13 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-30 03:14:13 +0200
commitebabd34385feb629b759216c1f7d85edc20bf2fd (patch)
tree432e68a6a58bcaf4bc1dd3c5ae438157f09f4d4a /c/pl.cpp
parentd485eb2bf7e0a82702afec9387f21bf0f89c985f (diff)
downloadEpisodeBrowser-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.cpp9
1 files changed, 5 insertions, 4 deletions
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 {};
}