/* {{{ int transliterator_object_construct( zval *object, UTransliterator *utrans, UErrorCode *status ) * Initialize internals of Transliterator_object. */ int transliterator_object_construct( zval *object, UTransliterator *utrans, UErrorCode *status ) { const UChar *ustr_id; int32_t ustr_id_len; zend_string *u8str; zval tmp; Transliterator_object *to; TRANSLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; assert( to->utrans == NULL ); /* this assignment must happen before any return with failure because the * caller relies on it always being made (so it can just destroy the object * to close the transliterator) */ to->utrans = utrans; ustr_id = utrans_getUnicodeID( utrans, &ustr_id_len ); u8str = intl_convert_utf16_to_utf8(ustr_id, (int ) ustr_id_len, status ); if( !u8str ) { return FAILURE; } ZVAL_NEW_STR(&tmp, u8str); zend_update_property(Transliterator_ce_ptr, object, "id", sizeof( "id" ) - 1, &tmp ); GC_DELREF(u8str); return SUCCESS; }
static void _expect(const UTransliterator* trans, const char* cfrom, const char* cto) { /* u_uastrcpy has no capacity param for the buffer -- so just * make all buffers way too big */ enum { CAP = 256 }; UChar from[CAP]; UChar to[CAP]; UChar buf[CAP]; const UChar *ID; int32_t IDLength; const char *id; UErrorCode status = U_ZERO_ERROR; int32_t limit; UTransPosition pos; XReplaceable xrep; XReplaceable *xrepPtr = &xrep; UReplaceableCallbacks xrepVtable; u_uastrcpy(from, cfrom); u_uastrcpy(to, cto); ID = utrans_getUnicodeID(trans, &IDLength); id = aescstrdup(ID, IDLength); /* utrans_transUChars() */ u_strcpy(buf, from); limit = u_strlen(buf); utrans_transUChars(trans, buf, NULL, CAP, 0, &limit, &status); if (U_FAILURE(status)) { log_err("FAIL: utrans_transUChars() failed, error=%s\n", u_errorName(status)); return; } if (0 == u_strcmp(buf, to)) { log_verbose("Ok: utrans_transUChars(%s) x %s -> %s\n", id, cfrom, cto); } else { char actual[CAP]; u_austrcpy(actual, buf); log_err("FAIL: utrans_transUChars(%s) x %s -> %s, expected %s\n", id, cfrom, actual, cto); } /* utrans_transIncrementalUChars() */ u_strcpy(buf, from); pos.start = pos.contextStart = 0; pos.limit = pos.contextLimit = u_strlen(buf); utrans_transIncrementalUChars(trans, buf, NULL, CAP, &pos, &status); utrans_transUChars(trans, buf, NULL, CAP, pos.start, &pos.limit, &status); if (U_FAILURE(status)) { log_err("FAIL: utrans_transIncrementalUChars() failed, error=%s\n", u_errorName(status)); return; } if (0 == u_strcmp(buf, to)) { log_verbose("Ok: utrans_transIncrementalUChars(%s) x %s -> %s\n", id, cfrom, cto); } else { char actual[CAP]; u_austrcpy(actual, buf); log_err("FAIL: utrans_transIncrementalUChars(%s) x %s -> %s, expected %s\n", id, cfrom, actual, cto); } /* utrans_trans() */ InitXReplaceableCallbacks(&xrepVtable); InitXReplaceable(&xrep, cfrom); limit = u_strlen(from); utrans_trans(trans, (UReplaceable*)xrepPtr, &xrepVtable, 0, &limit, &status); if (U_FAILURE(status)) { log_err("FAIL: utrans_trans() failed, error=%s\n", u_errorName(status)); FreeXReplaceable(&xrep); return; } if (0 == u_strcmp(xrep.text, to)) { log_verbose("Ok: utrans_trans(%s) x %s -> %s\n", id, cfrom, cto); } else { char actual[CAP]; u_austrcpy(actual, xrep.text); log_err("FAIL: utrans_trans(%s) x %s -> %s, expected %s\n", id, cfrom, actual, cto); } FreeXReplaceable(&xrep); /* utrans_transIncremental() */ InitXReplaceable(&xrep, cfrom); pos.start = pos.contextStart = 0; pos.limit = pos.contextLimit = u_strlen(from); utrans_transIncremental(trans, (UReplaceable*)xrepPtr, &xrepVtable, &pos, &status); utrans_trans(trans, (UReplaceable*)xrepPtr, &xrepVtable, pos.start, &pos.limit, &status); if (U_FAILURE(status)) { log_err("FAIL: utrans_transIncremental() failed, error=%s\n", u_errorName(status)); FreeXReplaceable(&xrep); return; } if (0 == u_strcmp(xrep.text, to)) { log_verbose("Ok: utrans_transIncremental(%s) x %s -> %s\n", id, cfrom, cto); } else { char actual[CAP]; u_austrcpy(actual, xrep.text); log_err("FAIL: utrans_transIncremental(%s) x %s -> %s, expected %s\n", id, cfrom, actual, cto); } FreeXReplaceable(&xrep); }
static void TestUnicodeIDs() { UEnumeration *uenum; UTransliterator *utrans; const UChar *id, *id2; int32_t idLength, id2Length, count, count2; UErrorCode errorCode; errorCode=U_ZERO_ERROR; uenum=utrans_openIDs(&errorCode); if(U_FAILURE(errorCode)) { log_err("utrans_openIDs() failed - %s\n", u_errorName(errorCode)); return; } count=uenum_count(uenum, &errorCode); if(U_FAILURE(errorCode) || count<1) { log_err("uenum_count(transliterator IDs)=%d - %s\n", count, u_errorName(errorCode)); } count=0; for(;;) { id=uenum_unext(uenum, &idLength, &errorCode); if(U_FAILURE(errorCode)) { log_err("uenum_unext(transliterator ID %d) failed - %s\n", count, u_errorName(errorCode)); break; } if(id==NULL) { break; } if(++count>10) { /* try to actually open only a few transliterators */ continue; } utrans=utrans_openU(id, idLength, UTRANS_FORWARD, NULL, 0, NULL, &errorCode); if(U_FAILURE(errorCode)) { log_err("utrans_openU(%s) failed - %s\n", aescstrdup(id, idLength), u_errorName(errorCode)); continue; } id2=utrans_getUnicodeID(utrans, &id2Length); if(idLength!=id2Length || 0!=u_memcmp(id, id2, idLength)) { log_err("utrans_getUnicodeID(%s) does not match the original ID\n", aescstrdup(id, idLength)); } utrans_close(utrans); } uenum_reset(uenum, &errorCode); if(U_FAILURE(errorCode) || count<1) { log_err("uenum_reset(transliterator IDs) failed - %s\n", u_errorName(errorCode)); } else { count2=uenum_count(uenum, &errorCode); if(U_FAILURE(errorCode) || count<1) { log_err("2nd uenum_count(transliterator IDs)=%d - %s\n", count2, u_errorName(errorCode)); } else if(count!=count2) { log_err("uenum_unext(transliterator IDs) returned %d IDs but uenum_count() after uenum_reset() claims there are %d\n", count, count2); } } uenum_close(uenum); }
{ const UChar *ustr_id; int32_t ustr_id_len; char *str_id; int str_id_len; Transliterator_object *to; TRANSLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; assert( to->utrans == NULL ); /* this assignment must happen before any return with failure because the * caller relies on it always being made (so it can just destroy the object * to close the transliterator) */ to->utrans = utrans; ustr_id = utrans_getUnicodeID( utrans, &ustr_id_len ); intl_convert_utf16_to_utf8( &str_id, &str_id_len, ustr_id, (int ) ustr_id_len, status ); if( U_FAILURE( *status ) ) { return FAILURE; } zend_update_property_stringl(Transliterator_ce_ptr, object, "id", sizeof( "id" ) - 1, str_id, str_id_len TSRMLS_CC ); efree( str_id ); return SUCCESS; } /* }}} */ /* * Auxiliary functions needed by objects of 'Transliterator' class