Skip to content

Commit beb6707

Browse files
committed
ct 1.651 - tweaked proc containsWithValidBoundaries
1 parent a2027a6 commit beb6707

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

mostfiles/ctwig.nim

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import std/[os, strutils, paths, tables, parseopt]
3434
# mies
3535

3636
var
37-
versionfl: float = 1.65
37+
versionfl: float = 1.651
3838
codetwigst: string = "CodeTwig"
3939
ct_projectsdirst: string = "projects"
4040
dec_list_suffikst: string = "dec_list.dat"
@@ -482,7 +482,7 @@ proc substringInSequence(stringsq: seq[string]; substringst: string): bool =
482482

483483

484484

485-
proc containsWithValidBoundaries(tekst, subst: string; beforesq, aftersq: seq[string], allowfirstlastbo: bool): bool =
485+
proc containsWithValidBoundaries(tekst, subst: string; beforesq, aftersq: seq[string]; allowfirstbo, allowlastbo: bool): bool =
486486

487487
# subst within tekst has valid bounds if before and after strings are in seqs
488488
# allowfirstlastbo means that the subst is allowed as first or last part of tekst
@@ -500,27 +500,40 @@ proc containsWithValidBoundaries(tekst, subst: string; beforesq, aftersq: seq[st
500500
aftokbo = false
501501
skipbo = false
502502

503+
wisp("tekst = ", tekst)
504+
wisp("subst =", subst)
505+
wisp("beforesq = ", $beforesq)
506+
wisp("aftersq = ", $aftersq)
507+
wisp("tekst.len = ", tekst.len)
508+
wisp("allowfirstbo = ", allowfirstbo)
509+
wisp("allowlastbo = ", allowlastbo)
510+
511+
503512
substartit = tekst.find(subst)
504-
subendit = substartit + subst.len
513+
subendit = substartit + subst.len - 1
505514

506-
wisp("tekst.len = ", tekst.len)
507515
wisp("substartit = ", substartit)
508516
wisp("subendit = ", subendit)
509-
wisp("allowfirstlastbo = ", allowfirstlastbo)
517+
510518

511519
if substartit >= 0:
512520

513-
if allowfirstlastbo:
521+
if allowfirstbo:
514522
if substartit == 0:
515523
forokbo = true
524+
else:
525+
if substartit == 0:
526+
skipbo = true
527+
528+
if allowlastbo:
516529
if subendit == tekst.len - 1:
517530
aftokbo = true
518531
else:
519-
if substartit == 0 or subendit == tekst.len - 1:
520-
# no further testing needed
532+
if subendit == tekst.len - 1:
521533
skipbo = true
522534

523-
if not forokbo and not (substartit == 0) and not skipbo:
535+
536+
if not forokbo and not skipbo:
524537
wisp "in for"
525538
for forst in beforesq:
526539
forstartit = substartit - forst.len
@@ -531,18 +544,20 @@ proc containsWithValidBoundaries(tekst, subst: string; beforesq, aftersq: seq[st
531544
forokbo = true
532545
break
533546

534-
if not aftokbo and not (subendit == tekst.len - 1) and not skipbo:
547+
if not aftokbo and not skipbo:
535548
wisp "in aft"
536549
for aftst in aftersq:
537550
aftendit = subendit + aftst.len
538551
wisp("aftendit = ", aftendit)
539-
if aftendit <= tekst.len:
540-
aftslicest = tekst[subendit .. aftendit - 1]
552+
if aftendit < tekst.len:
553+
aftslicest = tekst[subendit + 1 .. aftendit]
541554
wisp("aftslicest = ", aftslicest)
542555
if aftslicest == aftst:
543556
aftokbo = true
544557
break
545558

559+
wisp("forokbo =", forokbo)
560+
wisp("aftokbo = ", aftokbo)
546561

547562
wispbo = false
548563

@@ -823,7 +838,7 @@ proc createDeclarationList(proj_def_pathst: string) =
823838

824839
if sline.len > 2 and not incommentblockbo and not commentclosingbo and not singlecommentbo:
825840
#if sline.contains(declare2st) and not sline.contains("\"" & declare2st & "\""):
826-
if sline.containsWithValidBoundaries(declare2st, @[".", "(", " ", "=", "["], @["(", "=", " ", "."], false) :
841+
if sline.containsWithValidBoundaries(declare2st, @[".", "(", " ", "=", "["], @["(", "=", " ", "."], false, true) :
827842

828843
foundcountit += 1
829844

@@ -2414,5 +2429,5 @@ else:
24142429
if true:
24152430
var tekst = "aapnootmies"
24162431

2417-
echo "containsWithValidBoundaries = ", $containsWithValidBoundaries(tekst, "noot", @["p"], @["mie"], false)
2432+
echo "containsWithValidBoundaries = ", $containsWithValidBoundaries(tekst, "noot", @["p"], @["mi"], true, true)
24182433

0 commit comments

Comments
 (0)