| 1 |
#! /bin/sh |
| 2 |
# From [email protected] Sun Apr 22 20:15:25 2007 |
| 3 |
# Date: Thu, 19 Apr 2007 17:09:02 +0300 |
| 4 |
# From: Pekka Pessi <[email protected]> |
| 5 |
# X-Face: #V(jdpv[lI!TNUU=2*oh:="#suS*ponXW"yr6G;~L}<xZn_2^0)V{jqdc4y}@2b]ffd}SY# |
| 6 |
# :9||1pew85O,WjiYA"6C7bW^zt^+.{b#B{lEE+4$9lrXL(55g}dU>uZ\JfD\"IG#G{j`hZI;=DmT\H |
| 7 |
# pfDMyJ`i=:M;BM3R.`[>P^ER8+]i |
| 8 |
# Subject: UTF-8 locale and \n in regexps |
| 9 |
# To: [email protected] |
| 10 |
# Cc: [email protected] |
| 11 |
# Message-id: <[email protected]> |
| 12 |
# MIME-version: 1.0 |
| 13 |
# Content-type: multipart/mixed; boundary="=-=-=" |
| 14 |
# |
| 15 |
# --=-=-= |
| 16 |
# |
| 17 |
# Hello, |
| 18 |
# |
| 19 |
# It looks like regexp with \n in [^] behaves badly if locale has |
| 20 |
# an UTF-8 ctype. |
| 21 |
# |
| 22 |
# It looks like if there is \n and an range without \n, like /\n[^x\n]foo/, |
| 23 |
# and first \n ends an even-numbered line within the string, regexp |
| 24 |
# does not match. |
| 25 |
# |
| 26 |
# Please see the attached script for an demonstration. |
| 27 |
# |
| 28 |
# --Pekka Pessi |
| 29 |
# |
| 30 |
# |
| 31 |
# --=-=-= |
| 32 |
# Content-Disposition: inline; filename=gawk-test |
| 33 |
# |
| 34 |
#! /bin/sh |
| 35 |
|
| 36 |
AWK=${AWK:-../gawk} |
| 37 |
|
| 38 |
# April 2010: Remove UNKNOWN, causes spurious failures on some systems |
| 39 |
for LC in C POSIX en_US.ISO-8859-1 en_US.UTF-8 #UNKNOWN |
| 40 |
do |
| 41 |
export LC_ALL=$LC 2>/dev/null |
| 42 |
cat <<EOF | |
| 43 |
line1 |
| 44 |
line2 |
| 45 |
line3 |
| 46 |
line4 |
| 47 |
line5 |
| 48 |
line6 |
| 49 |
line7 |
| 50 |
line8 |
| 51 |
line9 |
| 52 |
EOF |
| 53 |
$AWK --posix ' |
| 54 |
BEGIN { RS="\0"; } |
| 55 |
{ |
| 56 |
if (match($0, /\n[^2\n]*2/)) { got2=1; } else { print "no match 2"; } |
| 57 |
if (match($0, /\n[^3\n]*3/)) { got3=1; } else { print "no match 3"; } |
| 58 |
if (match($0, /\n[^4\n]*4/)) { got4=1; } else { print "no match 4"; } |
| 59 |
if (match($0, /\n[^5\t]*5/)) { got5=1; } else { print "no match 5"; } |
| 60 |
if (match($0, /\n[^6\n]*6/)) { got6=1; } else { print "no match 6"; } |
| 61 |
if (match($0, /\n[a-z]*7\n/)){ got7=1; } else { print "no match 7"; } |
| 62 |
if (match($0, /\n[^8\n]*8/)) { got8=1; } else { print "no match 8"; } |
| 63 |
if (match($0, /8.[^9\n]+9/)) { got9=1; } else { print "no match 9"; } |
| 64 |
} |
| 65 |
|
| 66 |
END { exit(!(got2 && got3 && got4 && got5 && got6 && got7 && got8 && got9)); } |
| 67 |
' || { |
| 68 |
echo LC_ALL=$LC_ALL FAILED |
| 69 |
exit 1 |
| 70 |
} |
| 71 |
echo LC_ALL=$LC_ALL passed |
| 72 |
done |
| 73 |
# |
| 74 |
# --=-=-=-- |
| 75 |
# |