BadScript 2
Loading...
Searching...
No Matches
CommandLine.Infrastructure.StringBuilderExtensions Class Reference

Static Public Member Functions

static StringBuilder AppendWhen (this StringBuilder builder, bool condition, params string[] values)
 
static StringBuilder AppendWhen (this StringBuilder builder, bool condition, params char[] values)
 
static StringBuilder AppendFormatWhen (this StringBuilder builder, bool condition, string format, params object[] args)
 
static StringBuilder AppendIf (this StringBuilder builder, bool condition, string ifTrue, string ifFalse)
 
static StringBuilder BimapIf (this StringBuilder builder, bool condition, Func< StringBuilder, StringBuilder > ifTrue, Func< StringBuilder, StringBuilder > ifFalse)
 
static StringBuilder MapIf (this StringBuilder builder, bool condition, Func< StringBuilder, StringBuilder > ifTrue)
 
static StringBuilder AppendIfNotEmpty (this StringBuilder builder, params string[] values)
 
static string SafeToString (this StringBuilder builder)
 
static int SafeLength (this StringBuilder builder)
 
static StringBuilder TrimEnd (this StringBuilder builder, char c)
 
static StringBuilder TrimEndIfMatch (this StringBuilder builder, char c)
 
static StringBuilder TrimEndIfMatchWhen (this StringBuilder builder, bool condition, char c)
 
static int TrailingSpaces (this StringBuilder builder)
 
static bool SafeStartsWith (this StringBuilder builder, string s)
 Indicates whether the string value of a System.Text.StringBuilder starts with the input System.String parameter. Returns false if either the StringBuilder or input string is null or empty.
 
static bool SafeEndsWith (this StringBuilder builder, string s)
 Indicates whether the string value of a System.Text.StringBuilder ends with the input System.String parameter. Returns false if either the StringBuilder or input string is null or empty.
 

Detailed Description

Definition at line 8 of file StringBuilderExtensions.cs.

Member Function Documentation

◆ AppendFormatWhen()

static StringBuilder CommandLine.Infrastructure.StringBuilderExtensions.AppendFormatWhen ( this StringBuilder  builder,
bool  condition,
string  format,
params object[]  args 
)
static

Definition at line 36 of file StringBuilderExtensions.cs.

40 {
41 return condition
42 ? builder.AppendFormat(format, args)
43 : builder;
44 }

◆ AppendIf()

static StringBuilder CommandLine.Infrastructure.StringBuilderExtensions.AppendIf ( this StringBuilder  builder,
bool  condition,
string  ifTrue,
string  ifFalse 
)
static

Definition at line 46 of file StringBuilderExtensions.cs.

47 {
48 return condition
49 ? builder.Append(ifTrue)
50 : builder.Append(ifFalse);
51 }

◆ AppendIfNotEmpty()

static StringBuilder CommandLine.Infrastructure.StringBuilderExtensions.AppendIfNotEmpty ( this StringBuilder  builder,
params string[]  values 
)
static

Definition at line 72 of file StringBuilderExtensions.cs.

73 {
74 foreach (string value in values)
75 {
76 if (value.Length > 0)
77 {
78 builder.Append(value);
79 }
80 }
81
82 return builder;
83 }

◆ AppendWhen() [1/2]

static StringBuilder CommandLine.Infrastructure.StringBuilderExtensions.AppendWhen ( this StringBuilder  builder,
bool  condition,
params char[]  values 
)
static

Definition at line 23 of file StringBuilderExtensions.cs.

24 {
25 if (condition)
26 {
27 foreach (char value in values)
28 {
29 builder.Append(value);
30 }
31 }
32
33 return builder;
34 }

◆ AppendWhen() [2/2]

static StringBuilder CommandLine.Infrastructure.StringBuilderExtensions.AppendWhen ( this StringBuilder  builder,
bool  condition,
params string[]  values 
)
static

Definition at line 10 of file StringBuilderExtensions.cs.

11 {
12 if (condition)
13 {
14 foreach (string value in values)
15 {
16 builder.Append(value);
17 }
18 }
19
20 return builder;
21 }

◆ BimapIf()

static StringBuilder CommandLine.Infrastructure.StringBuilderExtensions.BimapIf ( this StringBuilder  builder,
bool  condition,
Func< StringBuilder, StringBuilder >  ifTrue,
Func< StringBuilder, StringBuilder >  ifFalse 
)
static

Definition at line 53 of file StringBuilderExtensions.cs.

57 {
58 return condition
59 ? ifTrue(builder)
60 : ifFalse(builder);
61 }

◆ MapIf()

static StringBuilder CommandLine.Infrastructure.StringBuilderExtensions.MapIf ( this StringBuilder  builder,
bool  condition,
Func< StringBuilder, StringBuilder >  ifTrue 
)
static

Definition at line 63 of file StringBuilderExtensions.cs.

66 {
67 return condition
68 ? ifTrue(builder)
69 : builder;
70 }

◆ SafeEndsWith()

static bool CommandLine.Infrastructure.StringBuilderExtensions.SafeEndsWith ( this StringBuilder  builder,
string  s 
)
static

Indicates whether the string value of a System.Text.StringBuilder ends with the input System.String parameter. Returns false if either the StringBuilder or input string is null or empty.

Parameters
builderThe System.Text.StringBuilder to test.
sThe System.String to look for.
Returns

Definition at line 184 of file StringBuilderExtensions.cs.

185 {
186 if (string.IsNullOrEmpty(s))
187 {
188 return false;
189 }
190
191 return builder?.Length >= s.Length && builder.ToString(builder.Length - s.Length, s.Length) == s;
192 }

◆ SafeLength()

static int CommandLine.Infrastructure.StringBuilderExtensions.SafeLength ( this StringBuilder  builder)
static

Definition at line 92 of file StringBuilderExtensions.cs.

93 {
94 return builder == null ? 0 : builder.Length;
95 }

◆ SafeStartsWith()

static bool CommandLine.Infrastructure.StringBuilderExtensions.SafeStartsWith ( this StringBuilder  builder,
string  s 
)
static

Indicates whether the string value of a System.Text.StringBuilder starts with the input System.String parameter. Returns false if either the StringBuilder or input string is null or empty.

Parameters
builderThe System.Text.StringBuilder to test.
sThe System.String to look for.
Returns

Definition at line 166 of file StringBuilderExtensions.cs.

167 {
168 if (string.IsNullOrEmpty(s))
169 {
170 return false;
171 }
172
173 return builder?.Length >= s.Length && builder.ToString(0, s.Length) == s;
174 }

◆ SafeToString()

static string CommandLine.Infrastructure.StringBuilderExtensions.SafeToString ( this StringBuilder  builder)
static

Definition at line 85 of file StringBuilderExtensions.cs.

86 {
87 return builder == null
88 ? string.Empty
89 : builder.ToString();
90 }

◆ TrailingSpaces()

static int CommandLine.Infrastructure.StringBuilderExtensions.TrailingSpaces ( this StringBuilder  builder)
static

Definition at line 124 of file StringBuilderExtensions.cs.

125 {
126 int bound = builder.Length - 1;
127
128 if (builder.Length == 0)
129 {
130 return 0;
131 }
132
133 if (builder[bound] != ' ')
134 {
135 return 0;
136 }
137
138 int c = 0;
139
140 for (int i = bound; i <= bound; i--)
141 {
142 if (i < 0)
143 {
144 break;
145 }
146
147 if (builder[i] != ' ')
148 {
149 break;
150 }
151
152 c++;
153 }
154
155 return c;
156 }

◆ TrimEnd()

static StringBuilder CommandLine.Infrastructure.StringBuilderExtensions.TrimEnd ( this StringBuilder  builder,
char  c 
)
static

Definition at line 97 of file StringBuilderExtensions.cs.

98 {
99 return builder.Length > 0
100 ? builder.Remove(builder.Length - 1, 1)
101 : builder;
102 }

◆ TrimEndIfMatch()

static StringBuilder CommandLine.Infrastructure.StringBuilderExtensions.TrimEndIfMatch ( this StringBuilder  builder,
char  c 
)
static

Definition at line 104 of file StringBuilderExtensions.cs.

105 {
106 if (builder.Length > 0)
107 {
108 if (builder[builder.Length - 1] == c)
109 {
110 builder.Remove(builder.Length - 1, 1);
111 }
112 }
113
114 return builder;
115 }

◆ TrimEndIfMatchWhen()

static StringBuilder CommandLine.Infrastructure.StringBuilderExtensions.TrimEndIfMatchWhen ( this StringBuilder  builder,
bool  condition,
char  c 
)
static

Definition at line 117 of file StringBuilderExtensions.cs.

118 {
119 return condition
120 ? builder.TrimEndIfMatch(c)
121 : builder;
122 }

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