Factored compute of the new size in str_replace