| 1 |
#!/bin/sh |
| 2 |
# Ensure that grep -P's \d matches only the 10 ASCII digits. |
| 3 |
# With, grep-3.9, \d would match e.g., the multibyte Arabic digits. |
| 4 |
# The same applied to \D. |
| 5 |
# |
| 6 |
# Copyright (C) 2023-2025 Free Software Foundation, Inc. |
| 7 |
# |
| 8 |
# Copying and distribution of this file, with or without modification, |
| 9 |
# are permitted in any medium without royalty provided the copyright |
| 10 |
# notice and this notice are preserved. |
| 11 |
|
| 12 |
. "${srcdir=.}/init.sh"; path_prepend_ ../src |
| 13 |
require_en_utf8_locale_ |
| 14 |
LC_ALL=en_US.UTF-8 |
| 15 |
export LC_ALL |
| 16 |
require_pcre_ |
| 17 |
|
| 18 |
echo . | grep -qP '(*UTF).' 2>/dev/null \ |
| 19 |
|| skip_ 'PCRE unicode support is compiled out' |
| 20 |
echo 0 | grep -qP '(?aD)\d' \ |
| 21 |
|| skip_ 'PCRE 10.42 and older lack (?aD)' |
| 22 |
|
| 23 |
fail=0 |
| 24 |
|
| 25 |
# $ printf %s ٠١٢٣٤٥٦٧٨٩|od -An -to1 -w10 |sed 's/ /\\/g'; : arabic digits |
| 26 |
# \331\240\331\241\331\242\331\243\331\244 |
| 27 |
# \331\245\331\246\331\247\331\250\331\251 |
| 28 |
printf '\331\240\331\241\331\242\331\243\331\244' > in || framework_failure_ |
| 29 |
printf '\331\245\331\246\331\247\331\250\331\251' >> in || framework_failure_ |
| 30 |
printf '\n' >> in || framework_failure_ |
| 31 |
|
| 32 |
# Ensure that \d matches no Arabic-Indic digits. |
| 33 |
returns_ 1 grep -P '\d' in > out || fail=1 |
| 34 |
compare /dev/null out || fail=1 |
| 35 |
|
| 36 |
# Ensure that ^\D+$ matches all the Arabic-Indic digits. |
| 37 |
grep -P '^\D+$' in > out || fail=1 |
| 38 |
compare in out || fail=1 |
| 39 |
|
| 40 |
# When built with PCRE2 10.43 and newer, one may use (?aD) and (?-aD) |
| 41 |
# to toggle between modes. (?aD) is the default (making \d == [0-9]). |
| 42 |
# (?-aD) relaxes \d, making it match "all" digits. |
| 43 |
# Use mixed digits as input: Arabic-Indic digit zero and ASCII 4. |
| 44 |
printf '\331\2404\n' > in2 || framework_failure_ |
| 45 |
|
| 46 |
returns_ 1 grep -P '\d\d' in2 > out || fail=1 |
| 47 |
compare /dev/null out || fail=1 |
| 48 |
|
| 49 |
grep -P '(?-aD)\d(?aD)\d' in2 > out || fail=1 |
| 50 |
compare in2 out || fail=1 |
| 51 |
|
| 52 |
returns_ 1 grep -P '\d(?-aD)\d' in2 > out || fail=1 |
| 53 |
compare /dev/null out || fail=1 |
| 54 |
|
| 55 |
Exit $fail |