Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8bee489

Browse files
committed
better deal with nonregular exps
1 parentf0da1db commit8bee489

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

‎pike.c‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
Copyright 2007-2009 Russ Cox. All Rights Reserved.
33
Copyright 2020-2021 Kyryl Melekhin. All Rights Reserved.
44
Use of this source code is governed by a BSD-style
@@ -422,7 +422,7 @@ int re_comp(rcode *prog, const char *re, int nsubs)
422422
prog->splits= (scnt-SPLIT) /2;
423423
prog->len=icnt+2;
424424
prog->presub=sizeof(rsub)+(sizeof(char*)* (nsubs+1)*2);
425-
prog->sub=prog->presub* (prog->len-prog->splits+4);
425+
prog->sub=prog->presub* (prog->len-prog->splits+3);
426426
prog->sparsesz=scnt;
427427
returnRE_SUCCESS;
428428
}
@@ -431,7 +431,8 @@ int re_comp(rcode *prog, const char *re, int nsubs)
431431
if (freesub) \
432432
{ s1 = freesub; freesub = s1->freesub; copy } \
433433
else \
434-
{ s1 = (rsub*)&nsubs[suboff+=rsubsize]; init } \
434+
{ if (suboff == prog->sub) suboff = 0; \
435+
s1 = (rsub*)&nsubs[suboff]; suboff += rsubsize; init } \
435436

436437
#definedecref(csub) \
437438
if (--csub->ref == 0) { \
@@ -562,7 +563,7 @@ clistidx = nlistidx; \
562563

563564
intre_pikevm(rcode*prog,constchar*s,constchar**subp,intnsubp)
564565
{
565-
intrsubsize=prog->presub,suboff=rsubsize;
566+
intrsubsize=prog->presub,suboff=0;
566567
intspc,i,j,c,*npc,osubp=nsubp*sizeof(char*);
567568
intsi=0,clistidx=0,nlistidx,mcont=MATCH;
568569
constchar*sp=s,*_sp=s;
@@ -595,13 +596,11 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
595596
matched:
596597
nlist[nlistidx++].pc=&mcont;
597598
if (npc!=&mcont) {
598-
if (matched) {
599+
if (matched)
599600
decref(matched)
600-
suboff=0;
601-
}
602601
matched=nsub;
603602
}
604-
if ((sp==_sp||nlistidx==1)&&matched->sub[nsubp/2]) {
603+
if (sp==_sp||nlistidx==1) {
605604
for (i=0,j=i;i<nsubp;i+=2,j++) {
606605
subp[i]=matched->sub[j];
607606
subp[i+1]=matched->sub[nsubp /2+j];

‎test.sh‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,21 @@ aaaaa(aa)aa(aa(a)a)?aa
156156
\\\\\\\\\\\\\\\\<
157157
[^a]*b
158158
^(.+):([0-9]+):(.+)
159+
^(.+):([0-9]+).(.+)
160+
^(.+):([0-9]+).(.+){2,5}
159161
^(.+):([0-9]+):(.+)
162+
^(.+):([0-9]+).(.+)
160163
^(.+):([0-9]+):(.+)
161164
^(.+):([0-9]+):(.+)(.+)
162165
(.*):([0-9]*):(.*)
163166
(.*):([0-9]*)( ):((.*)+)
164167
(((aaa+)+)bb*)(.*):([0-9]*):(.+)
165168
^(.+):([0-9]+):(.{8})+
166169
^(.+):([0-9]+):((aaaa)|(.+))\"
170+
[0-9]+.(.*)
171+
[0-9]+.(.*)
172+
([0-9])+.(.*)
173+
(([0-9])+)(.)(.*)
167174
"
168175
input="\
169176
abcdef
@@ -321,14 +328,21 @@ xabcx
321328
\\\\\\\\<
322329
hhagbdbdbjsjjjda..b
323330
userspace-api/media/v4l/vbi_625.svg:98: :34bstroke-linejoin:m;stroke-miteit:10;stroke-day:n;se-ty:1\"
331+
userspace-api/media/v4l/vbi_625.svg:98: :34bstroke-linejoin:m;stroke-miteit:10;stroke-day:n;se-ty:1\"
332+
userspace-api/media/v4l/vbi_625.svg:98: :34bstroke-linejoin:m;stroke-miteit:10;stroke-day:n;se-ty:1\"
324333
h:98: :3234434butt;stroke-linejoin:miter;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1\"
325334
h:98: :3234utt;strokeliin:miter;stroke-mirlimit:10;stroke-dasharray:none;stroke-opacity:1n\"
326335
h:98: :3234utt;strokeliin:miter;stroke-mirlimit:10;stroke-dasharray:none;stroke-opacity:1n\"
327336
h:98: :3234utt;strokeliin:miter;stroke-mirlimit:10;stroke-dasharray:none;stroke-opacity:1n\"
328337
h:98: :3234utt;strokeliin:miter;stroke-mirlimit:10;stroke-dasharray:none;stroke-opacity:1n\"
338+
h:98: :3234utt;strokeliin:miter;stroke-mirlimit:10;stroke-dasharray:none;stroke-opacity:1n\"
329339
aaaaabb grt:123:....
330340
h:98: :3234utt;strokeliin:miter;stroke-mirlimit:10;stroke-dasharray:none;stroke-opacity:1n\"
331341
h:98: :3234utt;strokeliin:miter;stroke-mirlimit:10;stroke-dasharray:none;stroke-opacity:1n\"
342+
650-253-0001
343+
650-253-000123434-45551221
344+
650-253-000123434-45551221
345+
650-253-000123434-455512213224hsaqer
332346
"
333347
expect="\
334348
(0,3)
@@ -486,14 +500,21 @@ expect="\
486500
(2,5)
487501
(3,9)
488502
(0,102)(0,35)(36,38)(39,102)
503+
(0,102)(0,77)(78,80)(81,102)
504+
(0,102)(0,77)(78,80)(101,102)
489505
(0,103)(0,1)(2,4)(5,103)
506+
(0,93)(0,89)(90,91)(92,93)
490507
(0,93)(0,1)(2,4)(5,93)
491508
(0,93)(0,1)(2,4)(5,92)(92,93)
492509
(0,93)(0,1)(2,4)(5,93)
493510
(0,93)(0,4)(5,5)(5,8)(9,93)(9,93)
494511
(0,20)(0,7)(0,5)(0,5)(7,11)(12,15)(16,20)
495512
(0,93)(0,1)(2,4)(85,93)
496513
(0,93)(0,1)(2,4)(5,92)(?,?)(5,92)
514+
(0,12)(4,12)
515+
(0,26)(4,26)
516+
(0,26)(2,3)(4,26)
517+
(0,36)(0,3)(2,3)(3,4)(4,36)
497518
(0,0)
498519
"
499520

@@ -507,12 +528,16 @@ printf '%s\n' "$regex" | while read re; do
507528
exp=$(printf'%s\n'"$expect"| awk -v c=$c'BEGIN{ RS = "" ; FS = "\n" }{print $c}')
508529
var=$(./a.out"$re""$inp")
509530
if ["$1" ];then
510-
printf'%s\n'"$var"
531+
printf'%s\n'"$var"
511532
fi
512533
var1=$(printf'%s\n'"$var"| tail -1)
513534
if [!"$exp"="$var1" ];then
514535
printf'%s\n'"fail test$c regex:$re input:$inp expect:$exp output:$var1"
515-
exit 1
536+
if [!"$1"== 1 ];then
537+
exit 1
538+
fi
539+
c=$((c+1))
540+
continue
516541
fi
517542
time=$(printf'%s\n'"$var"| tail -2| head -n1)
518543
printf'%s\n'"pass test$c regex:$re input:$inp expect:$exp output:$var1$time"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp