Line 7,668: |
Line 7,668: |
| | <samp>EscapeQuotes</samp> | | | <samp>EscapeQuotes</samp> |
| | Escape quotes in a string so they're ignored by methods like <samp>SplitQuoteAware</samp>. | | | Escape quotes in a string so they're ignored by methods like <samp>SplitQuoteAware</samp>. |
| + | |
| + | This isn't idempotent (e.g. calling it twice will result in double-escaped quotes). |
| + | |- |
| + | | <samp>UnsplitQuoteAware</samp> |
| + | | Combine an array of arguments into a single string with a custom delimiter, using quotes where needed to escape delimiters within an argument. Calling <samp>SplitQuoteAware</samp> on the resulting string with the same delimiter will produce the original values. |
| + | |
| + | For example: |
| + | <syntaxhighlight lang="c#"> |
| + | string args = ArgUtility.UnsplitQuoteAware(new[] { "A", "B C", "D" }, ' '); // A "B C" D |
| + | </syntaxhighlight> |
| | | |
| This isn't idempotent (e.g. calling it twice will result in double-escaped quotes). | | This isn't idempotent (e.g. calling it twice will result in double-escaped quotes). |
Line 7,730: |
Line 7,740: |
| else | | else |
| this.Helper.Monitor.Log($"Failed getting remainder: {error}", LogLevel.Warn); | | this.Helper.Monitor.Log($"Failed getting remainder: {error}", LogLevel.Warn); |
| + | </syntaxhighlight> |
| + | |- |
| + | | <samp>GetSubsetOf</samp> |
| + | | Get a slice of the input array. For example: |
| + | <syntaxhighlight lang="c#"> |
| + | string[] subset1 = ArgUtility.GetSubsetOf(new[] { "A", "B", "C", "D" }, startAt: 1); // B, C, D |
| + | string[] subset2 = ArgUtility.GetSubsetOf(new[] { "A", "B", "C", "D" }, startAt: 1, length: 2); // B, C |
| + | </syntaxhighlight> |
| + | |
| + | This is fault-tolerant as long as <samp>startAt</samp> isn't negative. For example: |
| + | <syntaxhighlight lang="c#"> |
| + | string[] subset2 = ArgUtility.GetSubsetOf(new[] { "A", "B", "C", "D" }, startAt: 100); // <empty array> |
| + | string[] subset1 = ArgUtility.GetSubsetOf(new[] { "A", "B", "C", "D" }, startAt: 1, length: 100); // B, C, D |
| </syntaxhighlight> | | </syntaxhighlight> |
| |} | | |} |