cvs: php4 /ext/standard basic_functions.c config.m4 php_string.h string.c /ext/standard/tests/file .cvsignore /ext/standard/tests/string 001.phpt
| From: | Stig Bakken | Date: | Fri, 15 Dec 2000 01:01:14 +0000 |
| Subject: | cvs: php4 /ext/standard basic_functions.c config.m4 php_string.h string.c /ext/standard/tests/file .cvsignore /ext/standard/tests/string 001.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-3170@lists.php.net to get a copy of this message | ||
ssb Thu Dec 14 17:01:14 2000 EDT
Added files:
/php4/ext/standard/tests/string 001.phpt
Modified files:
/php4/ext/standard basic_functions.c config.m4 php_string.h
string.c
/php4/ext/standard/tests/file .cvsignore
Log:
@Added iconv() function (using libc or libiconv) (Stig)
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.286 php4/ext/standard/basic_functions.c:1.287
--- php4/ext/standard/basic_functions.c:1.286 Wed Dec 13 14:50:10 2000
+++ php4/ext/standard/basic_functions.c Thu Dec 14 17:01:13 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: basic_functions.c,v 1.286 2000/12/13 22:50:10 zeev Exp $ */
+/* $Id: basic_functions.c,v 1.287 2000/12/15 01:01:13 ssb Exp $ */
#include "php.h"
#include "php_main.h"
@@ -183,7 +183,7 @@
PHP_FE(implode, NULL)
PHP_FE(setlocale, NULL)
PHP_FE(soundex, NULL)
- PHP_FE(levenshtein, NULL)
+ PHP_FE(levenshtein, NULL)
PHP_FE(chr, NULL)
PHP_FE(ord, NULL)
PHP_FE(parse_str, second_arg_force_ref)
@@ -194,6 +194,7 @@
PHP_NAMED_FE(printf, PHP_FN(user_printf), NULL)
PHP_FE(sscanf, third_and_rest_force_ref)
PHP_FE(fscanf, third_and_rest_force_ref)
+ PHP_FE(iconv, NULL)
PHP_FE(parse_url, NULL)
PHP_FE(urlencode, NULL)
Index: php4/ext/standard/config.m4
diff -u php4/ext/standard/config.m4:1.24 php4/ext/standard/config.m4:1.25
--- php4/ext/standard/config.m4:1.24 Wed Jul 19 09:19:40 2000
+++ php4/ext/standard/config.m4 Thu Dec 14 17:01:13 2000
@@ -1,4 +1,4 @@
-dnl $Id: config.m4,v 1.24 2000/07/19 16:19:40 rasmus Exp $ -*- sh -*-
+dnl $Id: config.m4,v 1.25 2000/12/15 01:01:13 ssb Exp $ -*- sh -*-
divert(3)dnl
@@ -162,5 +162,13 @@
fi
])
-PHP_EXTENSION(standard)
+AC_CHECK_LIB(c, iconv_open, [
+ AC_DEFINE(HAVE_ICONV, 1, [ ])
+], [
+ AC_CHECK_LIB(iconv, iconv_open, [
+ EXTRA_LIBS="$EXTRA_LIBS -liconv"
+ AC_DEFINE(HAVE_ICONV, 1, [ ])
+ ])
+])
+PHP_EXTENSION(standard)
Index: php4/ext/standard/php_string.h
diff -u php4/ext/standard/php_string.h:1.27 php4/ext/standard/php_string.h:1.28
--- php4/ext/standard/php_string.h:1.27 Wed Sep 27 08:18:00 2000
+++ php4/ext/standard/php_string.h Thu Dec 14 17:01:13 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_string.h,v 1.27 2000/09/27 15:18:00 sas Exp $ */
+/* $Id: php_string.h,v 1.28 2000/12/15 01:01:13 ssb Exp $ */
/* Synced with php 3.0 revision 1.43 1999-06-16 [ssb] */
@@ -78,6 +78,7 @@
PHP_FUNCTION(substr_count);
PHP_FUNCTION(str_pad);
PHP_FUNCTION(sscanf);
+PHP_FUNCTION(iconv);
#define strnatcmp(a, b) \
strnatcmp_ex(a, strlen(a), b, strlen(b), 0)
Index: php4/ext/standard/string.c
diff -u php4/ext/standard/string.c:1.172 php4/ext/standard/string.c:1.173
--- php4/ext/standard/string.c:1.172 Thu Dec 14 07:58:14 2000
+++ php4/ext/standard/string.c Thu Dec 14 17:01:13 2000
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: string.c,v 1.172 2000/12/14 15:58:14 sas Exp $ */
+/* $Id: string.c,v 1.173 2000/12/15 01:01:13 ssb Exp $ */
/* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
@@ -30,6 +30,9 @@
#ifdef HAVE_LOCALE_H
# include <locale.h>
#endif
+#ifdef HAVE_ICONV
+# include <iconv.h>
+#endif
#include "scanf.h"
#include "zend_API.h"
#include "zend_execute.h"
@@ -2986,6 +2989,56 @@
}
/* }}} */
+#ifdef HAVE_ICONV
+/* {{{ proto iconv(string in_charset, string out_charset, string str)
+ Returns str converted to the out_charset character set.
+*/
+PHP_FUNCTION(iconv)
+{
+ zval **in_charset, **out_charset, **in_buffer;
+ unsigned int in_size, out_size;
+ char *out_buffer, *in_p, *out_p;
+ iconv_t cd;
+ size_t result;
+ typedef unsigned int ucs4_t;
+
+ if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &in_charset, &out_charset,
&in_buffer) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_string_ex(in_charset);
+ convert_to_string_ex(out_charset);
+ convert_to_string_ex(in_buffer);
+
+ in_size = Z_STRLEN_PP(in_buffer) * sizeof(char) + 1;
+ out_size = Z_STRLEN_PP(in_buffer) * sizeof(ucs4_t) + 1;
+
+ out_buffer = (char *) emalloc(out_size);
+
+ in_p = Z_STRVAL_PP(in_buffer);
+ out_p = out_buffer;
+
+ cd = iconv_open(Z_STRVAL_PP(out_charset), Z_STRVAL_PP(in_charset));
+
+ if (cd == (iconv_t)(-1)) {
+ php_error(E_WARNING, "iconv: cannot convert from
%s' to
%s'",
+ Z_STRVAL_PP(in_charset), Z_STRVAL_PP(out_charset));
+ efree(out_buffer);
+ RETURN_FALSE;
+ }
+
+ result = iconv(cd, (const char **) &in_p, &in_size, (char **)
+ &out_p, &out_size);
+
+ if (result == (size_t)(-1)) {
+ sprintf(out_buffer, "???") ;
+ }
+
+ iconv_close(cd);
+
+ RETVAL_STRING(out_buffer, 0);
+}
+#endif
/*
* Local variables:
Index: php4/ext/standard/tests/file/.cvsignore
diff -u php4/ext/standard/tests/file/.cvsignore:1.1 php4/ext/standard/tests/file/.cvsignore:1.2
--- php4/ext/standard/tests/file/.cvsignore:1.1 Tue Nov 21 00:00:08 2000
+++ php4/ext/standard/tests/file/.cvsignore Thu Dec 14 17:01:13 2000
@@ -2,3 +2,4 @@
*.out
*.php
phpt.*
+test.file
Index: php4/ext/standard/tests/string/001.phpt
+++ php4/ext/standard/tests/string/001.phpt
--TEST--
iconv test
--FILE--
<?php
$test = "Stig Sæther Bakken";
print "$test\n";
printf("%s\n", iconv("iso-8859-1", "utf-8", $test));
?>
--EXPECT--
Stig Sæther Bakken
Stig Sæther Bakken