Refactoring replace functions of basic_string_t.