}
/* }}} */
- static const enum mbfl_no_encoding php_mb_unsupported_no_encoding_list[] = {
- mbfl_no_encoding_pass,
- mbfl_no_encoding_auto,
- mbfl_no_encoding_wchar,
- mbfl_no_encoding_byte2be,
- mbfl_no_encoding_byte2le,
- mbfl_no_encoding_byte4be,
- mbfl_no_encoding_byte4le,
- mbfl_no_encoding_base64,
- mbfl_no_encoding_uuencode,
- mbfl_no_encoding_html_ent,
- mbfl_no_encoding_qprint,
- mbfl_no_encoding_utf7,
- mbfl_no_encoding_utf7imap,
- mbfl_no_encoding_2022kr,
- mbfl_no_encoding_jis,
- mbfl_no_encoding_2022jp,
- mbfl_no_encoding_2022jpms,
- mbfl_no_encoding_jis_ms,
- mbfl_no_encoding_2022jp_2004,
- mbfl_no_encoding_2022jp_kddi,
- mbfl_no_encoding_cp50220,
- mbfl_no_encoding_cp50220raw,
- mbfl_no_encoding_cp50221,
- mbfl_no_encoding_cp50222
- };
-
- static inline int php_mb_is_unsupported_no_encoding(enum mbfl_no_encoding no_enc)
- {
- int i;
- int size = sizeof(php_mb_unsupported_no_encoding_list)/sizeof(php_mb_unsupported_no_encoding_list[0]);
-
- for (i = 0; i < size; i++) {
-
- if (no_enc == php_mb_unsupported_no_encoding_list[i]) {
- return 1;
- }
-
- }
-
- return 0;
- }
-
- static const enum mbfl_no_encoding php_mb_no_encoding_unicode_list[] = {
- mbfl_no_encoding_utf8,
- mbfl_no_encoding_utf8_docomo,
- mbfl_no_encoding_utf8_kddi_a,
- mbfl_no_encoding_utf8_kddi_b,
- mbfl_no_encoding_utf8_sb,
- mbfl_no_encoding_ucs4,
- mbfl_no_encoding_ucs4be,
- mbfl_no_encoding_ucs4le,
- mbfl_no_encoding_utf32,
- mbfl_no_encoding_utf32be,
- mbfl_no_encoding_utf32le,
- mbfl_no_encoding_ucs2,
- mbfl_no_encoding_ucs2be,
- mbfl_no_encoding_ucs2le,
- mbfl_no_encoding_utf16,
- mbfl_no_encoding_utf16be,
- mbfl_no_encoding_utf16le
- };
-
- static inline int php_mb_is_no_encoding_unicode(enum mbfl_no_encoding no_enc)
- {
- int i;
- int size = sizeof(php_mb_no_encoding_unicode_list)/sizeof(php_mb_no_encoding_unicode_list[0]);
-
- for (i = 0; i < size; i++) {
-
- if (no_enc == php_mb_no_encoding_unicode_list[i]) {
- return 1;
- }
-
- }
-
- return 0;
- }
-
- static const enum mbfl_no_encoding php_mb_no_encoding_utf8_list[] = {
- mbfl_no_encoding_utf8,
- mbfl_no_encoding_utf8_docomo,
- mbfl_no_encoding_utf8_kddi_a,
- mbfl_no_encoding_utf8_kddi_b,
- mbfl_no_encoding_utf8_sb
- };
-
- static inline int php_mb_is_no_encoding_utf8(enum mbfl_no_encoding no_enc)
- {
- int i;
- int size = sizeof(php_mb_no_encoding_utf8_list)/sizeof(php_mb_no_encoding_utf8_list[0]);
-
- for (i = 0; i < size; i++) {
-
- if (no_enc == php_mb_no_encoding_utf8_list[i]) {
- return 1;
- }
-
- }
-
- return 0;
- }
-
+static inline int php_mb_check_code_point(long cp)
+{
+ enum mbfl_no_encoding no_enc;
+ char* buf;
+ char buf_len;
+
+ no_enc = MBSTRG(current_internal_encoding)->no_encoding;
+
+ if (php_mb_is_no_encoding_utf8(no_enc)) {
+
+ if ((cp > 0 && 0xd800 > cp) || (cp > 0xdfff && 0x110000 > cp)) {
+ return 1;
+ }
+
+ return 0;
+ } else if (php_mb_is_no_encoding_unicode(no_enc)) {
+
+ if (0 > cp || cp > 0x10ffff) {
+ return 0;
+ }
+
+ return 1;
+
+ // backward compatibility
+ } else if (php_mb_is_unsupported_no_encoding(no_enc)) {
+ return cp < 0xffff && cp > 0x0;
+ }
+
+ if (cp < 0x100) {
+ buf_len = 1;
+ buf = (char *) safe_emalloc(buf_len, 1, 1);
+ buf[0] = cp;
+ buf[1] = 0;
+ } else if (cp < 0x10000) {
+ buf_len = 2;
+ buf = (char *) safe_emalloc(buf_len, 1, 1);
+ buf[0] = cp >> 8;
+ buf[1] = cp & 0xff;
+ buf[2] = 0;
+ } else if (cp < 0x1000000) {
+ buf_len = 3;
+ buf = (char *) safe_emalloc(buf_len, 1, 1);
+ buf[0] = cp >> 16;
+ buf[1] = (cp >> 8) & 0xff;
+ buf[2] = cp & 0xff;
+ buf[3] = 0;
+ } else {
+ buf_len = 4;
+ buf = (char *) safe_emalloc(buf_len, 1, 1);
- buf[0] = cp >> 24;
++ buf[0] = cp >> 24;
+ buf[1] = (cp >> 16) & 0xff;
+ buf[2] = (cp >> 8) & 0xff;
+ buf[3] = cp & 0xff;
+ buf[4] = 0;
+ }
+
+ if (php_mb_check_encoding(buf, buf_len, NULL)) {
+ efree(buf);
+
+ return 1;
+ }
+
+ efree(buf);
+
+ return 0;
+}
+
/* {{{ proto mixed mb_substitute_character([mixed substchar])
Sets the current substitute_character or returns the current substitute_character */
PHP_FUNCTION(mb_substitute_character)
string.val = (unsigned char *)str;
string.len = str_len;
-
+ if ((from < 0) || (width < 0)) {
+ swidth = mbfl_strwidth(&string);
+ }
+
+ if (from < 0) {
+ from += swidth;
+ }
++
if (from < 0 || (size_t)from > str_len) {
php_error_docref(NULL, E_WARNING, "Start position is out of range");
RETURN_FALSE;