moriyoshi               Thu Oct 24 18:04:29 2002 EDT

  Modified files:              
    /php4/ext/standard  html.c 
  Log:
  Improved determine_charset() to look up SG(default_charset) value 
  
  
Index: php4/ext/standard/html.c
diff -u php4/ext/standard/html.c:1.58 php4/ext/standard/html.c:1.59
--- php4/ext/standard/html.c:1.58       Thu Oct 24 17:10:45 2002
+++ php4/ext/standard/html.c    Thu Oct 24 18:04:28 2002
@@ -18,12 +18,13 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: html.c,v 1.58 2002/10/24 21:10:45 moriyoshi Exp $ */
+/* $Id: html.c,v 1.59 2002/10/24 22:04:28 moriyoshi Exp $ */
 
 #include "php.h"
 #include "reg.h"
 #include "html.h"
 #include "php_string.h"
+#include "SAPI.h"
 #if HAVE_LOCALE_H
 #include <locale.h>
 #endif
@@ -529,7 +530,7 @@
        if (charset_hint == NULL)
                return cs_8859_1;
 
-       if (strlen(charset_hint) == 0)  {
+       if ((len = strlen(charset_hint)) == 0) {
 #if HAVE_MBSTRING
        /* XXX: Ugly things. Why don't we look for a more sophisticated way? */
                switch (MBSTRG(internal_encoding)) {
@@ -563,46 +564,45 @@
                                return cs_gb2312;
                }
 #endif
-               /* try to detect the charset for the locale */
+               charset_hint = SG(default_charset);
+               if (charset_hint == NULL || (len=strlen(charset_hint)) == 0) {
+                       /* try to detect the charset for the locale */
 #if HAVE_NL_LANGINFO && HAVE_LOCALE_H && defined(CODESET)
-               charset_hint = nl_langinfo(CODESET);
+                       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;
+                       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;
                                len = strlen(charset_hint);
                        }
-               } else
-                       len = strlen(charset_hint);
-#else
-               if (charset_hint)
-                       len = strlen(charset_hint);
 #endif
+               }
        }
        if (charset_hint) {
                int found = 0;
-               if (!len)
-                       len = strlen(charset_hint);
                
                /* now walk the charset map and look for the codeset */
                for (i = 0; charset_map[i].codeset; i++)        {



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

Reply via email to