diff options
author | Behnam Esfahbod <behnam@zwnj.org> | 2008-12-02 02:32:02 +0330 |
---|---|---|
committer | Behnam ZWNJ Esfahbod <behnam@zwnj.org> | 2008-12-02 02:32:02 +0330 |
commit | c0a967a01fdfa8869669ba9478a8b4d1ccc7f4d5 (patch) | |
tree | 9595080d3ac48fcbd6a1f2988f3c8259448ae7b9 | |
parent | 530802453518b251f4e20213e70169bb688bb95a (diff) |
Mark private functions
-rwxr-xr-x | fribidi.py | 62 |
1 files changed, 41 insertions, 21 deletions
@@ -8,31 +8,49 @@ import sys libfribidi = ctypes.CDLL("libfribidi.so") -def malloc_utf8_array (l): +def _malloc_utf8_array (l): + """ + Returns a pointer to allocated UTF8 (C char) array of length `l' + """ + Utf8Array = ctypes.c_char * l return Utf8Array() -def malloc_utf8_array_from_string (s): +def _malloc_utf8_array_from_string (s): + """ + Returns a pointer to allocated UTF8 (C char) array, initialized with value of `s' + """ + return ctypes.c_char_p(s) -def malloc_utc32_array (l): +def _malloc_utc32_array (l): + """ + Returns a pointer to allocated UTC32 (C int32) array of length `l' + """ + Utc32Array = ctypes.c_uint32 * l return Utc32Array() -def pyunicode_to_utc32_p (a_unicode): - print - print 'Enter pyunicode_to_utc32_p' - print +def _pyunicode_to_utc32_p (a_pyunicode): + """ + Converts Python Unicode instance to UTC32 (C int32) array + + Note: Caller should free the allocated memory of returned pointer + """ + + a_len = len(a_pyunicode) - utf8_pystr = a_unicode.encode('utf-8') + print 'a_len', a_len + + utf8_pystr = a_pyunicode.encode('utf-8') utf8_len = len(utf8_pystr) - utf8_p = malloc_utf8_array_from_string(utf8_pystr) + utf8_p = _malloc_utf8_array_from_string(utf8_pystr) print 'utf8_p.value', utf8_p.value print 'utf8_len', utf8_len - utc32_p = malloc_utc32_array(utf8_len+1) + utc32_p = _malloc_utc32_array(a_len+1) libfribidi.fribidi_utf8_to_unicode (utf8_p, utf8_len, utc32_p) print 'utc32_p [%04x, %04x, %04x, %04x]' % (utc32_p[0], utc32_p[1], utc32_p[2], utc32_p[3]) @@ -43,15 +61,20 @@ def pyunicode_to_utc32_p (a_unicode): return utc32_p -def utc32_p_to_pyunicode (a_utc32_p, a_len): - print - print 'Enter utc32_p_to_pyunicode' - print +def _utc32_p_to_pyunicode (a_utc32_p): + """ + Converts UTC32 (C int32) array to Python Unicode instance + """ print 'a_utc32_p [%04x, %04x, %04x, %04x]' % (a_utc32_p[0], a_utc32_p[1], a_utc32_p[2], a_utc32_p[3]) - utf8_p = malloc_utf8_array(6*a_len+1) - libfribidi.fribidi_unicode_to_utf8 (a_utc32_p, a_len, utf8_p) + utc32_len = ctypes.sizeof(a_utc32_p) / ctypes.sizeof(ctypes.c_uint32) - 1 + print 'utc32_len', utc32_len + + utf8_len = 6*utc32_len+1 + utf8_p = _malloc_utf8_array(utf8_len) + + libfribidi.fribidi_unicode_to_utf8 (a_utc32_p, utc32_len, utf8_p) print @@ -60,17 +83,14 @@ def utc32_p_to_pyunicode (a_utc32_p, a_len): def log2vis (input_pyunicode): - l = len(input_pyunicode) print 'input_pyunicode', input_pyunicode - print 'l', l - print - input_utc32_p = pyunicode_to_utc32_p(input_pyunicode) + input_utc32_p = _pyunicode_to_utc32_p(input_pyunicode) #print libfribidi.fribidi_log2vis() output_utc32_p = input_utc32_p - output_u = utc32_p_to_pyunicode(output_utc32_p, l) + output_u = _utc32_p_to_pyunicode(output_utc32_p) print 'output_u', output_u |