|
| 1 | +--- |
| 2 | +RFC: '0054' |
| 3 | +Author: Friedrich Weinmann |
| 4 | +Status: Withdrawn |
| 5 | +SupercededBy: n/a |
| 6 | +Version: 1.0 |
| 7 | +Area: cmdlets/data manipulation |
| 8 | +Comments Due: |
| 9 | +Plan to implement: Yes |
| 10 | +--- |
| 11 | + |
| 12 | +# String Manipulating Cmdlets |
| 13 | + |
| 14 | +Add cmdlets that manipulate strings and are capable of doing so on the pipeline. |
| 15 | + |
| 16 | +## Motivation |
| 17 | + |
| 18 | +Existing tools to manipulate strings - the most common data type manipulated in PowerShell are lacking in usability. |
| 19 | +The .NET tools available through string and regex are inconvenient to use. |
| 20 | +String-manipulating operators (such as `-split`) are unintuitive to explore, as their options are not easily discoverable. |
| 21 | +Neither option allows use on the pipeline, forcing interruption of the pipeline or use of inefficient `ForEach-Object` calls. |
| 22 | + |
| 23 | +From this come two main pain points this RFC is aimed to resolve: |
| 24 | + |
| 25 | +Current string data manipulation ... |
| 26 | + |
| 27 | + - is technically insufficient from a performance perspective. |
| 28 | + - is unintuitive and inconvenient for the end user. |
| 29 | + |
| 30 | +Given that this is a universal problem affecting literally all users and most code, this should be implemented as part of the core application, not an external third party module. |
| 31 | + |
| 32 | +## Specification |
| 33 | + |
| 34 | +### New Cmdlets |
| 35 | + |
| 36 | +The solution should provide cmdlets that allow string manipulation on the pipeline. |
| 37 | + |
| 38 | +The following operations should be supported: |
| 39 | + |
| 40 | + - `Add-String` | Implements partial `-f` functionality to add content to strings, as well as the `.PadLeft()` and `.PadRight()` methods. |
| 41 | + - `Format-String` | Implements full `-f` functionality or the `String.Format()` method. Supports gathering multiple items from the pipeline before formatting. |
| 42 | + - `Get-SubString` | Implements the `.SubString()` method, the `-Trim` operator as well as the `.TrimStart()` and `.TrimEnd()` methods. |
| 43 | + - `Join-String` | Implements the `-join` operator, allowing specifying the number of items to join in each batch. |
| 44 | + - `Set-String` | Implements the `-Replace` operator as well as the `.Replace()` method. |
| 45 | + - `Split-String` | Implements the `-Split` operator as well as the `.Split()` method. |
| 46 | + |
| 47 | +### New Aliases |
| 48 | + |
| 49 | +Given that part of the goal is to improve the user experience, introducing aliases - especially for those mapping operators where users are used to it - will improve user experience and accelerate adoption. |
| 50 | + |
| 51 | +Thus here a proposed list of aliases: |
| 52 | + |
| 53 | + - `Add-String` | `wrap` or `add` |
| 54 | + - `Format-String` | `format` |
| 55 | + - `Get-SubString` | None needed - `substring` will automatically resolve to `Get-SubString` |
| 56 | + - `Join-String` | `join` |
| 57 | + - `Set-String` | `replace` |
| 58 | + - `Split-String` | `split` |
| 59 | + |
| 60 | +## Alternate Proposals and Considerations |
| 61 | + |
| 62 | +### Distribution as part of a module |
| 63 | + |
| 64 | +Theoretically, these cmdlets could also be released and distributed as part of an external module. |
| 65 | + |
| 66 | +The same could really be said of every single cmdlet that is shipped as part of the core PowerShell. |
| 67 | +What makes a cmdlet core then? |
| 68 | +Not bound to a specific use-case? Check. |
| 69 | +Relevant to the vast majority of users? Check. (In fact vastly more so than quite a few other core cmdlets) |
| 70 | + |
| 71 | +### Status Quo |
| 72 | + |
| 73 | +The status quo - having users keep using operators and .NET methods -would have several disadvantages: |
| 74 | + |
| 75 | + - More coding effort to use |
| 76 | + - Additional resource cost (memory when interrupting pipeline, CPU when using `ForEach-Object` instead) |
| 77 | + - Harder to maintain code |
| 78 | + - Less discoverability for users |
| 79 | + - Harder to find documentation for users |
| 80 | + |
| 81 | +## Notes: |
| 82 | + |
| 83 | + - This topic has already been discussed in an issue](https://github.com/PowerShell/PowerShell/issues/6697) |
| 84 | + - For an experimental implementation, [see the following PR](https://github.com/PowerShell/PowerShell/pull/6753) |
0 commit comments