Nuke.Cola
Loading...
Searching...
No Matches
Nuke.Cola.TextExtensions Class Reference

Static Public Member Functions

static IEnumerable< string > DoubleQuoteIfNeeded (this IEnumerable< object > self)
 
static Func< string, string?> Parse (this string? input, string pattern, RegexOptions options=RegexOptions.None, bool forceNullOnEmpty=false, bool forceNullOnWhitespce=false)
 Shorthand for one-liner regex parsing from named captures.
 
static Func< string, string?> Parse (this string? input, Regex pattern, bool forceNullOnEmpty=false, bool forceNullOnWhitespce=false)
 Shorthand for one-liner regex parsing from named captures. Allows to use precompiled pattern.
 
static string AsSingleLine (this string input, string replaceWith=" ")
 Simple convenience function for replacing new lines with other string (space by default)
 
static string GlobToRegex (this string glob)
 Converts a glob expression into a Regex expression with captures.
 
static string AppendNonEmpty (this string? self, string other)
 Convenience, append a piece of string to an input string only if input string is non-null and non-empty.
 
static string PrependNonEmpty (this string? self, string other)
 Convenience, prepend a piece of string to an input string only if input string is non-null and non-empty.
 
static ? string Else (this string? self, string? def=null, bool ignoreWhitespace=true)
 Defer to a default value if string is null or empty or whitespace only.
 

Detailed Description

Definition at line 12 of file TextExtensions.cs.

Member Function Documentation

◆ AppendNonEmpty()

static string Nuke.Cola.TextExtensions.AppendNonEmpty ( this string? self,
string other )
static

Convenience, append a piece of string to an input string only if input string is non-null and non-empty.

◆ AsSingleLine()

static string Nuke.Cola.TextExtensions.AsSingleLine ( this string input,
string replaceWith = " " )
static

Simple convenience function for replacing new lines with other string (space by default)

◆ Else()

static ? string Nuke.Cola.TextExtensions.Else ( this string? self,
string? def = null,
bool ignoreWhitespace = true )
static

Defer to a default value if string is null or empty or whitespace only.

Parameters
self
defDefault value to substitute null/empty/whitespace with (null by default)
ignoreWhitespaceIf set to true treat whitespace-only string as empty as well. (true by default)
Returns

◆ GlobToRegex()

static string Nuke.Cola.TextExtensions.GlobToRegex ( this string glob)
static

Converts a glob expression into a Regex expression with captures.

Parameters
glob
Returns

◆ Parse() [1/2]

static Func< string, string?> Nuke.Cola.TextExtensions.Parse ( this string? input,
Regex pattern,
bool forceNullOnEmpty = false,
bool forceNullOnWhitespce = false )
static

Shorthand for one-liner regex parsing from named captures. Allows to use precompiled pattern.

"Hello World".Parse(new Regex("Hello (?<SUBJECT>\w+)"))("SUBJECT")

Returns
A function to be called with the desired capture name

Definition at line 39 of file TextExtensions.cs.

◆ Parse() [2/2]

static Func< string, string?> Nuke.Cola.TextExtensions.Parse ( this string? input,
string pattern,
RegexOptions options = RegexOptions.None,
bool forceNullOnEmpty = false,
bool forceNullOnWhitespce = false )
static

Shorthand for one-liner regex parsing from named captures.

"Hello World".Parse("Hello (?<SUBJECT>\w+)")("SUBJECT")

Returns
A function to be called with the desired capture name

◆ PrependNonEmpty()

static string Nuke.Cola.TextExtensions.PrependNonEmpty ( this string? self,
string other )
static

Convenience, prepend a piece of string to an input string only if input string is non-null and non-empty.


The documentation for this class was generated from the following file: