| 92 | |
| 93 | static const U32 MaxPlayerNameLength = 16; |
| 94 | DefineEngineFunction( strToPlayerName, const char*, (const char* ptr ), , "strToPlayerName(string);" ) |
| 95 | { |
| 96 | |
| 97 | // Strip leading spaces and underscores: |
| 98 | while ( *ptr == ' ' || *ptr == '_' ) |
| 99 | ptr++; |
| 100 | |
| 101 | U32 len = dStrlen( ptr ); |
| 102 | if ( len ) |
| 103 | { |
| 104 | char* ret = Con::getReturnBuffer( MaxPlayerNameLength + 1 ); |
| 105 | char* rptr = ret; |
| 106 | ret[MaxPlayerNameLength - 1] = '\0'; |
| 107 | ret[MaxPlayerNameLength] = '\0'; |
| 108 | bool space = false; |
| 109 | |
| 110 | U8 ch; |
| 111 | while ( *ptr && dStrlen( ret ) < MaxPlayerNameLength ) |
| 112 | { |
| 113 | ch = (U8) *ptr; |
| 114 | |
| 115 | // Strip all illegal characters: |
| 116 | if ( ch < 32 || ch == ',' || ch == '.' || ch == '\'' || ch == '`' ) |
| 117 | { |
| 118 | ptr++; |
| 119 | continue; |
| 120 | } |
| 121 | |
| 122 | // Don't allow double spaces or space-underline combinations: |
| 123 | if ( ch == ' ' || ch == '_' ) |
| 124 | { |
| 125 | if ( space ) |
| 126 | { |
| 127 | ptr++; |
| 128 | continue; |
| 129 | } |
| 130 | else |
| 131 | space = true; |
| 132 | } |
| 133 | else |
| 134 | space = false; |
| 135 | |
| 136 | *rptr++ = *ptr; |
| 137 | ptr++; |
| 138 | } |
| 139 | *rptr = '\0'; |
| 140 | |
| 141 | //finally, strip out the ML text control chars... |
| 142 | return GuiMLTextCtrl::stripControlChars(ret); |
| 143 | } |
| 144 | |
| 145 | return( "" ); |
| 146 | } |
| 147 | |
| 148 | ConsoleFunctionGroupBegin( Platform , "General platform functions."); |
| 149 |
no test coverage detected