diff options
| author | Andrei Zmievski <andrei@php.net> | 2005-08-18 22:33:23 +0000 |
|---|---|---|
| committer | Andrei Zmievski <andrei@php.net> | 2005-08-18 22:33:23 +0000 |
| commit | fe71ae29d98d98ef65b89c15bab58d6b3db57957 (patch) | |
| tree | e6c4a92d1366eab0e464c62add29c79c7c473e96 /Zend/zend_unicode.h | |
| parent | 07e355fc9c68b6283463a3cb13562a4cdc2fc43a (diff) | |
| download | php-git-fe71ae29d98d98ef65b89c15bab58d6b3db57957.tar.gz | |
- Implement zend_codepoint_to_uchar().
- Rename and fix zend_get_unified_string_type() so that it does not
allow mixing of binary and Unicode types.
Diffstat (limited to 'Zend/zend_unicode.h')
| -rw-r--r-- | Zend/zend_unicode.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Zend/zend_unicode.h b/Zend/zend_unicode.h index 950dc7c1fd..6de5538936 100644 --- a/Zend/zend_unicode.h +++ b/Zend/zend_unicode.h @@ -71,6 +71,24 @@ static inline UChar32 zend_get_codepoint_at(UChar *str, int32_t length, int32_t return c; } +/* + * Convert a single codepoint to UChar sequence (1 or 2). + * The UChar buffer is assumed to be large enough. + */ +static inline int zend_codepoint_to_uchar(UChar32 codepoint, UChar *buf) +{ + if (U_IS_BMP(codepoint)) { + *buf++ = (UChar) codepoint; + return 1; + } else if (codepoint <= UCHAR_MAX_VALUE) { + *buf++ = (UChar) U16_LEAD(codepoint); + *buf++ = (UChar) U16_TRAIL(codepoint); + return 2; + } else { + return 0; + } +} + #define ZEND_U_CONVERTER(c) ((c)?(c):UG(fallback_encoding_conv)) #define USTR_FREE(ustr) do { if (ustr) { efree(ustr); } } while (0); |
