@internal
(string: string, replacement: string | ReplacementFunction)
| 1263 | |
| 1264 | /** @internal */ |
| 1265 | _replaceString(string: string, replacement: string | ReplacementFunction): this { |
| 1266 | const { original } = this |
| 1267 | const index = original.indexOf(string) |
| 1268 | |
| 1269 | if (index !== -1) { |
| 1270 | if (typeof replacement === 'function') { |
| 1271 | replacement = replacement(string, index, original) |
| 1272 | } |
| 1273 | if (string !== replacement) { |
| 1274 | if (string.length === 0) { |
| 1275 | // an empty search string matches the empty range at the start of the |
| 1276 | // string, which has no characters to overwrite - the replacement is an |
| 1277 | // insertion there, as it is for `String.prototype.replace` |
| 1278 | this.appendRight(index, replacement) |
| 1279 | } |
| 1280 | else { |
| 1281 | this.overwrite(index, index + string.length, replacement) |
| 1282 | } |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | return this |
| 1287 | } |
| 1288 | |
| 1289 | /** |
| 1290 | * String replacement with RegExp or string. |
no test coverage detected