LoginSignup
1
3

More than 5 years have passed since last update.

PHP7.2 の 鬼車(Oniguruma)(mb_ereg_*)の変更点の一部をピックアップ

Last updated at Posted at 2017-12-10

はじめに

mbstring に含まれる 鬼車(Oniguruma)(mb_ereg_*系関数の正規表現ライブラリー)のバージョンが、PHP7.2 から 6.3.0 がベースとなった。(PHP5.6-7.1 は、5.9.5 がベース。)(鬼車 6.0.0 で、 update Unicode data to 8.0.0 となった。(鬼車の履歴))

そのため、以下のスクリプトは、真逆の結果を返す。(https://3v4l.org/NeqNo)

<?php
//echo 'PHP_VERSION: ', PHP_VERSION, "\n";
mb_regex_encoding('UTF-8') || exit("mb_regex_encoding('UTF-8') error.");
foreach (['0085', '180e'] as $hex) {
    $utf8 = mb_convert_encoding(pack('N', hexdec($hex)), 'UTF-8', 'UTF-32BE');
    echo "U+{$hex}", (mb_ereg_match('\A[\s]\z', $utf8) ? ' match \\s !' : '')."\n";
}
foreach (['00ad', '200B'] as $hex) {
    $utf8 = mb_convert_encoding(pack('N', hexdec($hex)), 'UTF-8', 'UTF-32BE');
    echo "U+{$hex}", (mb_ereg_match('\A[[:cntrl:]]\z', $utf8) ? ' match cntrl !' : '')."\n";
}

Output for 7.2.0

U+0085 match \s !
U+180e
U+00ad
U+200B

Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.1.12

U+0085
U+180e match \s !
U+00ad match cntrl !
U+200B match cntrl !

変更点の一部をピックアップ

サポートするUnicode 文字プロパティーが増えた

PCRE(preg_*) のUnicode 文字プロパティ でサポートされていないプロパティを含む、
UTF8, UTF16, UTF32で有効なプロパティ名一覧は、Unicode Properties (from Unicode Version: 8.0.0) を参照

\s([:space:], [:blank:]) は、U+180E が対象外となった。

U+180E (Mongolian Vowel Separator) は、
[:White_Space=Yes:] に含まれないが、
Unicode8.0.0 で、スペースとしてリストされている。

また、PCRE(preg_*) では、 U+180E (Mongolian Vowel Separator) は、space characters 扱いとなっている。
- pcre2.txt
- pcre/pcre2_internal.h?rev=39

```c
/* Character U+180E (Mongolian Vowel Separator) is not included in the list of
spaces in the Unicode file PropList.txt, and Perl does not recognize it as a
space. However, in many other sources it is listed as a space and has been in
PCRE (both APIs) for a long time. */
```
  • php-7.2.0/mbstring/oniguruma/unicode_property_data.c#L2792

    /* PROPERTY: 'Space': POSIX [[:Space:]] */
    static const OnigCodePoint
    CR_Space[] = { 10,
    0x0009, 0x000d,
    0x0020, 0x0020,
    0x0085, 0x0085,
    0x00a0, 0x00a0,
    0x1680, 0x1680,
    0x2000, 0x200a,
    0x2028, 0x2029,
    0x202f, 0x202f,
    0x205f, 0x205f,
    0x3000, 0x3000,
    }; /* END of CR_Space */
    
  • php-7.1.12/mbstring/oniguruma/unicode.c#L2012

    /* 'Space': [[:Space:]] */
    static const OnigCodePoint CR_Space[] = {
      11,
      0x0009, 0x000d,
      0x0020, 0x0020,
      0x0085, 0x0085,
      0x00a0, 0x00a0,
      0x1680, 0x1680,
      0x180e, 0x180e,
      0x2000, 0x200a,
      0x2028, 0x2029,
      0x202f, 0x202f,
      0x205f, 0x205f,
      0x3000, 0x3000
    }; /* CR_Space */
    

[:cntrl:] の対象文字

  • php-7.2/mbstring/oniguruma/unicode_property_data.c#L678

    /* PROPERTY: 'Cntrl': POSIX [[:Cntrl:]] */
    static const OnigCodePoint
    CR_Cntrl[] = { 2,
    0x0000, 0x001f,
    0x007f, 0x009f,
    }; /* END of CR_Cntrl */
    
  • php-7.1.12/mbstring/oniguruma/unicode.c#L517

    /* 'Cntrl': [[:Cntrl:]] */
    static const OnigCodePoint CR_Cntrl[] = {
      19,
      0x0000, 0x001f,
      0x007f, 0x009f,
      0x00ad, 0x00ad,
      0x0600, 0x0603,
      0x06dd, 0x06dd,
      0x070f, 0x070f,
      0x17b4, 0x17b5,
      0x200b, 0x200f,
      0x202a, 0x202e,
      0x2060, 0x2063,
      0x206a, 0x206f,
      0xd800, 0xf8ff,
      0xfeff, 0xfeff,
      0xfff9, 0xfffb,
      0x1d173, 0x1d17a,
      0xe0001, 0xe0001,
      0xe0020, 0xe007f,
      0xf0000, 0xffffd,
      0x100000, 0x10fffd
    }; /* CR_Cntrl */
    

参考

ドキュメント

定義(ソース)

(Onigmo/unicode/name2ctype.h)

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3