Consolidate common code for the sub() method and function.

.gitlab-ci.yml not found in this commit