Do conversion of CFStrings to/from unicode.

This commit is contained in:
unknown 2001-07-04 22:38:52 +00:00
parent d1054ef31a
commit c90acb9599
2 changed files with 255 additions and 43 deletions

File diff suppressed because it is too large Load Diff

View File

@ -250,6 +250,15 @@ def outputCheckConvertArg(self):
*p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, 0);
return 1;
}
if (PyUnicode_Check(v)) {
/* We use the CF types here, if Python was configured differently that will give an error */
CFIndex size = PyUnicode_GetSize(v);
UniChar *unichars = PyUnicode_AsUnicode(v);
if (!unichars) return 0;
*p_itself = CFStringCreateWithCharacters((CFAllocatorRef)NULL, unichars, size);
return 1;
}
""")
def outputRepr(self):
@ -377,6 +386,24 @@ def outputRepr(self):
f.docstring = lambda: "() -> (string _rv)"
CFStringRef_object.add(f)
getasunicode_body = """
int size = CFStringGetLength(_self->ob_itself)+1;
Py_UNICODE *data = malloc(size*sizeof(Py_UNICODE));
CFRange range;
range.location = 0;
range.length = size;
if( data == NULL ) return PyErr_NoMemory();
CFStringGetCharacters(_self->ob_itself, range, data);
_res = (PyObject *)PyUnicode_FromUnicode(data, size);
free(data);
return _res;
"""
f = ManualGenerator("CFStringGetUnicode", getasunicode_body);
f.docstring = lambda: "() -> (unicode _rv)"
CFStringRef_object.add(f)
# ADD add forloop here
# generate output (open the output file as late as possible)