updated gensub to support the occurrence number (the third argument)
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-08-30 22:51:23 +09:00
parent 311e7e3580
commit 0f59ab4a94
5 changed files with 66 additions and 38 deletions

View File

@ -196,6 +196,29 @@ function main()
tap_ensure (z, @r"x\&ax", @SCRIPTNAME, @SCRIPTLINE);
}
## gensub
{
@local x;
x = gensub(/(tiger|dog)/, "\\1-\\1", "g", "the tiger pounces on the dog");
tap_ensure (x, "the tiger-tiger pounces on the dog-dog", @SCRIPTNAME, @SCRIPTLINE);
x = gensub(/(tiger|dog)/, "\\1-\\1", 'G', "the tiger pounces on the dog");
tap_ensure (x, "the tiger-tiger pounces on the dog-dog", @SCRIPTNAME, @SCRIPTLINE);
x = gensub(/(tiger|dog)/, "\\1-\\1", 'G', @b"the tiger pounces on the dog");
tap_ensure (x, @b"the tiger-tiger pounces on the dog-dog", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (hawk::typename(x), "mbs", @SCRIPTNAME, @SCRIPTLINE);
x = gensub(/(tiger|dog)/, "\\1-\\1", 1, "the tiger pounces on the dog");
tap_ensure (x, "the tiger-tiger pounces on the dog", @SCRIPTNAME, @SCRIPTLINE);
x = gensub(/(tiger|dog)/, "\\1-\\1", 2, "the tiger pounces on the dog");
tap_ensure (x, "the tiger pounces on the dog-dog", @SCRIPTNAME, @SCRIPTLINE);
## 0 as the third argument is same as not passing "g"/"G" or a positive occurrence number.
x = gensub(/(tiger|dog)/, "\\1-\\1", 0, "the tiger pounces on the dog");
tap_ensure (x, "the tiger-tiger pounces on the dog", @SCRIPTNAME, @SCRIPTLINE);
x = gensub(/(tiger|dog)/, "\\1-\\1", "", "the tiger pounces on the dog");
tap_ensure (x, "the tiger-tiger pounces on the dog", @SCRIPTNAME, @SCRIPTLINE);
x = gensub(/(tiger|dog)/, "\\1-\\1", 10, "the tiger pounces on the dog");
tap_ensure (x, "the tiger pounces on the dog", @SCRIPTNAME, @SCRIPTLINE);
}
{
@local pi, e, tmp;