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;

View File

@ -194,7 +194,7 @@ int main(int argc, char* argv[])
malloc_time = (double)(end_time - start_time) / CLOCKS_PER_SEC - free_time;
printf("Performed %d interleaved malloc/free operations\n", num_iterations);
printf("Performed %lu interleaved malloc/free operations\n", (unsigned long)num_iterations);
printf("Total malloc time (estimated): %.6f seconds\n", malloc_time);
printf("Total free time : %.6f seconds\n", free_time);
printf("Average time per operation : %.9f seconds\n", (malloc_time + free_time) / num_iterations);