summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWez Furlong <wez@php.net>2001-07-04 10:10:30 +0000
committerWez Furlong <wez@php.net>2001-07-04 10:10:30 +0000
commitf1364ebf3ead89f145af573e3b90f3503898b0ad (patch)
treed33144965c977b7fa15233997cab3b84ff339a5e
parent649d14ae7966496a57d3a91bc8e93b1865bd565e (diff)
downloadphp-git-f1364ebf3ead89f145af573e3b90f3503898b0ad.tar.gz
(PHP nl_langinfo) Added function when provided by OS
(PHP htmlentities, htmlspecialchars) Uses nl_langinfo to determine charset @- Added nl_langinfo() (when OS provides it) that returns locale information. (Wez Furlong) # There are a lot of constants used by nl_langinfo; should we do something # along the lines of what we do for syslog?
-rw-r--r--configure.in2
-rw-r--r--ext/standard/basic_functions.c9
-rw-r--r--ext/standard/html.c74
-rw-r--r--ext/standard/php_string.h4
-rw-r--r--ext/standard/string.c119
5 files changed, 176 insertions, 32 deletions
diff --git a/configure.in b/configure.in
index c6dc97d41b..b7ae5f6af9 100644
--- a/configure.in
+++ b/configure.in
@@ -290,6 +290,7 @@ crypt.h \
fcntl.h \
grp.h \
ieeefp.h \
+langinfo.h \
limits.h \
locale.h \
netinet/in.h \
@@ -388,6 +389,7 @@ memcpy \
memmove \
mkstemp \
mmap \
+nl_langinfo \
putenv \
random \
rand_r \
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index 131d949e9a..7f15e80852 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -193,6 +193,11 @@ function_entry basic_functions[] = {
PHP_FE(implode, NULL)
PHP_FE(setlocale, NULL)
PHP_FE(localeconv, NULL)
+#if HAVE_NL_LANGINFO
+ PHP_FE(nl_langinfo, NULL)
+#else
+ PHP_FALIAS(nl_langinfo, warn_not_available, NULL)
+#endif
PHP_FE(soundex, NULL)
PHP_FE(levenshtein, NULL)
PHP_FE(chr, NULL)
@@ -759,7 +764,9 @@ PHP_MINIT_FUNCTION(basic)
#if defined(HAVE_LOCALECONV) && defined(ZTS)
PHP_MINIT(localeconv)(INIT_FUNC_ARGS_PASSTHRU);
#endif
-
+#if defined(HAVE_NL_LANGINFO)
+ PHP_MINIT(nl_langinfo)(INIT_FUNC_ARGS_PASSTHRU);
+#endif
#if HAVE_CRYPT
PHP_MINIT(crypt)(INIT_FUNC_ARGS_PASSTHRU);
#endif
diff --git a/ext/standard/html.c b/ext/standard/html.c
index 5e9bc50117..5d1b01fd27 100644
--- a/ext/standard/html.c
+++ b/ext/standard/html.c
@@ -14,6 +14,7 @@
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
| Jaakko Hyvätti <jaakko.hyvatti@iki.fi> |
+ | Wez Furlong <wez@thebrainroom.com> |
+----------------------------------------------------------------------+
*/
@@ -26,6 +27,9 @@
#if HAVE_LOCALE_H
#include <locale.h>
#endif
+#if HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
/* This must be fixed to handle the input string according to LC_CTYPE.
Defaults to ISO-8859-1 for now. */
@@ -218,41 +222,50 @@ static enum entity_charset determine_charset(char * charset_hint)
enum entity_charset charset = cs_8859_1;
int len;
-#if HAVE_LOCALE_H
+ /* Guarantee default behaviour */
if (charset_hint == NULL)
- {
- /* try to figure out the charset from the locale */
- char * localename;
- char * dot, * at;
-
- /* lang[_territory][.codeset][@modifier] */
- localename = setlocale(LC_CTYPE, NULL);
-
- dot = strchr(localename, '.');
- if (dot) {
- dot++;
- /* locale specifies a codeset */
- at = strchr(dot, '@');
- if (at)
- len = at - dot;
- else
- len = strlen(dot);
- charset_hint = dot;
+ return cs_8859_1;
+
+ if (strlen(charset_hint) == 0) {
+ /* try to detect the charset for the locale */
+#if HAVE_NL_LANGINFO
+ charset_hint = nl_langinfo(CODESET);
+#endif
+#if HAVE_LOCALE_H
+ if (charset_hint == NULL)
+ {
+ /* try to figure out the charset from the locale */
+ char * localename;
+ char * dot, * at;
+
+ /* lang[_territory][.codeset][@modifier] */
+ localename = setlocale(LC_CTYPE, NULL);
+
+ dot = strchr(localename, '.');
+ if (dot) {
+ dot++;
+ /* locale specifies a codeset */
+ at = strchr(dot, '@');
+ if (at)
+ len = at - dot;
+ else
+ len = strlen(dot);
+ charset_hint = dot;
+ }
+ else {
+ /* no explicit name; see if the name itself
+ * is the charset */
+ charset_hint = localename;
+ len = strlen(charset_hint);
+ }
}
- else {
- /* no explicit name; see if the name itself
- * is the charset */
- charset_hint = localename;
+ else
len = strlen(charset_hint);
- }
- }
- else
- len = strlen(charset_hint);
#else
- if (charset_hint)
- len = strlen(charset_hint);
+ if (charset_hint)
+ len = strlen(charset_hint);
#endif
-
+ }
if (charset_hint) {
/* now walk the charset map and look for the codeset */
for (i = 0; charset_map[i].codeset; i++) {
@@ -262,7 +275,6 @@ static enum entity_charset determine_charset(char * charset_hint)
}
}
}
-
return charset;
}
/* }}} */
diff --git a/ext/standard/php_string.h b/ext/standard/php_string.h
index a223043f9f..7e0ea30dcb 100644
--- a/ext/standard/php_string.h
+++ b/ext/standard/php_string.h
@@ -66,6 +66,7 @@ PHP_FUNCTION(ord);
PHP_FUNCTION(nl2br);
PHP_FUNCTION(setlocale);
PHP_FUNCTION(localeconv);
+PHP_FUNCTION(nl_langinfo);
PHP_FUNCTION(stristr);
PHP_FUNCTION(chunk_split);
PHP_FUNCTION(parse_str);
@@ -88,6 +89,9 @@ PHP_FUNCTION(strcoll);
PHP_MINIT_FUNCTION(localeconv);
PHP_MSHUTDOWN_FUNCTION(localeconv);
#endif
+#if HAVE_NL_LANGINFO
+PHP_MINIT_FUNCTION(nl_langinfo);
+#endif
#define strnatcmp(a, b) \
strnatcmp_ex(a, strlen(a), b, strlen(b), 0)
diff --git a/ext/standard/string.c b/ext/standard/string.c
index 74ea02863a..61fb9db4aa 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -30,6 +30,9 @@
#ifdef HAVE_LOCALE_H
# include <locale.h>
#endif
+#ifdef HAVE_LANGINFO_H
+# include <langinfo.h>
+#endif
#include "scanf.h"
#include "zend_API.h"
#include "zend_execute.h"
@@ -225,6 +228,122 @@ PHP_FUNCTION(strcspn)
}
/* }}} */
+#if HAVE_NL_LANGINFO
+PHP_MINIT_FUNCTION(nl_langinfo)
+{
+#define REGISTER_NL_LANGINFO_CONSTANT(x) REGISTER_LONG_CONSTANT(#x, x, CONST_CS | CONST_PERSISTENT)
+ REGISTER_NL_LANGINFO_CONSTANT(ABDAY_1);
+ REGISTER_NL_LANGINFO_CONSTANT(ABDAY_2);
+ REGISTER_NL_LANGINFO_CONSTANT(ABDAY_3);
+ REGISTER_NL_LANGINFO_CONSTANT(ABDAY_4);
+ REGISTER_NL_LANGINFO_CONSTANT(ABDAY_5);
+ REGISTER_NL_LANGINFO_CONSTANT(ABDAY_6);
+ REGISTER_NL_LANGINFO_CONSTANT(ABDAY_7);
+ REGISTER_NL_LANGINFO_CONSTANT(DAY_1);
+ REGISTER_NL_LANGINFO_CONSTANT(DAY_2);
+ REGISTER_NL_LANGINFO_CONSTANT(DAY_3);
+ REGISTER_NL_LANGINFO_CONSTANT(DAY_4);
+ REGISTER_NL_LANGINFO_CONSTANT(DAY_5);
+ REGISTER_NL_LANGINFO_CONSTANT(DAY_6);
+ REGISTER_NL_LANGINFO_CONSTANT(DAY_7);
+ REGISTER_NL_LANGINFO_CONSTANT(ABMON_1);
+ REGISTER_NL_LANGINFO_CONSTANT(ABMON_2);
+ REGISTER_NL_LANGINFO_CONSTANT(ABMON_3);
+ REGISTER_NL_LANGINFO_CONSTANT(ABMON_4);
+ REGISTER_NL_LANGINFO_CONSTANT(ABMON_5);
+ REGISTER_NL_LANGINFO_CONSTANT(ABMON_6);
+ REGISTER_NL_LANGINFO_CONSTANT(ABMON_7);
+ REGISTER_NL_LANGINFO_CONSTANT(ABMON_8);
+ REGISTER_NL_LANGINFO_CONSTANT(ABMON_9);
+ REGISTER_NL_LANGINFO_CONSTANT(ABMON_10);
+ REGISTER_NL_LANGINFO_CONSTANT(ABMON_11);
+ REGISTER_NL_LANGINFO_CONSTANT(ABMON_12);
+ REGISTER_NL_LANGINFO_CONSTANT(MON_1);
+ REGISTER_NL_LANGINFO_CONSTANT(MON_2);
+ REGISTER_NL_LANGINFO_CONSTANT(MON_3);
+ REGISTER_NL_LANGINFO_CONSTANT(MON_4);
+ REGISTER_NL_LANGINFO_CONSTANT(MON_5);
+ REGISTER_NL_LANGINFO_CONSTANT(MON_6);
+ REGISTER_NL_LANGINFO_CONSTANT(MON_7);
+ REGISTER_NL_LANGINFO_CONSTANT(MON_8);
+ REGISTER_NL_LANGINFO_CONSTANT(MON_9);
+ REGISTER_NL_LANGINFO_CONSTANT(MON_10);
+ REGISTER_NL_LANGINFO_CONSTANT(MON_11);
+ REGISTER_NL_LANGINFO_CONSTANT(MON_12);
+ REGISTER_NL_LANGINFO_CONSTANT(AM_STR);
+ REGISTER_NL_LANGINFO_CONSTANT(PM_STR);
+ REGISTER_NL_LANGINFO_CONSTANT(D_T_FMT);
+ REGISTER_NL_LANGINFO_CONSTANT(D_FMT);
+ REGISTER_NL_LANGINFO_CONSTANT(T_FMT);
+ REGISTER_NL_LANGINFO_CONSTANT(T_FMT_AMPM);
+ REGISTER_NL_LANGINFO_CONSTANT(ERA);
+ REGISTER_NL_LANGINFO_CONSTANT(ERA_YEAR);
+ REGISTER_NL_LANGINFO_CONSTANT(ERA_D_T_FMT);
+ REGISTER_NL_LANGINFO_CONSTANT(ERA_D_FMT);
+ REGISTER_NL_LANGINFO_CONSTANT(ERA_T_FMT);
+ REGISTER_NL_LANGINFO_CONSTANT(ALT_DIGITS);
+ REGISTER_NL_LANGINFO_CONSTANT(INT_CURR_SYMBOL);
+#ifdef CURRENCY_SYMBOL
+ REGISTER_NL_LANGINFO_CONSTANT(CURRENCY_SYMBOL);
+#endif
+#ifdef CRNCYSTR
+ REGISTER_NL_LANGINFO_CONSTANT(CRNCYSTR);
+#endif
+ REGISTER_NL_LANGINFO_CONSTANT(MON_DECIMAL_POINT);
+ REGISTER_NL_LANGINFO_CONSTANT(MON_THOUSANDS_SEP);
+ REGISTER_NL_LANGINFO_CONSTANT(MON_GROUPING);
+ REGISTER_NL_LANGINFO_CONSTANT(POSITIVE_SIGN);
+ REGISTER_NL_LANGINFO_CONSTANT(NEGATIVE_SIGN);
+ REGISTER_NL_LANGINFO_CONSTANT(INT_FRAC_DIGITS);
+ REGISTER_NL_LANGINFO_CONSTANT(FRAC_DIGITS);
+ REGISTER_NL_LANGINFO_CONSTANT(P_CS_PRECEDES);
+ REGISTER_NL_LANGINFO_CONSTANT(P_SEP_BY_SPACE);
+ REGISTER_NL_LANGINFO_CONSTANT(N_CS_PRECEDES);
+ REGISTER_NL_LANGINFO_CONSTANT(N_SEP_BY_SPACE);
+ REGISTER_NL_LANGINFO_CONSTANT(P_SIGN_POSN);
+ REGISTER_NL_LANGINFO_CONSTANT(N_SIGN_POSN);
+#ifdef DECIMAL_POINT
+ REGISTER_NL_LANGINFO_CONSTANT(DECIMAL_POINT);
+#endif
+#ifdef RADIXCHAR
+ REGISTER_NL_LANGINFO_CONSTANT(RADIXCHAR);
+#endif
+#ifdef THOUSANDS_SEP
+ REGISTER_NL_LANGINFO_CONSTANT(THOUSANDS_SEP);
+#endif
+#ifdef THOUSEP
+ REGISTER_NL_LANGINFO_CONSTANT(THOUSEP);
+#endif
+ REGISTER_NL_LANGINFO_CONSTANT(GROUPING);
+ REGISTER_NL_LANGINFO_CONSTANT(YESEXPR);
+ REGISTER_NL_LANGINFO_CONSTANT(NOEXPR);
+ REGISTER_NL_LANGINFO_CONSTANT(YESSTR);
+ REGISTER_NL_LANGINFO_CONSTANT(NOSTR);
+#ifdef CODESET
+ REGISTER_NL_LANGINFO_CONSTANT(CODESET);
+#endif
+#undef REGISTER_NL_LANGINFO_CONSTANT
+ return SUCCESS;
+}
+PHP_FUNCTION(nl_langinfo)
+{
+ zval ** item;
+ char * value;
+
+ if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &item) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_long_ex(item);
+ value = nl_langinfo(Z_LVAL_PP(item));
+ if (value == NULL) {
+ RETURN_FALSE;
+ }
+ else {
+ RETURN_STRING(value, 1);
+ }
+}
+#endif
+
#ifdef HAVE_STRCOLL
/* {{{ proto int strcoll(string str1, string str2)
Compare two strings using the current locale */