improve utf-8

This commit is contained in:
Vitor Santos Costa 2012-12-07 08:10:21 +00:00
parent 556937195d
commit b98b09e7de
2 changed files with 12 additions and 27 deletions

View File

@ -34,7 +34,7 @@ ex(create) :-
LAST_NAME CHAR(20), LAST_NAME CHAR(20),
AGE INT, AGE INT,
SEX CHAR(1), SEX CHAR(1),
INCOME FLOAT )', INCOME FLOAT ) DEFAULT charset=utf8',
:= $cursor:execute($sql), := $cursor:execute($sql),
close. close.
@ -102,5 +102,5 @@ except:-
customer('João', 'Matos', 40, 'M', 2000). customer('João', 'Matos', 40, 'M', 2000).
customer('Maria', 'Söderling', 20, 'F', 3000). customer('Maria', 'Söderling', 20, 'F', 3000).
%customer('毛', '泽东', 44, 'M', 500). customer('毛', '泽东', 44, 'M', 500).
%customer('রবীন্দ্রনাথ', 'ঠাকুর', 30, 'M', 8000). customer('রবীন্দ্রনাথ', 'ঠাকুর', 30, 'M', 8000).

View File

@ -588,29 +588,23 @@ term_to_python(term_t t)
case PL_VARIABLE: case PL_VARIABLE:
return NULL; return NULL;
case PL_ATOM: case PL_ATOM:
case PL_STRING:
{ {
char *s; char *s;
atom_t at; atom_t at;
if (!PL_get_atom_chars(t, &s)) { if (PL_get_atom(t, &at)) {
wchar_t *w; if (at == ATOM_true) return Py_True;
size_t len; if (at == ATOM_false) return Py_False;
if (!PL_get_atom(t, &at))
return NULL;
if (!(w = PL_atom_wchars(at, &len)))
return NULL;
return PyUnicode_FromWideChar(w, len );
} }
if (!PL_get_atom(t, &at)) { if (!PL_get_chars(t, &s, REP_UTF8|CVT_ATOM|CVT_STRING|BUF_DISCARDABLE) ) {
return NULL; return NULL;
} }
if (at == ATOM_true) return Py_True; if (proper_ascii_string(s)) {
if (at == ATOM_false) return Py_False;
if (proper_ascii_string(s))
return PyString_FromStringAndSize(s, strlen(s) ); return PyString_FromStringAndSize(s, strlen(s) );
else { } else {
PyObject *pobj = PyUnicode_DecodeLatin1(s, strlen(s), NULL); PyObject *pobj = PyUnicode_DecodeUTF8(s, strlen(s), NULL);
//fprintf(stderr, "%s\n", s);
return pobj; return pobj;
} }
} }
@ -621,15 +615,6 @@ term_to_python(term_t t)
return NULL; return NULL;
return PyInt_FromLong(j); return PyInt_FromLong(j);
} }
case PL_STRING:
{
char *s;
size_t len;
if (!PL_get_string_chars(t, &s, &len))
return NULL;
return PyByteArray_FromStringAndSize(s, len);
}
case PL_FLOAT: case PL_FLOAT:
{ {
double fl; double fl;