mbstring関数の"auto"指定(再び)
古い話を再燃させて恐縮ですが。
前回は「php_mb_default_identify_list_*」の並び順を無理やり変更する事で実現したんだけど(あまり)実用的では無かった。
"auto"が指定された場合の検出順を(ずーっと前から)何とかしたいと思ってました。ようやくタコさんパッチを作成。
--- php-4.4.2,orig/ext/mbstring/mbstring.c 2006-01-01 22:46:54.000000000 +0900 +++ php-4.4.2/ext/mbstring/mbstring.c 2006-02-06 21:09:49.000000000 +0900 @@ -396,8 +396,13 @@ enum mbfl_no_encoding *identify_list; int identify_list_size; - identify_list = MBSTRG(default_detect_order_list); - identify_list_size = MBSTRG(default_detect_order_list_size); + identify_list = MBSTRG(current_detect_order_list); + identify_list_size = MBSTRG(current_detect_order_list_size); + + if (identify_list_size <= 0) { + identify_list = MBSTRG(default_detect_order_list); + identify_list_size = MBSTRG(default_detect_order_list_size); + } /* copy the value string for work */ if (value[0]=='"' && value[value_length-1]=='"' && value_length>2) { @@ -520,8 +525,13 @@ enum mbfl_no_encoding *identify_list; int identify_list_size; - identify_list = MBSTRG(default_detect_order_list); - identify_list_size = MBSTRG(default_detect_order_list_size); + identify_list = MBSTRG(current_detect_order_list); + identify_list_size = MBSTRG(current_detect_order_list_size); + + if (identify_list_size <= 0) { + identify_list = MBSTRG(default_detect_order_list); + identify_list_size = MBSTRG(default_detect_order_list_size); + } target_hash = Z_ARRVAL_P(array); zend_hash_internal_pointer_reset(target_hash);
(これを適用すると)"auto"が指定された場合、mbstring.detect_orderで定義した値に置き換えて処理します。
mbstring.detect_orderの値が"auto"(とか未定義)の場合、今まで通りの動作になります。
"auto"の検出順を(部分的に)変更したい場合、mb_detect_order関数を使えば動的に変える事が可能です。
コレでmb_detect_order関数をカマしてたトコが全て"auto"で書けるようになる。。。くだらねー。_| ̄|○