Table of Contents

Class SystemStringExtensions

Namespace
Luny
/
Assembly
Luny.dll
public static class SystemStringExtensions
Expand Details ...
Inheritance
Object
SystemStringExtensions

Methods

IsValidCSharpIdentifier(String, Boolean, Boolean)

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 Boolean IsValidCSharpIdentifier(this String str, Boolean allowNamespaces = false, Boolean allowGenerics = false)

Parameters

Type Name Description
String
str
Boolean
allowNamespaces

Allows '.' as character as well

Boolean
allowGenerics

Returns

Boolean

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

Type Name Description
String
str
Char
replacement

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

Type Name Description
String
identifier

Returns

String

ToForwardSlashes(String)

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

public static String ToForwardSlashes(this String str)

Parameters

Type Name Description
String
str

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.