Class SystemStringExtensions
- Namespace
- Luny
- Assembly
- Luny.dll
public static class SystemStringExtensions
- Inheritance
-
objectSystemStringExtensions
Methods
IsValidCSharpIdentifier(string, bool, bool)
Correctness check of a C# identifier (ie variable, method name) that works across platforms and doesn't use Regex. It may not catch all edge cases, but 99% of them.
public static bool IsValidCSharpIdentifier(this string str, bool allowNamespaces = false, bool allowGenerics = false)
Parameters
strstringallowNamespacesboolAllows '.' as character as well
allowGenericsbool
Returns
- bool
ReplaceIllegalCSharpIdentifierChars(string, char)
Replaces any illegal C# identifier character in the string with the given replacement character. If the string matches a known C# keyword, it gets prefixed with '@' to make it a legal identifier.
public static string ReplaceIllegalCSharpIdentifierChars(this string str, char replacement = '_')
Parameters
strstringreplacementchar
Returns
- string
SanitizeIdentifier(string)
Trims string and replaces illegal C# identifier characters and prints a Debug.LogWarning if it had to be altered.
public static string SanitizeIdentifier(this string identifier)
Parameters
identifierstring
Returns
- string
ToForwardSlashes(string)
Converts any backslashes '' to forward slashes '/' to "normalize" strings representing a path.
public static string ToForwardSlashes(this string str)
Parameters
strstring
Returns
- string
Remarks
Method first checks if there is a '' in the string to avoid unnecessary string allocations. Uses IndexOf() and Replace() which are both SIMD-optimized.