Back to index

php5  5.3.10
Functions
msgformat_helpers.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int32_t umsg_format_arg_count (UMessageFormat *fmt)
void umsg_format_helper (UMessageFormat *fmt, int arg_count, zval **args, UChar **formatted, int *formatted_len, UErrorCode *status TSRMLS_DC)
void umsg_parse_helper (UMessageFormat *fmt, int *count, zval ***args, UChar *source, int source_len, UErrorCode *status)

Function Documentation

int32_t umsg_format_arg_count ( UMessageFormat *  fmt)

Definition at line 51 of file msgformat_helpers.cpp.

{
       int32_t fmt_count = 0;
       MessageFormatAdapter::getArgTypeList(*(const MessageFormat*)fmt, fmt_count);
       return fmt_count;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void umsg_format_helper ( UMessageFormat *  fmt,
int  arg_count,
zval **  args,
UChar **  formatted,
int formatted_len,
UErrorCode *status  TSRMLS_DC 
)

Definition at line 58 of file msgformat_helpers.cpp.

{
       int fmt_count = 0;
    const Formattable::Type* argTypes =
              MessageFormatAdapter::getArgTypeList(*(const MessageFormat*)fmt, fmt_count);
       Formattable* fargs = new Formattable[fmt_count ? fmt_count : 1];

       for(int32_t i = 0; i < fmt_count; ++i) {
        UChar  *stringVal = NULL;
              int     stringLen = 0;
              int64_t tInt64 = 0;

              switch(argTypes[i]) {
                     case Formattable::kDate:
                            convert_to_long_ex(&args[i]);
                            fargs[i].setDate(U_MILLIS_PER_SECOND * (double)Z_LVAL_P(args[i]));
                            break;

                     case Formattable::kDouble:
                            convert_to_double_ex(&args[i]);
                         fargs[i].setDouble(Z_DVAL_P(args[i]));
                            break;
            
               case Formattable::kLong:
                            convert_to_long_ex(&args[i]);
                         fargs[i].setLong(Z_LVAL_P(args[i]));
                            break;

               case Formattable::kInt64:
                            if(Z_TYPE_P(args[i]) == IS_DOUBLE) {
                                   tInt64 = (int64_t)Z_DVAL_P(args[i]);
                            } else if(Z_TYPE_P(args[i]) == IS_LONG) {
                                   tInt64 = (int64_t)Z_LVAL_P(args[i]);
                            } else {
                                   SEPARATE_ZVAL_IF_NOT_REF(&args[i]);
                                   convert_scalar_to_number( args[i] TSRMLS_CC );
                                   tInt64 = (Z_TYPE_P(args[i]) == IS_DOUBLE)?(int64_t)Z_DVAL_P(args[i]):Z_LVAL_P(args[i]);
                            }
                         fargs[i].setInt64(tInt64);
                            break;
            
               case Formattable::kString:
                      convert_to_string_ex(&args[i]);
                            intl_convert_utf8_to_utf16(&stringVal, &stringLen, Z_STRVAL_P(args[i]), Z_STRLEN_P(args[i]), status);
                            if(U_FAILURE(*status)){
                                   delete[] fargs;
                                   return;
                            }
                            fargs[i].setString(stringVal);
                            efree(stringVal);
                         break;
            
                     case Formattable::kArray:
                     case Formattable::kObject:
                            *status = U_UNSUPPORTED_ERROR;
                            delete[] fargs;
                            return;
        }            
       }

    UnicodeString resultStr;
    FieldPosition fieldPosition(0);
    
    /* format the message */
    ((const MessageFormat*)fmt)->format(fargs, fmt_count, resultStr, fieldPosition, *status);

    delete[] fargs;

    if(U_FAILURE(*status)){
        return;
    }

       *formatted_len = resultStr.length();
       *formatted = eumalloc(*formatted_len+1);
       resultStr.extract(*formatted, *formatted_len+1, *status);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void umsg_parse_helper ( UMessageFormat *  fmt,
int count,
zval ***  args,
UChar source,
int  source_len,
UErrorCode *  status 
)

Definition at line 137 of file msgformat_helpers.cpp.

{
    UnicodeString srcString(source, source_len);
    Formattable *fargs = ((const MessageFormat*)fmt)->parse(srcString, *count, *status);

       if(U_FAILURE(*status)) {
              return;
       }

       *args = (zval **)safe_emalloc(*count, sizeof(zval *), 0);

    // assign formattables to varargs
    for(int32_t i = 0; i < *count; i++) {
           int64_t aInt64;
              double aDate;
              UnicodeString temp;
              char *stmp;
              int stmp_len;

              ALLOC_INIT_ZVAL((*args)[i]);
              
              switch(fargs[i].getType()) {
        case Formattable::kDate:
                     aDate = ((double)fargs[i].getDate())/U_MILLIS_PER_SECOND;
                     if(aDate > LONG_MAX || aDate < -LONG_MAX) {
                            ZVAL_DOUBLE((*args)[i], aDate<0?ceil(aDate):floor(aDate));
                     } else {
                            ZVAL_LONG((*args)[i], (long)aDate);
                     }
            break;

        case Formattable::kDouble:
                     ZVAL_DOUBLE((*args)[i], (double)fargs[i].getDouble());
            break;

        case Formattable::kLong:
                     ZVAL_LONG((*args)[i], fargs[i].getLong());
            break;

        case Formattable::kInt64:
            aInt64 = fargs[i].getInt64();
                     if(aInt64 > LONG_MAX || aInt64 < -LONG_MAX) {
                            ZVAL_DOUBLE((*args)[i], (double)aInt64);
                     } else {
                            ZVAL_LONG((*args)[i], (long)aInt64);
                     }
            break;

        case Formattable::kString:
            fargs[i].getString(temp);
                     intl_convert_utf16_to_utf8(&stmp, &stmp_len, temp.getBuffer(), temp.length(), status);
                     if(U_FAILURE(*status)) {
                            cleanup_zvals();
                            return;
                     }
                     ZVAL_STRINGL((*args)[i], stmp, stmp_len, 0);
            break;

        case Formattable::kObject:
        case Formattable::kArray:
            *status = U_ILLEGAL_ARGUMENT_ERROR;
                     cleanup_zvals();
            break;
        }
    }
       delete[] fargs;
}

Here is the call graph for this function:

Here is the caller graph for this function: