Table of Contents

Class SystemStringExtensions

Namespace
Luny
Assembly
Luny.dll
public static class SystemStringExtensions
Inheritance
object
SystemStringExtensions

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

str string
allowNamespaces bool

Allows '.' as character as well

allowGenerics bool

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

str string
replacement char

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

identifier string

Returns

string

ToForwardSlashes(string)

Converts any backslashes '' to forward slashes '/' to "normalize" strings representing a path.

public static string ToForwardSlashes(this string str)

Parameters

str string

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.