// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // // Creation Date: 1 December 1996 // // // // // string interToUI(string $interCapName) // // // Takes a string in interCaps form, // and returns a "UI" string. Allows // things that are called something like // graphEditor to be shown to the // user as "Graph Editor" // // // string $interCapName Name to convert, assumed to be in interCaps. // // // string : Converted name // // // interToUI( "graphEditor" ); // // Result : Graph Editor // // interToUI( "heffalump" ); // // Result : Heffalump // // interToUI( "AndWoozles" ); // // Result : And Woozles // // // // global proc string interToUI( string $input ) { string $retval = ""; int $stringSize = size( $input ); if (0 < $stringSize) { string $character = substring( $input, 1, 1 ); string $upperChar = toupper( $character ); $retval = ( $retval + $upperChar ); int $parenLevel = 0; int $capitalizeNext = false; string $prevChar = $character; for( $i=2; $i <= $stringSize; $i++ ) { $character = substring( $input, $i, $i ); $upperChar = toupper( $character ); // Capitalize this character if the previous was a "." // if( $capitalizeNext ) { $character = $upperChar; } // Do not add spaces before numbers or brackets/parens // or else "myMultiAttr[16]" will come out as // "My Multi Attr [ 1 6 ]" // int $isOpenParen = size( match( "\\[", $character ) ) || size( match( "\\(", $character ) ); int $isCloseParen= size( match( "\\]", $character ) ) || size( match( "\\)", $character ) ); int $isPeriod = size( match( "\\.", $character ) ); // Increment the level of nested parens // if( $isOpenParen ) { $parenLevel++; } // Take "." to mean a new phrase starts and we // need a capital letter. // if( $isPeriod ) { $capitalizeNext = true; } // If the character is already capitalized, then // insert a space before putting the character // back into the string // if( ($character==$upperChar) && !$isPeriod && ($parenLevel==0) ) { // The only exception is if we're beginning a new // phrase. "T.Tx" should remain "T.Tx" not "T. Tx" // // Also, don't separate groups of caps. // "colorRGB" should appear as "Color RGB" // not "Color R G B". // if( !$capitalizeNext &&( $prevChar != toupper($prevChar) ) ) { $retval = ( $retval + " " ); } $capitalizeNext = false; } // Decrement the level of nested parens // if( $isCloseParen ) { $parenLevel--; } $retval = ( $retval + $character ); $prevChar = $character; } } return $retval; }