summaryrefslogtreecommitdiff
path: root/ext/standard/html.c
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 /ext/standard/html.c
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?
Diffstat (limited to 'ext/standard/html.c')
-rw-r--r--ext/standard/html.c74
1 files changed, 43 insertions, 31 deletions
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;
}
/* }}} */