MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / validateObjectName

Function validateObjectName

Engine/source/gui/editor/editorFunctions.cpp:29–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27
28
29bool validateObjectName( const char *data, const SimObject *object )
30{
31 if( !data || !data[ 0 ] )
32 return true;
33
34 bool isValidId = true;
35 if( !dIsalpha( data[ 0 ] ) && data[ 0 ] != '_' )
36 isValidId = false;
37 else
38 {
39 for( U32 i = 1; data[ i ] != '\0'; ++ i )
40 {
41 if( !dIsalnum( data[ i ] ) && data[ i ] != '_' )
42 {
43 isValidId = false;
44 break;
45 }
46 }
47 }
48
49 if( !isValidId )
50 {
51 Platform::AlertOK( "Invalid Object Name", avar( "'%s' is not a valid "
52 "object name. Please choose a name that begins with a letter or "
53 "underscore and is otherwise comprised exclusively of letters, "
54 "digits, and/or underscores.", data ) );
55 return false;
56 }
57
58 SimObject *pTemp = NULL;
59 if ( Sim::findObject( data, pTemp ) && pTemp != object )
60 {
61 const char* filename = pTemp->getFilename();
62 if ( !filename || !filename[0] )
63 filename = "an unknown file";
64
65 Platform::AlertOK( "Invalid Object Name", avar( "Object names must be unique, "
66 "and there is an existing %s object with the name '%s' (defined in %s). "
67 "Please choose another name.", pTemp->getClassName(), data, filename ) );
68 return false;
69 }
70
71 if ( AbstractClassRep::findClassRep( data ) )
72 {
73 Platform::AlertOK( "Invalid Object Name", avar( "'%s' is the name of an "
74 "existing TorqueScript class. Please choose another name.", data ) );
75 return false;
76 }
77
78 return true;
79}

Callers 2

verifyDataMethod · 0.85
onRenameValidateMethod · 0.85

Calls 6

dIsalphaFunction · 0.85
dIsalnumFunction · 0.85
avarFunction · 0.85
findObjectFunction · 0.50
getFilenameMethod · 0.45
getClassNameMethod · 0.45

Tested by 1

verifyDataMethod · 0.68