andrei          Tue Jun 13 23:46:04 2006 UTC

  Added files:                 
    /php-src/ext/unicode        php_transform.h transform.c 

  Modified files:              
    /php-src/ext/unicode        config.m4 config.w32 unicode.c 
  Log:
  transliterate()
  
  
http://cvs.php.net/viewcvs.cgi/php-src/ext/unicode/config.m4?r1=1.9&r2=1.10&diff_format=u
Index: php-src/ext/unicode/config.m4
diff -u php-src/ext/unicode/config.m4:1.9 php-src/ext/unicode/config.m4:1.10
--- php-src/ext/unicode/config.m4:1.9   Fri May  5 20:56:21 2006
+++ php-src/ext/unicode/config.m4       Tue Jun 13 23:46:04 2006
@@ -1,7 +1,7 @@
 dnl
-dnl $Id: config.m4,v 1.9 2006/05/05 20:56:21 andrei Exp $
+dnl $Id: config.m4,v 1.10 2006/06/13 23:46:04 andrei Exp $
 dnl
 
 PHP_SUBST(UNICODE_SHARED_LIBADD)
 AC_DEFINE(HAVE_UNICODE, 1, [ ])
-PHP_NEW_EXTENSION(unicode, unicode.c locale.c unicode_iterators.c collator.c 
property.c constants.c, $ext_shared)
+PHP_NEW_EXTENSION(unicode, unicode.c locale.c unicode_iterators.c collator.c 
property.c constants.c transform.c, $ext_shared)
http://cvs.php.net/viewcvs.cgi/php-src/ext/unicode/config.w32?r1=1.10&r2=1.11&diff_format=u
Index: php-src/ext/unicode/config.w32
diff -u php-src/ext/unicode/config.w32:1.10 php-src/ext/unicode/config.w32:1.11
--- php-src/ext/unicode/config.w32:1.10 Mon May  8 21:06:34 2006
+++ php-src/ext/unicode/config.w32      Tue Jun 13 23:46:04 2006
@@ -1,5 +1,5 @@
-// $Id: config.w32,v 1.10 2006/05/08 21:06:34 edink Exp $
+// $Id: config.w32,v 1.11 2006/06/13 23:46:04 andrei Exp $
 // vim:ft=javascript
 
-EXTENSION("unicode", "unicode.c unicode_iterators.c collator.c locale.c 
property.c constants.c", false);
+EXTENSION("unicode", "unicode.c unicode_iterators.c collator.c locale.c 
property.c constants.c transform.c", false);
 AC_DEFINE('HAVE_UNICODE', 1, 'ICU API extension');
http://cvs.php.net/viewcvs.cgi/php-src/ext/unicode/unicode.c?r1=1.34&r2=1.35&diff_format=u
Index: php-src/ext/unicode/unicode.c
diff -u php-src/ext/unicode/unicode.c:1.34 php-src/ext/unicode/unicode.c:1.35
--- php-src/ext/unicode/unicode.c:1.34  Tue May  9 18:21:27 2006
+++ php-src/ext/unicode/unicode.c       Tue Jun 13 23:46:04 2006
@@ -15,11 +15,12 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: unicode.c,v 1.34 2006/05/09 18:21:27 andrei Exp $ */ 
+/* $Id: unicode.c,v 1.35 2006/06/13 23:46:04 andrei Exp $ */ 
 
 #include "php_unicode.h"
 #include "zend_unicode.h"
 #include "php_property.h"
+#include "php_transform.h"
 
 void php_register_unicode_iterators(TSRMLS_D);
 
@@ -298,6 +299,10 @@
        PHP_FE(char_enum_names, NULL)
        PHP_FE(char_enum_types, NULL)
 
+       /* text transformation functions */
+
+       PHP_FE(transliterate, NULL)
+
        { NULL, NULL, NULL }
 };
 /* }}} */

http://cvs.php.net/viewcvs.cgi/php-src/ext/unicode/php_transform.h?view=markup&rev=1.1
Index: php-src/ext/unicode/php_transform.h
+++ php-src/ext/unicode/php_transform.h
/*
   +----------------------------------------------------------------------+
   | PHP Version 6                                                        |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
   | available through the world-wide-web at the following url:           |
   | http://www.php.net/license/3_01.txt                                  |
   | If you did not receive a copy of the PHP license and are unable to   |
   | obtain it through the world-wide-web, please send a note to          |
   | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Authors: Andrei Zmievski <[EMAIL PROTECTED]>                            |
   +----------------------------------------------------------------------+
*/

/* $Id: php_transform.h,v 1.1 2006/06/13 23:46:04 andrei Exp $ */ 

#ifndef PHP_TRANSFORM_H
#define PHP_TRANSFORM_H

PHP_FUNCTION(transliterate);

#endif /* PHP_TRANSFORM_H */


/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * End:
 * vim600: noet sw=4 ts=4 fdm=marker
 * vim<600: noet sw=4 ts=4
 */

http://cvs.php.net/viewcvs.cgi/php-src/ext/unicode/transform.c?view=markup&rev=1.1
Index: php-src/ext/unicode/transform.c
+++ php-src/ext/unicode/transform.c
/*
   +----------------------------------------------------------------------+
   | PHP Version 6                                                        |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
   | available through the world-wide-web at the following url:           |
   | http://www.php.net/license/3_01.txt                                  |
   | If you did not receive a copy of the PHP license and are unable to   |
   | obtain it through the world-wide-web, please send a note to          |
   | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Authors: Andrei Zmievski <[EMAIL PROTECTED]>                            |
   +----------------------------------------------------------------------+
 */

/* $Id: transform.c,v 1.1 2006/06/13 23:46:04 andrei Exp $ */ 

#include "php_unicode.h"

PHP_FUNCTION(transliterate)
{
        UChar      *str, *from, *to, *variant = NULL;
        int                     str_len, from_len, to_len, variant_len = 0;
        UChar           id[256];
        int                     id_len;
        UChar      *result = NULL;
        int                     result_len = 0;
        UTransliterator *trans = NULL;
        UErrorCode      status = U_ZERO_ERROR;
        int32_t         capacity, start, limit;

        /*
        {

                char *str;
                int32_t str_len;
                UEnumeration *ids;

                ids = utrans_openIDs(&status);
                printf("%d\n", uenum_count(ids, &status));
                str = (char*)uenum_next(ids, &str_len, &status);
                while (str) {
                        printf("id: %s\n", str);
                        str = (char*)uenum_next(ids, &str_len, &status);
                }
                uenum_close(ids);
        }

        return;
        */

        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "uuu|u", &str,
                                                          &str_len, &from, 
&from_len, &to, &to_len,
                                                          &variant, 
&variant_len) == FAILURE) {
                return;
        }

        if (variant) {
                id_len = u_snprintf(id, sizeof(id)-1, "%S-%S/%S", from, to, 
variant);
        } else {
                id_len = u_snprintf(id, sizeof(id)-1, "%S-%S", from, to);
        }

        if (id_len < 0) {
                php_error_docref("", E_WARNING, "Transliterator ID too long");
                return;
        }

        id[id_len] = 0;

        trans = utrans_openU(id, id_len, UTRANS_FORWARD, NULL, 0, NULL, 
&status);
        if (U_FAILURE(status)) {
                php_error_docref("", E_WARNING, "Failed to create 
transliterator");
                return;
        }

        result = eustrndup(str, str_len);
        result_len = limit = str_len;
        capacity = str_len + 1;

        while (1) {
                utrans_transUChars(trans, result, &result_len, capacity, 0, 
&limit, &status);
                if (status == U_BUFFER_OVERFLOW_ERROR) {
                        result = eurealloc(result, result_len + 1);
                        memcpy(result, str, UBYTES(str_len));
                        capacity = result_len + 1;
                        result_len = limit = str_len;
                        status = U_ZERO_ERROR;
                        utrans_transUChars(trans, result, &result_len, 
capacity, 0, &limit, &status);
                } else {
                        if (status == U_STRING_NOT_TERMINATED_WARNING) {
                                result = eurealloc(result, result_len + 1);
                        }
                        break;
                }
        }

        result[result_len] = 0;
        utrans_close(trans);

        RETURN_UNICODEL(result, result_len, 0);
}

/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * End:
 * vim600: noet sw=4 ts=4 fdm=marker
 * vim<600: noet sw=4 ts=4
 */

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to