Back to index

php5  5.3.10
Functions
locale_methods.h File Reference
#include <php.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 PHP_FUNCTION (locale_get_primary_language)
 PHP_FUNCTION (locale_get_script)
 PHP_FUNCTION (locale_get_region)
 PHP_FUNCTION (locale_get_all_variants)
 PHP_NAMED_FUNCTION (zif_locale_get_default)
 PHP_NAMED_FUNCTION (zif_locale_set_default)
 PHP_FUNCTION (locale_get_display_name)
 PHP_FUNCTION (locale_get_display_language)
 PHP_FUNCTION (locale_get_display_script)
 PHP_FUNCTION (locale_get_display_region)
 PHP_FUNCTION (locale_get_display_variant)
 PHP_FUNCTION (locale_get_keywords)
 PHP_FUNCTION (locale_canonicalize)
 PHP_FUNCTION (locale_compose)
 PHP_FUNCTION (locale_parse)
 PHP_FUNCTION (locale_filter_matches)
 PHP_FUNCTION (locale_lookup)
 PHP_FUNCTION (locale_accept_from_http)

Function Documentation

Definition at line 456 of file locale_methods.c.

Here is the call graph for this function:

Definition at line 432 of file locale_methods.c.

Here is the call graph for this function:

Definition at line 444 of file locale_methods.c.

Here is the call graph for this function:

Definition at line 1128 of file locale_methods.c.

{
       char*         loc_name        = NULL;
       int           loc_name_len    = 0;

       int    result        = 0;
       char*  token         = NULL;
       char*  variant              = NULL;
       char*  saved_ptr     = NULL;

       intl_error_reset( NULL TSRMLS_CC );
       
       if(zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s",
       &loc_name, &loc_name_len ) == FAILURE)
       {
              intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
            "locale_parse: unable to parse input params", 0 TSRMLS_CC );

              RETURN_FALSE;
       }

       if(loc_name_len == 0) {
              loc_name = INTL_G(default_locale);
       }


       array_init( return_value );

       /* If the locale is grandfathered, stop, no variants */
       if( findOffset( LOC_GRANDFATHERED , loc_name ) >=  0 ){ 
              /* ("Grandfathered Tag. No variants."); */
       }
       else { 
       /* Call ICU variant */
              variant = get_icu_value_internal( loc_name , LOC_VARIANT_TAG , &result ,0);
              if( result > 0 && variant){
                     /* Tokenize on the "_" or "-" */
                     token = php_strtok_r( variant , DELIMITER , &saved_ptr);       
                     add_next_index_stringl( return_value, token , strlen(token) ,TRUE );
                     /* tokenize on the "_" or "-" and stop  at singleton if any    */
                     while( (token = php_strtok_r(NULL , DELIMITER, &saved_ptr)) && (strlen(token)>1) ){
                            add_next_index_stringl( return_value, token , strlen(token) ,TRUE );
                     }
              }
              if( variant ){
                     efree( variant );
              }
       }
                     

}

Here is the call graph for this function:

Definition at line 599 of file locale_methods.c.

Here is the call graph for this function:

Definition at line 611 of file locale_methods.c.

Here is the call graph for this function:

Definition at line 623 of file locale_methods.c.

Here is the call graph for this function:

Definition at line 635 of file locale_methods.c.

Here is the call graph for this function:

Definition at line 649 of file locale_methods.c.

Here is the call graph for this function:

Definition at line 663 of file locale_methods.c.

{
    UEnumeration*   e        = NULL;
    UErrorCode      status   = U_ZERO_ERROR;

       const char*          kw_key        = NULL;
    int32_t         kw_key_len    = 0;

    char*            loc_name        = NULL;
    int                     loc_name_len    = 0;

/* 
       ICU expects the buffer to be allocated  before calling the function 
       and so the buffer size has been explicitly specified 
       ICU uloc.h #define   ULOC_KEYWORD_AND_VALUES_CAPACITY   100 
       hence the kw_value buffer size is 100
*/
       char*         kw_value        = NULL;
    int32_t     kw_value_len    = 100;

    intl_error_reset( NULL TSRMLS_CC );

    if(zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s",
        &loc_name, &loc_name_len ) == FAILURE)
    {
        intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
             "locale_get_keywords: unable to parse input params", 0 TSRMLS_CC );

        RETURN_FALSE;
    }

    if(loc_name_len == 0) {
        loc_name = INTL_G(default_locale);
    }

       /* Get the keywords */
    e = uloc_openKeywords( loc_name, &status );
    if( e != NULL )
    {
              /* Traverse it, filling the return array. */
       array_init( return_value );

       while( ( kw_key = uenum_next( e, &kw_key_len, &status ) ) != NULL ){
                     kw_value = ecalloc( 1 , kw_value_len  );

                     /* Get the keyword value for each keyword */
                     kw_value_len=uloc_getKeywordValue( loc_name,kw_key, kw_value, kw_value_len ,  &status );
                     if (status == U_BUFFER_OVERFLOW_ERROR) {
                            status = U_ZERO_ERROR;
                            kw_value = erealloc( kw_value , kw_value_len+1);
                            kw_value_len=uloc_getKeywordValue( loc_name,kw_key, kw_value, kw_value_len+1 ,  &status );
                     } else if(!U_FAILURE(status)) {
                            kw_value = erealloc( kw_value , kw_value_len+1);
                     } 
                     if (U_FAILURE(status)) {
                     intl_error_set( NULL, FAILURE, "locale_get_keywords: Error encountered while getting the keyword  value for the  keyword", 0 TSRMLS_CC );
                            if( kw_value){
                                   efree( kw_value );
                            }
                            zval_dtor(return_value);
                     RETURN_FALSE;
                     }

                     add_assoc_stringl( return_value, (char *)kw_key, kw_value , kw_value_len, 0);
              } /* end of while */

       } /* end of if e!=NULL */

    uenum_close( e );
}

Here is the call graph for this function:

PHP_FUNCTION ( locale_canonicalize  )

Definition at line 741 of file locale_methods.c.

Here is the call graph for this function:

PHP_FUNCTION ( locale_compose  )

Definition at line 891 of file locale_methods.c.

{
       smart_str            loc_name_s = {0};
       smart_str *loc_name = &loc_name_s;
       zval*                arr    = NULL;
       HashTable*           hash_arr = NULL;
       int                  result = 0;

       intl_error_reset( NULL TSRMLS_CC );

       if(zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "a",
              &arr) == FAILURE)
       {
              intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
                      "locale_compose: unable to parse input params", 0 TSRMLS_CC );
              RETURN_FALSE;
       }

       hash_arr = HASH_OF( arr );

       if( !hash_arr || zend_hash_num_elements( hash_arr ) == 0 )
              RETURN_FALSE;

       /* Check for grandfathered first */
       result = append_key_value(loc_name, hash_arr,  LOC_GRANDFATHERED_LANG_TAG);  
       if( result == SUCCESS){
              RETURN_SMART_STR(loc_name);
       }
       if( !handleAppendResult( result, loc_name TSRMLS_CC)){
              RETURN_FALSE;
       }

       /* Not grandfathered */
       result = append_key_value(loc_name, hash_arr , LOC_LANG_TAG);  
       if( result == LOC_NOT_FOUND ){
              intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
              "locale_compose: parameter array does not contain 'language' tag.", 0 TSRMLS_CC );
              smart_str_free(loc_name);
              RETURN_FALSE;
       }
       if( !handleAppendResult( result, loc_name TSRMLS_CC)){
              RETURN_FALSE;
       }

       /* Extlang */
       result = append_multiple_key_values(loc_name, hash_arr , LOC_EXTLANG_TAG TSRMLS_CC);
       if( !handleAppendResult( result, loc_name TSRMLS_CC)){
              RETURN_FALSE;
       }

       /* Script */
       result = append_key_value(loc_name, hash_arr , LOC_SCRIPT_TAG); 
       if( !handleAppendResult( result, loc_name TSRMLS_CC)){
              RETURN_FALSE;
       }
       
       /* Region */
       result = append_key_value( loc_name, hash_arr , LOC_REGION_TAG);
       if( !handleAppendResult( result, loc_name TSRMLS_CC)){
              RETURN_FALSE;
       }

       /* Variant */
       result = append_multiple_key_values( loc_name, hash_arr , LOC_VARIANT_TAG TSRMLS_CC); 
       if( !handleAppendResult( result, loc_name TSRMLS_CC)){
              RETURN_FALSE;
       }

       /* Private */
       result = append_multiple_key_values( loc_name, hash_arr , LOC_PRIVATE_TAG TSRMLS_CC);
       if( !handleAppendResult( result, loc_name TSRMLS_CC)){
              RETURN_FALSE;
       }

       RETURN_SMART_STR(loc_name);
}

Here is the call graph for this function:

PHP_FUNCTION ( locale_parse  )

Definition at line 1084 of file locale_methods.c.

{
    char*       loc_name        = NULL;
    int         loc_name_len    = 0;
    int         grOffset           = 0;

    intl_error_reset( NULL TSRMLS_CC );

    if(zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s",
        &loc_name, &loc_name_len ) == FAILURE)
    {
        intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
             "locale_parse: unable to parse input params", 0 TSRMLS_CC );

        RETURN_FALSE;
    }

    if(loc_name_len == 0) {
        loc_name = INTL_G(default_locale);
    }

       array_init( return_value );

       grOffset =  findOffset( LOC_GRANDFATHERED , loc_name );
       if( grOffset >= 0 ){
              add_assoc_string( return_value , LOC_GRANDFATHERED_LANG_TAG , estrdup(loc_name) ,FALSE );
       }
       else{
              /* Not grandfathered */
              add_array_entry( loc_name , return_value , LOC_LANG_TAG TSRMLS_CC);
              add_array_entry( loc_name , return_value , LOC_SCRIPT_TAG TSRMLS_CC);
              add_array_entry( loc_name , return_value , LOC_REGION_TAG TSRMLS_CC);
              add_array_entry( loc_name , return_value , LOC_VARIANT_TAG TSRMLS_CC);
              add_array_entry( loc_name , return_value , LOC_PRIVATE_TAG TSRMLS_CC);
       }
}

Here is the call graph for this function:

Definition at line 1223 of file locale_methods.c.

{
       char*         lang_tag        = NULL;
       int           lang_tag_len    = 0;
       char*         loc_range       = NULL;
       int           loc_range_len   = 0;

       int           result        = 0;
       char*         token         = 0;
       char*         chrcheck      = NULL;

       char*         can_lang_tag    = NULL;
       char*         can_loc_range   = NULL;

       char*         cur_lang_tag    = NULL;
       char*         cur_loc_range   = NULL;

       zend_bool     boolCanonical        = 0;   
       UErrorCode    status        = U_ZERO_ERROR;

       intl_error_reset( NULL TSRMLS_CC );
       
       if(zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "ss|b",
              &lang_tag, &lang_tag_len , &loc_range , &loc_range_len , 
              &boolCanonical) == FAILURE)
       {
              intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
              "locale_filter_matches: unable to parse input params", 0 TSRMLS_CC );

              RETURN_FALSE;
       }

       if(loc_range_len == 0) {
              loc_range = INTL_G(default_locale);
       }

       if( strcmp(loc_range,"*")==0){
              RETURN_TRUE;
       }

       if( boolCanonical ){
              /* canonicalize loc_range */
              can_loc_range=get_icu_value_internal( loc_range , LOC_CANONICALIZE_TAG , &result , 0);
              if( result ==0) {
                     intl_error_set( NULL, status, 
                            "locale_filter_matches : unable to canonicalize loc_range" , 0 TSRMLS_CC );
                     RETURN_FALSE;
              }

              /* canonicalize lang_tag */
              can_lang_tag = get_icu_value_internal( lang_tag , LOC_CANONICALIZE_TAG , &result ,  0);
              if( result ==0) {
                     intl_error_set( NULL, status, 
                            "locale_filter_matches : unable to canonicalize lang_tag" , 0 TSRMLS_CC );
                     RETURN_FALSE;
              }

              /* Convert to lower case for case-insensitive comparison */
              cur_lang_tag = ecalloc( 1, strlen(can_lang_tag) + 1);

              /* Convert to lower case for case-insensitive comparison */
              result = strToMatch( can_lang_tag , cur_lang_tag);
              if( result == 0) {
                     efree( cur_lang_tag );
                     efree( can_lang_tag );
                     RETURN_FALSE;
              }

              cur_loc_range = ecalloc( 1, strlen(can_loc_range) + 1);
              result = strToMatch( can_loc_range , cur_loc_range );
              if( result == 0) {
                     efree( cur_lang_tag );
                     efree( can_lang_tag );
                     efree( cur_loc_range );
                     efree( can_loc_range );
                     RETURN_FALSE;
              }

              /* check if prefix */
              token  = strstr( cur_lang_tag , cur_loc_range );
       
              if( token && (token==cur_lang_tag) ){
                     /* check if the char. after match is SEPARATOR */
                     chrcheck = token + (strlen(cur_loc_range));
                     if( isIDSeparator(*chrcheck) || isEndOfTag(*chrcheck) ){ 
                            if( cur_lang_tag){
                                   efree( cur_lang_tag );
                            }
                            if( cur_loc_range){
                                   efree( cur_loc_range );
                            }
                            if( can_lang_tag){
                                   efree( can_lang_tag );
                            }
                            if( can_loc_range){
                                   efree( can_loc_range );
                            }
                            RETURN_TRUE;
                     }
              }

              /* No prefix as loc_range */
              if( cur_lang_tag){
                     efree( cur_lang_tag );
              }
              if( cur_loc_range){
                     efree( cur_loc_range );
              }
              if( can_lang_tag){
                     efree( can_lang_tag );
              }
              if( can_loc_range){
                     efree( can_loc_range );
              }
              RETURN_FALSE;

       } /* end of if isCanonical */
       else{
              /* Convert to lower case for case-insensitive comparison */
              cur_lang_tag = ecalloc( 1, strlen(lang_tag ) + 1);
              
              result = strToMatch( lang_tag , cur_lang_tag);
              if( result == 0) {
                     efree( cur_lang_tag );
                     RETURN_FALSE;
              }
              cur_loc_range = ecalloc( 1, strlen(loc_range ) + 1);
              result = strToMatch( loc_range , cur_loc_range );
              if( result == 0) {
                     efree( cur_lang_tag );
                     efree( cur_loc_range );
                     RETURN_FALSE;
              }

              /* check if prefix */
              token  = strstr( cur_lang_tag , cur_loc_range );
              
              if( token && (token==cur_lang_tag) ){
                     /* check if the char. after match is SEPARATOR */
                     chrcheck = token + (strlen(cur_loc_range));
                     if( isIDSeparator(*chrcheck) || isEndOfTag(*chrcheck) ){ 
                            if( cur_lang_tag){
                                   efree( cur_lang_tag );
                            }
                            if( cur_loc_range){
                                   efree( cur_loc_range );
                            }
                            RETURN_TRUE;
                     }
              }

              /* No prefix as loc_range */
              if( cur_lang_tag){
                     efree( cur_lang_tag );
              }
              if( cur_loc_range){
                     efree( cur_loc_range );
              }
              RETURN_FALSE;

       }
}

Here is the call graph for this function:

Definition at line 1521 of file locale_methods.c.

{
       char*         fallback_loc                = NULL;
       int           fallback_loc_len     = 0;
       char*         loc_range                   = NULL;
       int           loc_range_len               = 0;

       zval*         arr                         = NULL;
       HashTable*    hash_arr             = NULL;
       zend_bool     boolCanonical = 0;
       char*         result               =NULL;

       intl_error_reset( NULL TSRMLS_CC );

       if(zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "as|bs", &arr, &loc_range, &loc_range_len,
              &boolCanonical,      &fallback_loc, &fallback_loc_len) == FAILURE) {
              intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,  "locale_lookup: unable to parse input params", 0 TSRMLS_CC );
              RETURN_FALSE;
       }

       if(loc_range_len == 0) {
              loc_range = INTL_G(default_locale);
       }

       hash_arr = HASH_OF(arr);

       if( !hash_arr || zend_hash_num_elements( hash_arr ) == 0 ) {
              RETURN_EMPTY_STRING();
       } 
       
       result = lookup_loc_range(loc_range, hash_arr, boolCanonical TSRMLS_CC);
       if(result == NULL || result[0] == '\0') {
              if( fallback_loc ) {
                     result = estrndup(fallback_loc, fallback_loc_len);
              } else {
                     RETURN_EMPTY_STRING();
              }
       }

       RETVAL_STRINGL(result, strlen(result), 0);
}

Here is the call graph for this function:

PHP_FUNCTION ( locale_accept_from_http  )

Definition at line 1571 of file locale_methods.c.

{
       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_FALSE;
       }
       
       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 (len < 0 || outResult == ULOC_ACCEPT_FAILED) {
              RETURN_FALSE;
       }
       RETURN_STRINGL(resultLocale, len, 1);
}

Here is the call graph for this function:

PHP_NAMED_FUNCTION ( zif_locale_get_default  )

Definition at line 209 of file locale_methods.c.

{
       if( INTL_G(default_locale) == NULL ) {
              INTL_G(default_locale) = pestrdup( uloc_getDefault(), 1);
       }
       RETURN_STRING( INTL_G(default_locale), TRUE );
}
PHP_NAMED_FUNCTION ( zif_locale_set_default  )

Definition at line 224 of file locale_methods.c.

{
       char* locale_name = NULL;
       int   len=0;  

       if(zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC,  "s",
              &locale_name ,&len ) == FAILURE)
       {
              intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
                            "locale_set_default: unable to parse input params", 0 TSRMLS_CC );

              RETURN_FALSE;
       }

       if(len == 0) {
              locale_name =  (char *)uloc_getDefault() ;
              len = strlen(locale_name);
       }

       zend_alter_ini_entry(LOCALE_INI_NAME, sizeof(LOCALE_INI_NAME), locale_name, len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); 

       RETURN_TRUE;
}

Here is the call graph for this function: