Debian Codegraph @

test/regnul1.awk

raw
1 # From [email protected] Thu May 29 09:07:56 IDT 2014
2 # Article: 8400 of comp.lang.awk
3 # X-Received: by 10.236.81.99 with SMTP id l63mr3912466yhe.3.1401224812642;
4 # Tue, 27 May 2014 14:06:52 -0700 (PDT)
5 # X-Received: by 10.140.37.148 with SMTP id r20mr578874qgr.0.1401224812310; Tue,
6 # 27 May 2014 14:06:52 -0700 (PDT)
7 # Path: eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!hl10no6493021igb.0!news-out.google.com!gi6ni15574igc.0!nntp.google.com!hl10no6493018igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
8 # Newsgroups: comp.lang.awk
9 # Date: Tue, 27 May 2014 14:06:52 -0700 (PDT)
10 # Complaints-To: [email protected]
11 # Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=85.253.50.165;
12 # posting-account=zNhVLgoAAACsg-WfVe_or2VV7loUhx8H
13 # NNTP-Posting-Host: 85.253.50.165
14 # User-Agent: G2/1.0
15 # MIME-Version: 1.0
16 # Message-ID: <[email protected]>
17 # Subject: \0 character can't be implement inside regexp in some cases?
18 # From: [email protected]
19 # Injection-Date: Tue, 27 May 2014 21:06:52 +0000
20 # Content-Type: text/plain; charset=ISO-8859-1
21 # Xref: news.eternal-september.org comp.lang.awk:8400
22 #
23 # Hello,
24 #
25 # while doing some experiments with the gawk(4.1.1) i was found problem in implementing character \x00 inside regexp for two cases:
26 #
27 # str~/\0/
28 #
29 # and
30 #
31 # switch ( str ) { case /\0/: ... }
32 #
33 # the following code try to match given string(=="\x00") with the regexp /^\0$/ using different ways provided by gawk:
34 #
35 func _chm(t) {
36 _ch("match()",match(t,/^\0$/))
37 _ch("split()",split(t,A,/^\0$/)>1)
38 _ch("patsplit()",patsplit(t,A,/^\0$/))
39 _ch("gsub()",gsub(/^\0$/,"&",t))
40 _ch("sub()",sub(/^\0$/,"&",t))
41 _ch("gensub()",!gensub(/^\0$/,"","G",t))
42 _ch("str~/rexp/",t~/^\0$/)
43 a=0; switch ( t ) { case /^\0$/: a=1 }; _ch("switch-case //",a) }
44
45 func _ch(fn,bool) {
46 print substr(fn ": ",1,16) (bool ? "+" : "-") }
47
48 BEGIN{ _chm("\000") }
49 #
50 # output:
51 #
52 # > gawk -f _null.gwk
53 # match(): +
54 # split(): +
55 # patsplit(): +
56 # gsub(): +
57 # sub(): +
58 # gensub(): +
59 # str~/rexp/: -
60 # switch-case //: -
61 #
62 # can someone explain me:
63 #
64 # why in case using match(), split(), patsplit(), gsub(), sub() and gensub() the given string "\x00" matches with the /^\0$/
65 #
66 # but in cases:
67 #
68 # "\x00"~/^\0$/
69 #
70 # and
71 #
72 # switch ( "\x00" ) { case /^\0$/: doesn't match? }
73 #
74 #
75 # thank You
76 #
77 #
78 # GNU Awk 4.1.1, API: 1.1 (GNU MPFR 3.1.0-p8, GNU MP 5.0.2)
79 # Copyright (C) 1989, 1991-2014 Free Software Foundation.
80 # downloaded from ezwinports
81 #
82 # windows 7x64; cmd
83 #
84 #