aboutsummaryrefslogtreecommitdiff
path: root/c/pl.h
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-23 18:59:37 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-23 18:59:37 +0200
commitc6cd2f1f164baac1414f2cf658566de146b10552 (patch)
treecec573bbddacd175f37d8d45e48e8cea80727420 /c/pl.h
parent2958c57db73b5af03af36598c9dffc9123a0a003 (diff)
downloadEpisodeBrowser-c6cd2f1f164baac1414f2cf658566de146b10552.tar.gz
Fix display of Unicode text.
Turns out that SWI-Prolog's wide string functions, which I started using in 03fe361, do not convert between narrow Prolog atoms and wide C strings, as I mistakenly thought. Instead, they work with wide Prolog atoms. In hindsight, it is not surprising.
Diffstat (limited to 'c/pl.h')
-rw-r--r--c/pl.h25
1 files changed, 19 insertions, 6 deletions
diff --git a/c/pl.h b/c/pl.h
index 8325c86..44b8a5e 100644
--- a/c/pl.h
+++ b/c/pl.h
@@ -1,9 +1,12 @@
#ifndef PL_H
#define PL_H
+#include <string>
#include <windows.h>
#include <SWI-Prolog.h>
+#include "common.h"
+
int PL_get_tchars(term_t t, TCHAR** pTsz, int iFlags);
struct Frame
@@ -43,14 +46,13 @@ inline int PlPut(term_t t, long long x) { return PL_put_int64(t, x); }
inline int PlPut(term_t t, atom_t x) { return PL_put_atom(t, x); }
inline int PlPut(term_t t, char* x) { return PL_put_atom_chars(t, x); }
inline int PlPut(term_t t, const char* x) { return PL_put_atom_chars(t, x); }
-inline int PlPut(term_t t, wchar_t* x) { return PL_unify_wchars(t, PL_ATOM, -1, x); }
-inline int PlPut(term_t t, const wchar_t* x) { return PL_unify_wchars(t, PL_ATOM, -1, x); }
inline int PlPut(term_t, int*) { return -1; }
inline int PlPut(term_t, long*) { return -1; }
inline int PlPut(term_t, long long*) { return -1; }
inline int PlPut(term_t, atom_t*) { return -1; }
inline int PlPut(term_t, char**) { return -1; }
-inline int PlPut(term_t, wchar_t**) { return -1; }
+inline int PlPut(term_t, std::string*) { return -1; }
+inline int PlPut(term_t, std::wstring*) { return -1; }
inline int PlGet(term_t, int) { return -1; }
inline int PlGet(term_t, long) { return -1; }
@@ -58,14 +60,25 @@ inline int PlGet(term_t, long long) { return -1; }
inline int PlGet(term_t, atom_t) { return -1; }
inline int PlGet(term_t, char*) { return -1; }
inline int PlGet(term_t, const char*) { return -1; }
-inline int PlGet(term_t, wchar_t*) { return -1; }
-inline int PlGet(term_t, const wchar_t*) { return -1; }
inline int PlGet(term_t t, int* x) { return PL_get_integer(t, x); }
inline int PlGet(term_t t, long* x) { return PL_get_long(t, x); }
inline int PlGet(term_t t, long long* x) { return PL_get_int64(t, x); }
inline int PlGet(term_t t, atom_t* x) { return PL_get_atom(t, x); }
inline int PlGet(term_t t, char** x) { return PL_get_atom_chars(t, x); }
-inline int PlGet(term_t t, wchar_t** x) { size_t len; return PL_get_wchars(t, &len, x, CVT_ATOM); }
+inline int PlGet(term_t t, std::string* x) {
+ Mark m;
+ char* sz;
+ if (!PlGet(t, &sz)) return 0;
+ *x = sz;
+ return 1;
+}
+inline int PlGet(term_t t, std::wstring* x) {
+ Mark m;
+ char* sz;
+ if (!PlGet(t, &sz)) return 0;
+ *x = BstrFromSz<wchar_t>(sz);
+ return 1; /* or catch potential exception from BstrFromSz? */
+}
/* Put in or get from a term reference an arbitrary number of values,
* returning false if any value could not be put/got. */