@@ -36,9 +36,9 @@ public static VerbalExpressions DefaultExpression
36
36
37
37
#region Private Members
38
38
39
- private string _prefixes = "" ;
40
- private string _source = "" ;
41
- private string _suffixes = "" ;
39
+ private StringBuilder _prefixes = new StringBuilder ( ) ;
40
+ private StringBuilder _source = new StringBuilder ( ) ;
41
+ private StringBuilder _suffixes = new StringBuilder ( ) ;
42
42
private RegexOptions _modifiers = RegexOptions . Multiline ;
43
43
44
44
#endregion Private Members
@@ -47,7 +47,7 @@ public static VerbalExpressions DefaultExpression
47
47
48
48
private string RegexString
49
49
{
50
- get { return _prefixes + _source + _suffixes ; }
50
+ get { return new StringBuilder ( ) . Append ( _prefixes ) . Append ( _source ) . Append ( _suffixes ) . ToString ( ) ; }
51
51
}
52
52
53
53
private Regex PatternRegex
@@ -108,7 +108,7 @@ public string Capture(string toTest, string groupName)
108
108
if ( ! Test ( toTest ) )
109
109
return null ;
110
110
111
- var match = PatternRegex . Match ( toTest ) ;
111
+ var match = PatternRegex . Match ( toTest ) ;
112
112
return match . Groups [ groupName ] . Value ;
113
113
}
114
114
@@ -137,19 +137,19 @@ public VerbalExpressions Add(string value, bool sanitize = true)
137
137
throw new ArgumentNullException ( "value must be provided" ) ;
138
138
139
139
value = sanitize ? Sanitize ( value ) : value ;
140
- _source += value ;
140
+ _source . Append ( value ) ;
141
141
return this ;
142
142
}
143
143
144
144
public VerbalExpressions StartOfLine ( bool enable = true )
145
145
{
146
- _prefixes = enable ? "^" : string . Empty ;
146
+ _prefixes . Append ( enable ? "^" : String . Empty ) ;
147
147
return this ;
148
148
}
149
149
150
150
public VerbalExpressions EndOfLine ( bool enable = true )
151
151
{
152
- _suffixes = enable ? "$" : string . Empty ;
152
+ _suffixes . Append ( enable ? "$" : String . Empty ) ;
153
153
return this ;
154
154
}
155
155
@@ -341,11 +341,9 @@ public VerbalExpressions Or(CommonRegex commonRegex)
341
341
342
342
public VerbalExpressions Or ( string value , bool sanitize = true )
343
343
{
344
- _prefixes += "(" ;
345
- _suffixes = ")" + _suffixes ;
346
-
347
- _source += ")|(" ;
348
-
344
+ _prefixes . Append ( "(" ) ;
345
+ _suffixes . Insert ( 0 , ")" ) ;
346
+ _source . Append ( ")|(" ) ;
349
347
return Add ( value , sanitize ) ;
350
348
}
351
349
@@ -356,7 +354,7 @@ public VerbalExpressions BeginCapture()
356
354
357
355
public VerbalExpressions BeginCapture ( string groupName )
358
356
{
359
- return Add ( "(?<" , false ) . Add ( groupName , true ) . Add ( ">" , false ) ;
357
+ return Add ( "(?<" , false ) . Add ( groupName , true ) . Add ( ">" , false ) ;
360
358
}
361
359
362
360
public VerbalExpressions EndCapture ( )
@@ -457,6 +455,6 @@ public VerbalExpressions WithOptions(RegexOptions options)
457
455
458
456
#endregion Public Methods
459
457
460
-
458
+
461
459
}
462
460
}
0 commit comments