Utility class for editor layer naming. It returns a display name for an ArchLayerNode by asking ArchKindsAsked for a name or by splitting the node identifier into a spaced, human readable string.
namespace Sunless.Architecture;
public static class ArchLayerNames
{
public static string DisplayName( ArchLayerNode node )
{
if ( node is null )
{
return "";
}
return ArchKindsAsked.DisplayName( node.Kind, node.Payload ) ?? SeparateIdentifier( node.Name ?? "" );
}
static string SeparateIdentifier( string value )
{
var result = "";
for ( var index = 0; index < value.Length; index++ )
{
var character = value[index];
var previous = index > 0 ? value[index - 1] : '\0';
var separates = index > 0 && character != '_' && previous != '_'
&& (char.IsDigit( character ) && !char.IsDigit( previous )
|| !char.IsDigit( character ) && char.IsDigit( previous )
|| char.IsUpper( character ) && char.IsLower( previous ));
if ( character == '_' )
{
if ( result.Length > 0 && result[^1] != ' ' )
{
result += ' ';
}
continue;
}
if ( separates )
{
result += ' ';
}
result += character;
}
return result.Trim();
}
}