@@ -823,8 +823,9 @@ public static bool EndsWithInvariant(this string str, string endsWith)
823
823
return str . EndsWith ( endsWith , PclExport . Instance . InvariantComparison ) ;
824
824
}
825
825
826
- private static readonly Regex InvalidVarCharsRegex = new Regex ( @"[^A-Za-z0-9]" , PclExport . Instance . RegexOptions ) ;
827
- private static readonly Regex SplitCamelCaseRegex = new Regex ( "([A-Z]|[0-9]+)" , PclExport . Instance . RegexOptions ) ;
826
+ private static readonly Regex InvalidVarCharsRegex = new Regex ( @"[^A-Za-z0-9_]" , RegexOptions . Compiled ) ;
827
+ private static readonly Regex InvalidVarRefCharsRegex = new Regex ( @"[^A-Za-z0-9._]" , RegexOptions . Compiled ) ;
828
+ private static readonly Regex SplitCamelCaseRegex = new Regex ( "([A-Z]|[0-9]+)" , RegexOptions . Compiled ) ;
828
829
private static readonly Regex HttpRegex = new Regex ( @"^http://" ,
829
830
PclExport . Instance . RegexOptions | RegexOptions . CultureInvariant | RegexOptions . IgnoreCase ) ;
830
831
@@ -910,11 +911,11 @@ public static bool ContainsAny(this string text, params string[] testMatches)
910
911
return false ;
911
912
}
912
913
913
- public static string SafeVarName ( this string text )
914
- {
915
- if ( string . IsNullOrEmpty ( text ) ) return null ;
916
- return InvalidVarCharsRegex . Replace ( text , "_" ) ;
917
- }
914
+ public static string SafeVarName ( this string text ) => ! string . IsNullOrEmpty ( text )
915
+ ? InvalidVarCharsRegex . Replace ( text , "_" ) : null ;
916
+
917
+ public static string SafeVarRef ( this string text ) => ! string . IsNullOrEmpty ( text )
918
+ ? InvalidVarRefCharsRegex . Replace ( text , "_" ) : null ;
918
919
919
920
public static string Join ( this List < string > items )
920
921
{
0 commit comments