From: Sara Golemon Date: Mon, 21 Jan 2008 06:08:03 +0000 (+0000) Subject: Make unicode ready X-Git-Tag: RELEASE_2_0_0a1~830 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=87c8d19c1bd99de13b53cf756063be440280f76f;p=php Make unicode ready --- diff --git a/ext/calendar/calendar.c b/ext/calendar/calendar.c index 9ce89fbe94..55d66f7b84 100644 --- a/ext/calendar/calendar.c +++ b/ext/calendar/calendar.c @@ -35,6 +35,8 @@ #include +ZEND_DECLARE_MODULE_GLOBALS(calendar); + /* {{{ arginfo */ static ZEND_BEGIN_ARG_INFO_EX(arginfo_unixtojd, 0, 0, 0) @@ -169,6 +171,20 @@ const zend_function_entry calendar_functions[] = { {NULL, NULL, NULL} }; +static PHP_GINIT_FUNCTION(calendar) +{ + if (zend_set_converter_encoding(&(calendar_globals->iso_8859_8_conv), "iso-8859-8") == FAILURE) { + php_error(E_CORE_WARNING, "Unable to instatiate iso-8859-8 converter for calendar extension, will be unable to produce hebrew dates in unicode mode"); + calendar_globals = NULL; + } +} + +static PHP_GSHUTDOWN_FUNCTION(calendar) +{ + if (calendar_globals->iso_8859_8_conv) { + ucnv_close(calendar_globals->iso_8859_8_conv); + } +} zend_module_entry calendar_module_entry = { STANDARD_MODULE_HEADER, @@ -180,7 +196,11 @@ zend_module_entry calendar_module_entry = { NULL, PHP_MINFO(calendar), NO_VERSION_YET, - STANDARD_MODULE_PROPERTIES, + PHP_MODULE_GLOBALS(calendar), + PHP_GINIT(calendar), + PHP_GSHUTDOWN(calendar), + NULL, + STANDARD_MODULE_PROPERTIES_EX, }; #ifdef COMPILE_DL_CALENDAR @@ -275,7 +295,7 @@ PHP_MINFO_FUNCTION(calendar) php_info_print_table_end(); } -static void _php_cal_info(int cal, zval **ret) +static void _php_cal_info(int cal, zval **ret TSRMLS_DC) { zval *months, *smonths; int i; @@ -290,23 +310,23 @@ static void _php_cal_info(int cal, zval **ret) array_init(smonths); for (i = 1; i <= calendar->num_months; i++) { - add_index_string(months, i, calendar->month_name_long[i], 1); - add_index_string(smonths, i, calendar->month_name_short[i], 1); - } - add_assoc_zval(*ret, "months", months); - add_assoc_zval(*ret, "abbrevmonths", smonths); - add_assoc_long(*ret, "maxdaysinmonth", calendar->max_days_in_month); - add_assoc_string(*ret, "calname", calendar->name, 1); - add_assoc_string(*ret, "calsymbol", calendar->symbol, 1); + add_index_ascii_string(months, i, calendar->month_name_long[i], ZSTR_DUPLICATE); + add_index_ascii_string(smonths, i, calendar->month_name_short[i], ZSTR_DUPLICATE); + } + + add_ascii_assoc_zval(*ret, "months", months); + add_ascii_assoc_zval(*ret, "abbrevmonths", smonths); + add_ascii_assoc_long(*ret, "maxdaysinmonth", calendar->max_days_in_month); + add_ascii_assoc_ascii_string(*ret, "calname", calendar->name, 1); + add_ascii_assoc_ascii_string(*ret, "calsymbol", calendar->symbol, 1); } -/* {{{ proto array cal_info([int calendar]) +/* {{{ proto array cal_info([int calendar]) U Returns information about a particular calendar */ PHP_FUNCTION(cal_info) { long cal = -1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &cal) == FAILURE) { RETURN_FALSE; @@ -320,7 +340,7 @@ PHP_FUNCTION(cal_info) for (i = 0; i < CAL_NUM_CALS; i++) { MAKE_STD_ZVAL(val); - _php_cal_info(i, &val); + _php_cal_info(i, &val TSRMLS_CC); add_index_zval(return_value, i, val); } return; @@ -332,12 +352,12 @@ PHP_FUNCTION(cal_info) RETURN_FALSE; } - _php_cal_info(cal, &return_value); + _php_cal_info(cal, &return_value TSRMLS_CC); } /* }}} */ -/* {{{ proto int cal_days_in_month(int calendar, int month, int year) +/* {{{ proto int cal_days_in_month(int calendar, int month, int year) U Returns the number of days in a month for a given year and calendar */ PHP_FUNCTION(cal_days_in_month) { @@ -366,7 +386,7 @@ PHP_FUNCTION(cal_days_in_month) sdn_next = calendar->to_jd(year, 1 + month, 1); if (sdn_next == 0) { -/* if invalid, try first month of the next year... */ + /* if invalid, try first month of the next year... */ sdn_next = calendar->to_jd(year + 1, 1, 1); } @@ -374,7 +394,7 @@ PHP_FUNCTION(cal_days_in_month) } /* }}} */ -/* {{{ proto int cal_to_jd(int calendar, int month, int day, int year) +/* {{{ proto int cal_to_jd(int calendar, int month, int day, int year) U Converts from a supported calendar to Julian Day Count */ PHP_FUNCTION(cal_to_jd) { @@ -393,7 +413,7 @@ PHP_FUNCTION(cal_to_jd) } /* }}} */ -/* {{{ proto array cal_from_jd(int jd, int calendar) +/* {{{ proto array cal_from_jd(int jd, int calendar) U Converts from Julian Day Count to a supported calendar and return extended information */ PHP_FUNCTION(cal_from_jd) { @@ -423,18 +443,19 @@ PHP_FUNCTION(cal_from_jd) add_assoc_long(return_value, "day", day); add_assoc_long(return_value, "year", year); -/* day of week */ + /* day of week */ dow = DayOfWeek(jd); - add_assoc_long(return_value, "dow", dow); - add_assoc_string(return_value, "abbrevdayname", DayNameShort[dow], 1); - add_assoc_string(return_value, "dayname", DayNameLong[dow], 1); -/* month name */ - add_assoc_string(return_value, "abbrevmonth", calendar->month_name_short[month], 1); - add_assoc_string(return_value, "monthname", calendar->month_name_long[month], 1); + add_ascii_assoc_long(return_value, "dow", dow); + add_ascii_assoc_ascii_string(return_value, "abbrevdayname", DayNameShort[dow], 1); + add_ascii_assoc_ascii_string(return_value, "dayname", DayNameLong[dow], 1); + + /* month name */ + add_ascii_assoc_ascii_string(return_value, "abbrevmonth", calendar->month_name_short[month], 1); + add_ascii_assoc_ascii_string(return_value, "monthname", calendar->month_name_long[month], 1); } /* }}} */ -/* {{{ proto string jdtogregorian(int juliandaycount) +/* {{{ proto string jdtogregorian(int juliandaycount) U Converts a julian day count to a gregorian calendar date */ PHP_FUNCTION(jdtogregorian) { @@ -449,11 +470,11 @@ PHP_FUNCTION(jdtogregorian) SdnToGregorian(julday, &year, &month, &day); snprintf(date, sizeof(date), "%i/%i/%i", month, day, year); - RETURN_STRING(date, 1); + RETURN_ASCII_STRING(date, ZSTR_DUPLICATE); } /* }}} */ -/* {{{ proto int gregoriantojd(int month, int day, int year) +/* {{{ proto int gregoriantojd(int month, int day, int year) U Converts a gregorian calendar date to julian day count */ PHP_FUNCTION(gregoriantojd) { @@ -467,7 +488,7 @@ PHP_FUNCTION(gregoriantojd) } /* }}} */ -/* {{{ proto string jdtojulian(int juliandaycount) +/* {{{ proto string jdtojulian(int juliandaycount) U Convert a julian day count to a julian calendar date */ PHP_FUNCTION(jdtojulian) { @@ -482,11 +503,11 @@ PHP_FUNCTION(jdtojulian) SdnToJulian(julday, &year, &month, &day); snprintf(date, sizeof(date), "%i/%i/%i", month, day, year); - RETURN_STRING(date, 1); + RETURN_ASCII_STRING(date, ZSTR_DUPLICATE); } /* }}} */ -/* {{{ proto int juliantojd(int month, int day, int year) +/* {{{ proto int juliantojd(int month, int day, int year) U Converts a julian calendar date to julian day count */ PHP_FUNCTION(juliantojd) { @@ -595,7 +616,7 @@ static char *heb_number_to_chars(int n, int fl, char **ret) } /* }}} */ -/* {{{ proto string jdtojewish(int juliandaycount [, bool hebrew [, int fl]]) +/* {{{ proto string jdtojewish(int juliandaycount [, bool hebrew [, int fl]]) U Converts a julian day count to a jewish calendar date */ PHP_FUNCTION(jdtojewish) { @@ -628,13 +649,16 @@ PHP_FUNCTION(jdtojewish) efree(yearp); } - RETURN_STRING(hebdate, 1); - + if (UG(unicode) && CALENDAR_G(iso_8859_8_conv)) { + RETURN_U_STRING(CALENDAR_G(iso_8859_8_conv), hebdate, ZSTR_DUPLICATE); + } else { + RETURN_STRING(hebdate, 1); + } } } /* }}} */ -/* {{{ proto int jewishtojd(int month, int day, int year) +/* {{{ proto int jewishtojd(int month, int day, int year) U Converts a jewish calendar date to a julian day count */ PHP_FUNCTION(jewishtojd) { @@ -648,7 +672,7 @@ PHP_FUNCTION(jewishtojd) } /* }}} */ -/* {{{ proto string jdtofrench(int juliandaycount) +/* {{{ proto string jdtofrench(int juliandaycount) U Converts a julian day count to a french republic calendar date */ PHP_FUNCTION(jdtofrench) { @@ -663,11 +687,11 @@ PHP_FUNCTION(jdtofrench) SdnToFrench(julday, &year, &month, &day); snprintf(date, sizeof(date), "%i/%i/%i", month, day, year); - RETURN_STRING(date, 1); + RETURN_ASCII_STRING(date, ZSTR_DUPLICATE); } /* }}} */ -/* {{{ proto int frenchtojd(int month, int day, int year) +/* {{{ proto int frenchtojd(int month, int day, int year) U Converts a french republic calendar date to julian day count */ PHP_FUNCTION(frenchtojd) { @@ -681,7 +705,7 @@ PHP_FUNCTION(frenchtojd) } /* }}} */ -/* {{{ proto mixed jddayofweek(int juliandaycount [, int mode]) +/* {{{ proto mixed jddayofweek(int juliandaycount [, int mode]) U Returns name or number of day of week from julian day count */ PHP_FUNCTION(jddayofweek) { @@ -699,10 +723,10 @@ PHP_FUNCTION(jddayofweek) switch (mode) { case CAL_DOW_SHORT: - RETURN_STRING(daynamel, 1); + RETURN_ASCII_STRING(daynamel, ZSTR_DUPLICATE); break; case CAL_DOW_LONG: - RETURN_STRING(daynames, 1); + RETURN_ASCII_STRING(daynames, ZSTR_DUPLICATE); break; case CAL_DOW_DAYNO: default: @@ -712,7 +736,7 @@ PHP_FUNCTION(jddayofweek) } /* }}} */ -/* {{{ proto string jdmonthname(int juliandaycount, int mode) +/* {{{ proto string jdmonthname(int juliandaycount, int mode) U Returns name of month for julian day count */ PHP_FUNCTION(jdmonthname) { @@ -740,6 +764,11 @@ PHP_FUNCTION(jdmonthname) case CAL_MONTH_JEWISH: /* jewish month */ SdnToJewish(julday, &year, &month, &day); monthname = JewishMonthName[month]; + if (UG(unicode) && CALENDAR_G(iso_8859_8_conv)) { + RETURN_U_STRING(CALENDAR_G(iso_8859_8_conv), monthname, ZSTR_DUPLICATE); + } else { + RETURN_STRING(monthname, 1); + } break; case CAL_MONTH_FRENCH: /* french month */ SdnToFrench(julday, &year, &month, &day); @@ -752,7 +781,7 @@ PHP_FUNCTION(jdmonthname) break; } - RETURN_STRING(monthname, 1); + RETURN_ASCII_STRING(monthname, ZSTR_DUPLICATE); } /* }}} */ diff --git a/ext/calendar/php_calendar.h b/ext/calendar/php_calendar.h index e353fab893..5b261c35b1 100644 --- a/ext/calendar/php_calendar.h +++ b/ext/calendar/php_calendar.h @@ -28,6 +28,17 @@ PHP_FUNCTION(cal_to_jd); PHP_FUNCTION(cal_days_in_month); PHP_FUNCTION(cal_info); +#ifdef ZTS +# include "TSRM.h" +# define CALENDAR_G(v) TSRMG(calendar_globals_id, zend_calendar_globals *, v) +#else +# define CALENDAR_G(v) (calendar_globals.v) +#endif + +ZEND_BEGIN_MODULE_GLOBALS(calendar) + UConverter *iso_8859_8_conv; +ZEND_END_MODULE_GLOBALS(calendar) + #define phpext_calendar_ptr calendar_module_ptr /*