stas            Wed Jul 23 01:15:34 2008 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src/ext/intl   php_intl.c 
    /php-src/ext/intl/locale    locale_class.c locale_methods.c 
                                locale_methods.h 
    /php-src/ext/intl/tests     ut_common.inc 
  Log:
  add acceptFromHttp
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/intl/php_intl.c?r1=1.1.2.3&r2=1.1.2.4&diff_format=u
Index: php-src/ext/intl/php_intl.c
diff -u php-src/ext/intl/php_intl.c:1.1.2.3 php-src/ext/intl/php_intl.c:1.1.2.4
--- php-src/ext/intl/php_intl.c:1.1.2.3 Mon Jul 14 07:16:24 2008
+++ php-src/ext/intl/php_intl.c Wed Jul 23 01:15:33 2008
@@ -278,6 +278,7 @@
        PHP_FE( locale_filter_matches, locale_3_args )
        PHP_FE( locale_canonicalize, locale_1_arg )
        PHP_FE( locale_lookup, locale_4_args )
+       PHP_FE( locale_accept_from_http, locale_1_arg )
 
        // MessageFormatter functions
        PHP_FE( msgfmt_create, NULL )
http://cvs.php.net/viewvc.cgi/php-src/ext/intl/locale/locale_class.c?r1=1.1.2.1&r2=1.1.2.2&diff_format=u
Index: php-src/ext/intl/locale/locale_class.c
diff -u php-src/ext/intl/locale/locale_class.c:1.1.2.1 
php-src/ext/intl/locale/locale_class.c:1.1.2.2
--- php-src/ext/intl/locale/locale_class.c:1.1.2.1      Mon Jul  7 22:51:03 2008
+++ php-src/ext/intl/locale/locale_class.c      Wed Jul 23 01:15:33 2008
@@ -89,6 +89,7 @@
        ZEND_FENTRY( filterMatches, ZEND_FN( locale_filter_matches ), 
locale_3_args, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
        ZEND_FENTRY( lookup, ZEND_FN( locale_lookup ), locale_4_args, 
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
        ZEND_FENTRY( canonicalize, ZEND_FN( locale_canonicalize ), locale_1_arg 
, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
+       ZEND_FENTRY( acceptFromHttp, ZEND_FN( locale_accept_from_http ), 
locale_1_arg , ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
        { NULL, NULL, NULL }
 };
 /* }}} */
http://cvs.php.net/viewvc.cgi/php-src/ext/intl/locale/locale_methods.c?r1=1.1.2.1&r2=1.1.2.2&diff_format=u
Index: php-src/ext/intl/locale/locale_methods.c
diff -u php-src/ext/intl/locale/locale_methods.c:1.1.2.1 
php-src/ext/intl/locale/locale_methods.c:1.1.2.2
--- php-src/ext/intl/locale/locale_methods.c:1.1.2.1    Mon Jul  7 22:51:03 2008
+++ php-src/ext/intl/locale/locale_methods.c    Wed Jul 23 01:15:33 2008
@@ -21,12 +21,14 @@
 #include <unicode/ustring.h>
 #include <unicode/udata.h>
 #include <unicode/putil.h>
+#include <unicode/ures.h>
 
 #include "php_intl.h"
 #include "locale.h"
 #include "locale_class.h"
 #include "locale_methods.h"
 #include "intl_convert.h"
+#include "intl_data.h"
 
 #include <zend_API.h>
 #include <zend.h>
@@ -424,12 +426,10 @@
 }
 /* }}} */
 
-/* {{{
- * proto public static string Locale::getScript($locale) 
+/* {{{ proto static string Locale::getScript($locale) 
  * gets the script for the $locale 
  }}} */
-/* {{{
- * proto public static string locale_get_script($locale) 
+/* {{{ proto static string locale_get_script($locale) 
  * gets the script for the $locale 
  */
 PHP_FUNCTION( locale_get_script ) 
@@ -438,12 +438,10 @@
 }
 /* }}} */
 
-/* {{{
- * proto public static string Locale::getRegion($locale) 
+/* {{{ proto static string Locale::getRegion($locale) 
  * gets the region for the $locale 
  }}} */
-/* {{{
- * proto public static string locale_get_region($locale) 
+/* {{{ proto static string locale_get_region($locale) 
  * gets the region for the $locale 
  */
 PHP_FUNCTION( locale_get_region ) 
@@ -452,12 +450,10 @@
 }
 /* }}} */
 
-/* {{{
- * proto public static string Locale::getPrimaryLanguage($locale) 
+/* {{{ proto static string Locale::getPrimaryLanguage($locale) 
  * gets the primary language for the $locale 
  }}} */
-/* {{{
- * proto public static string locale_get_primary_language($locale) 
+/* {{{ proto static string locale_get_primary_language($locale) 
  * gets the primary language for the $locale 
  */
 PHP_FUNCTION(locale_get_primary_language ) 
@@ -607,12 +603,10 @@
 }
 /* }}} */
 
-/* {{{
-* public static string Locale::getDisplayName($locale, $in_locale = null)
+/* {{{ proto static string Locale::getDisplayName($locale[, $in_locale = null])
 * gets the name for the $locale in $in_locale or default_locale
  }}} */
-/* {{{
-* public static string get_display_name($locale, $in_locale = null)
+/* {{{ proto static string get_display_name($locale[, $in_locale = null])
 * gets the name for the $locale in $in_locale or default_locale
 */
 PHP_FUNCTION(locale_get_display_name) 
@@ -621,12 +615,10 @@
 }
 /* }}} */
 
-/* {{{
-* public static string Locale::getDisplayLanguage($locale, $in_locale = null)
+/* {{{ proto static string Locale::getDisplayLanguage($locale[, $in_locale = 
null])
 * gets the language for the $locale in $in_locale or default_locale
  }}} */
-/* {{{
-* public static string get_display_language($locale, $in_locale = null)
+/* {{{ proto static string get_display_language($locale[, $in_locale = null])
 * gets the language for the $locale in $in_locale or default_locale
 */
 PHP_FUNCTION(locale_get_display_language) 
@@ -635,12 +627,10 @@
 }
 /* }}} */
 
-/* {{{
-* public static string Locale::getDisplayScript($locale, $in_locale = null)
+/* {{{ proto static string Locale::getDisplayScript($locale, $in_locale = null)
 * gets the script for the $locale in $in_locale or default_locale
  }}} */
-/* {{{
-* public static string get_display_script($locale, $in_locale = null)
+/* {{{ proto static string get_display_script($locale, $in_locale = null)
 * gets the script for the $locale in $in_locale or default_locale
 */
 PHP_FUNCTION(locale_get_display_script) 
@@ -649,12 +639,10 @@
 }
 /* }}} */
 
-/* {{{
-* public static string Locale::getDisplayRegion($locale, $in_locale = null)
+/* {{{ proto static string Locale::getDisplayRegion($locale, $in_locale = null)
 * gets the region for the $locale in $in_locale or default_locale
  }}} */
-/* {{{
-* public static string get_display_region($locale, $in_locale = null)
+/* {{{ proto static string get_display_region($locale, $in_locale = null)
 * gets the region for the $locale in $in_locale or default_locale
 */
 PHP_FUNCTION(locale_get_display_region) 
@@ -664,11 +652,11 @@
 /* }}} */
 
 /* {{{
-* public static string Locale::getDisplayVariant($locale, $in_locale = null)
+* proto static string Locale::getDisplayVariant($locale, $in_locale = null)
 * gets the variant for the $locale in $in_locale or default_locale
  }}} */
 /* {{{
-* public static string get_display_variant($locale, $in_locale = null)
+* proto static string get_display_variant($locale, $in_locale = null)
 * gets the variant for the $locale in $in_locale or default_locale
 */
 PHP_FUNCTION(locale_get_display_variant) 
@@ -677,17 +665,14 @@
 }
 /* }}} */
 
-     /* {{{
-     * proto static string[] getKeywords(string $locale) {
-     * return an associative array containing keyword-value
-     * pairs for this locale. The keys are keys to the array (doh!)
-     * }}}*/
-     /* {{{
-     * proto static string[] locale_get_keywords(string $locale) {
-     * return an associative array containing keyword-value
-     * pairs for this locale. The keys are keys to the array (doh!)
-     */ 
-
+ /* {{{ proto static array getKeywords(string $locale) {
+ * return an associative array containing keyword-value
+ * pairs for this locale. The keys are keys to the array (doh!)
+ * }}}*/
+ /* {{{ proto static array locale_get_keywords(string $locale) {
+ * return an associative array containing keyword-value
+ * pairs for this locale. The keys are keys to the array (doh!)
+ */ 
 PHP_FUNCTION( locale_get_keywords )
 {
     UEnumeration*   e        = NULL;
@@ -761,12 +746,10 @@
 }
 /* }}} */
 
- /* {{{
- * proto static string Locale::canonicalize($locale) 
+ /* {{{ proto static string Locale::canonicalize($locale) 
  * @return string the canonicalized locale 
  * }}} */
- /* {{{
- * proto static string locale_canonicalize(Locale $loc, string $locale) 
+ /* {{{ proto static string locale_canonicalize(Locale $loc, string $locale) 
  * @param string $locale       The locale string to canonicalize
  */
 PHP_FUNCTION(locale_canonicalize)
@@ -970,12 +953,10 @@
 }
 /* }}} */
 
-/* {{{
-* proto static string Locale::composeLocale($array) 
+/* {{{ proto static string Locale::composeLocale($array) 
 * Creates a locale by combining the parts of locale-ID passed  
 * }}} */
-/* {{{
-* proto static string compose_locale($array) 
+/* {{{ proto static string compose_locale($array) 
 * Creates a locale by combining the parts of locale-ID passed  
 * }}} */
 PHP_FUNCTION(locale_compose)
@@ -1174,13 +1155,12 @@
        }
        return cur_result;
 }
+/* }}} */
 
-/* {{{
-* proto static array Locale::parseLocale($locale) 
+/* {{{ proto static array Locale::parseLocale($locale) 
 * parses a locale-id into an array the different parts of it
  }}} */
-/* {{{
-* proto static array parse_locale($locale) 
+/* {{{ proto static array parse_locale($locale) 
 * parses a locale-id into an array the different parts of it
 */
 PHP_FUNCTION(locale_parse)
@@ -1317,8 +1297,12 @@
 }
 /* }}} */
 
-/*{{{
-* code used by locale_filter_maatches
+/* {{{ proto static boolean Locale::filterMatches(string $langtag, string 
$locale)
+* Checks if a $langtag filter matches with $locale according to RFC 4647's 
basic filtering algorithm 
+*/
+/* }}} */
+/* {{{ proto boolean locale_filter_matches(string $langtag, string $locale)
+* Checks if a $langtag filter matches with $locale according to RFC 4647's 
basic filtering algorithm 
 */
 PHP_FUNCTION(locale_filter_matches)
 {
@@ -1483,6 +1467,7 @@
 
        }
 }
+/* }}} */
 
 static void array_cleanup( char* arr[] , int arr_size)
 {
@@ -1656,13 +1641,12 @@
 }
 /* }}} */
 
-/* {{{
-* public static function lookup(array $langtag, $locale, $default = null) 
+/* {{{ proto string Locale::lookup(array $langtag, $locale[, $default = null]) 
 * Searchs the items in $langtag for the best match to the language
 * range 
 */
-/* {{{
-* public static function lookup(array $langtag, $locale, $default = null) 
+/* }}} */
+/* {{{ proto string locale_lookup(array $langtag, $locale[, $default = null])
 * Searchs the items in $langtag for the best match to the language
 * range 
 */
@@ -1718,8 +1702,44 @@
 
        RETVAL_STRINGL( result, strlen(result), 0);
 }
+/* }}} */
 
+/* {{{ proto string Locale::acceptFromHttp(string $http_accept)
+* Tries to find out best available locale based on HTTP “Accept-Language” 
header
+*/
+/* }}} */
+/* {{{ proto string locale_accept_from_http(string $http_accept)
+* Tries to find out best available locale based on HTTP “Accept-Language” 
header
+*/
+PHP_FUNCTION(locale_accept_from_http)
+{
+       UEnumeration *available;
+       char *http_accept = NULL;
+       int http_accept_len;
+       UErrorCode status = 0;
+       int len;
+       char resultLocale[INTL_MAX_LOCALE_LEN+1];
+       UAcceptResult outResult;
 
+       if(zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s", &http_accept, 
&http_accept_len) == FAILURE)
+       {
+               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
+               "locale_accept_from_http: unable to parse input parameters", 0 
TSRMLS_CC );
+               RETURN_NULL();
+       }
+       
+       available = ures_openAvailableLocales(NULL, &status);
+       INTL_CHECK_STATUS(status, "locale_accept_from_http: failed to retrieve 
locale list");
+       len = uloc_acceptLanguageFromHTTP(resultLocale, INTL_MAX_LOCALE_LEN, 
+                                               &outResult, http_accept, 
available, &status);
+       uenum_close(available);
+       INTL_CHECK_STATUS(status, "locale_accept_from_http: failed to find 
acceptable locale");
+       if(outResult == ULOC_ACCEPT_FAILED) {
+               RETURN_FALSE;
+       }
+       RETURN_STRINGL(resultLocale, len, 1);
+}
+/* }}} */
 
 /*
  * Local variables:
http://cvs.php.net/viewvc.cgi/php-src/ext/intl/locale/locale_methods.h?r1=1.1.2.1&r2=1.1.2.2&diff_format=u
Index: php-src/ext/intl/locale/locale_methods.h
diff -u php-src/ext/intl/locale/locale_methods.h:1.1.2.1 
php-src/ext/intl/locale/locale_methods.h:1.1.2.2
--- php-src/ext/intl/locale/locale_methods.h:1.1.2.1    Mon Jul  7 22:51:03 2008
+++ php-src/ext/intl/locale/locale_methods.h    Wed Jul 23 01:15:33 2008
@@ -43,5 +43,6 @@
 PHP_FUNCTION( locale_filter_matches);
 PHP_FUNCTION( locale_lookup);
 PHP_FUNCTION( locale_canonicalize);
+PHP_FUNCTION( locale_accept_from_http);
 
 #endif // LOCALE_METHODS_H
http://cvs.php.net/viewvc.cgi/php-src/ext/intl/tests/ut_common.inc?r1=1.1.2.2&r2=1.1.2.3&diff_format=u
Index: php-src/ext/intl/tests/ut_common.inc
diff -u php-src/ext/intl/tests/ut_common.inc:1.1.2.2 
php-src/ext/intl/tests/ut_common.inc:1.1.2.3
--- php-src/ext/intl/tests/ut_common.inc:1.1.2.2        Thu Jul 10 21:58:02 2008
+++ php-src/ext/intl/tests/ut_common.inc        Wed Jul 23 01:15:33 2008
@@ -280,6 +280,9 @@
 {
     return $GLOBALS['oo-mode'] ? Locale::lookup( 
$lang_tag_arr,$loc_range,$isCanonical,$default_loc ) : locale_lookup( 
$lang_tag_arr,$loc_range,$isCanonical,$default_loc );
 }
+function ut_loc_accept_http($http) {
+       return $GLOBALS['oo-mode'] ? 
Locale::acceptFromHttp($http):locale_accept_from_http($http);
+}
 /* MessageFormatter functions */
 function ut_msgfmt_create( $locale, $pattern)
 {

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

Reply via email to