Re: PL_chars_to_term caracter encoding

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 03/15/2014 02:40 PM, Uwe Lesta wrote:
> Hello List,
>
> I'll try to feed SWI-Prolog (latest stabile release 6.6.2) with some Unicode chars.
>
> PL_chars_to_term() is the interesting part here. I'll try an utf8 encoding but I did not work.

No.  PL_chars_to_term() interprets its input as ISO-Latin-1.  Use 
PL_wchars_to_term().  The
current C++ wrapper makes sure all works well if you use wchar_t*.

Possibly the default should be to interpret char* using the default 
locale.  Old code
however assumed that all char* interfaces used octet encoding.  That 
code now still works,
but would break if we go for the locale.

	Cheers --- Jan


>
>
>       	PlCall("consult('d:/test.pl')");
> 	// save_term('eşek').
> 	// char str[19] = {'s','a','v','e','_','t','e','r','m','(',0x27, 0x65, 0xc5, 0x9f, 0x65,  0x6b, 0x27, ')', 0};
> 	// none('eşek').
> 	char str[14] = {'n','o','n','e','(',0x27, 0x65, 0xc5, 0x9f, 0x65,  0x6b, 0x27, ')', 0};
> 	// char str[8] = {0x27, 0x65, 0x65, 0x65, 0x65,  0x65, 0x27, 0};
> 	char * pStr = &str[0];
> 	bool b = PlCall(pStr);  // is false and should be true
> 	PlTerm t = PlCompound(pStr);	// an other test
> 	
> How can this be done?
>
> Any ideas are welcome.
>
>
> Prolog helper file test.pl
> --------------------------
> save_term_to_file(File, Term) :-
> 	setup_call_cleanup(open(File, write, Out, [encoding(utf8)]),
> 			   format(Out, '~q .~n', [Term]),
> 			   close(Out)).
>
> save_term(T):-
> 	save_term_to_file('d:\\test.out', T).
>
> 	% in Utf8 hex codes 65 c5 9f 65 6b
> none('eşek').
> --------------------------
>
> --
>
> Kind regards
>
> Uwe Lesta
>
>
> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.