(UCHAR32), and zend_unicode_to_ascii() function.
# define GLOBAL_CONSTANTS_TABLE EG(zend_constants)
#endif
-#ifndef __GNUC__
ZEND_API zstr null_zstr;
ZEND_API zstr empty_zstr;
-#endif
#if defined(ZEND_WIN32) && ZEND_DEBUG
BOOL WINAPI IsDebuggerPresent(VOID);
{
unicode_globals->unicode = 0;
unicode_globals->utf8_conv = NULL;
+ unicode_globals->ascii_conv = NULL;
unicode_globals->fallback_encoding_conv = NULL;
unicode_globals->runtime_encoding_conv = NULL;
unicode_globals->output_encoding_conv = NULL;
unicode_globals->http_input_encoding_conv = NULL;
unicode_globals->filesystem_encoding_conv = NULL;
zend_set_converter_encoding(&unicode_globals->utf8_conv, "UTF-8");
+ zend_set_converter_encoding(&unicode_globals->ascii_conv, "US-ASCII");
+ zend_set_converter_error_mode(unicode_globals->ascii_conv, ZEND_FROM_UNICODE, ZEND_CONV_ERROR_STOP);
unicode_globals->from_error_mode = ZEND_CONV_ERROR_SUBST;
memset(unicode_globals->from_subst_char, 0, 3 * sizeof(UChar));
zend_codepoint_to_uchar(0x3f, unicode_globals->from_subst_char);
if (unicode_globals->utf8_conv) {
ucnv_close(unicode_globals->utf8_conv);
}
+ if (unicode_globals->ascii_conv) {
+ ucnv_close(unicode_globals->ascii_conv);
+ }
zend_hash_destroy(&unicode_globals->flex_compatible);
}
void *v;
} zstr;
-#ifdef __GNUC__
-# define ZSTR(x) ((zstr)(x))
-# define NULL_ZSTR ZSTR((void*)NULL)
-# define EMPTY_ZSTR ZSTR("\0\0")
-#else
extern ZEND_API zstr null_zstr;
extern ZEND_API zstr empty_zstr;
# define ZSTR(x) _to_zstr(x)
# define NULL_ZSTR null_zstr
# define EMPTY_ZSTR empty_zstr
-#endif
#define EMPTY_STR ((UChar*)"\0\0")
Z_TYPE_P(z) = IS_UNICODE; \
}
+#define ZVAL_UCHAR32(z, ch) { \
+ UChar buf[3]; \
+ int buf_len = zend_codepoint_to_uchar(ch, buf); \
+ ZVAL_UNICODEL(z, buf, buf_len, 1); \
+}
+
#define ZVAL_EMPTY_STRING(z) { \
Z_STRLEN_P(z) = 0; \
Z_STRVAL_P(z) = STR_EMPTY_ALLOC(); \
#define RETVAL_EMPTY_STRING() ZVAL_EMPTY_STRING(return_value)
#define RETVAL_UNICODE(u, duplicate) ZVAL_UNICODE(return_value, u, duplicate)
#define RETVAL_UNICODEL(u, l, duplicate) ZVAL_UNICODEL(return_value, u, l, duplicate)
+#define RETVAL_UCHAR32(ch) ZVAL_UCHAR32(return_value, ch)
#define RETVAL_EMPTY_UNICODE() ZVAL_EMPTY_UNICODE(return_value)
#define RETVAL_ZVAL(zv, copy, dtor) ZVAL_ZVAL(return_value, zv, copy, dtor)
#define RETVAL_FALSE ZVAL_BOOL(return_value, 0)
#define RETURN_EMPTY_STRING() { RETVAL_EMPTY_STRING(); return; }
#define RETURN_UNICODE(u, duplicate) { RETVAL_UNICODE(u, duplicate); return; }
#define RETURN_UNICODEL(u, l, duplicate) { RETVAL_UNICODEL(u, l, duplicate); return; }
+#define RETURN_UCHAR32(ch) { RETVAL_UCHAR32(ch); return; }
#define RETURN_EMPTY_UNICODE() { RETVAL_EMPTY_UNICODE(); return; }
#define RETURN_ZVAL(zv, copy, dtor) { RETVAL_ZVAL(zv, copy, dtor); return; }
#define RETURN_FALSE { RETVAL_FALSE; return; }
UConverter *http_input_encoding_conv;/* http input encoding converter */
UConverter *filesystem_encoding_conv;/* default filesystem converter (entries, not contents) */
UConverter *utf8_conv; /* all-purpose UTF-8 converter */
+ UConverter *ascii_conv; /* all-purpose ASCII converter */
uint16_t from_error_mode;
UChar from_subst_char[3];
}
/* }}} */
+/* {{{ zend_unicode_to_ascii */
+ZEND_API char* zend_unicode_to_ascii(const UChar *us, int us_len TSRMLS_DC)
+{
+ char *cs;
+ int cs_len;
+ UErrorCode status = U_ZERO_ERROR;
+
+ zend_convert_from_unicode(UG(ascii_conv), &cs, &cs_len, us, us_len, &status);
+ if (U_FAILURE(status)) {
+ efree(cs);
+ return NULL;
+ }
+
+ return cs;
+}
+/* }}} */
+
/* {{{ zend_raise_conversion_error_ex */
ZEND_API void zend_raise_conversion_error_ex(char *message, UConverter *conv, zend_conv_direction dir, int error_char_offset, int use_exception TSRMLS_DC)
{
ZEND_API int zend_convert_to_unicode(UConverter *conv, UChar **target, int *target_len, const char *source, int source_len, UErrorCode *status);
ZEND_API int zend_convert_from_unicode(UConverter *conv, char **target, int *target_len, const UChar *source, int source_len, UErrorCode *status);
ZEND_API void zend_convert_encodings(UConverter *target_conv, UConverter *source_conv, char **target, int *target_len, const char *source, int source_len, UErrorCode *status);
+ZEND_API char* zend_unicode_to_ascii(const UChar *us, int us_len TSRMLS_DC);
+
ZEND_API int zval_string_to_unicode_ex(zval *string, UConverter *conv TSRMLS_DC);
ZEND_API int zval_string_to_unicode(zval *string TSRMLS_DC);
ZEND_API int zval_unicode_to_string(zval *string, UConverter *conv TSRMLS_DC);