Quote:
Originally Posted by Slice
pawn Код:
stock GetParam( const szString[ ], iParam ) { new iSearchPos, iPos, iHoles, szReturn[ 128 ], iFoundParam = -1; if ( szString[ 0 ] <= 1 ) // Treat \1 as a null character for ZCMD/YCMD compatibility. return szReturn; // If the string is empty there's no point in looking for stuff. iPos = -1; while ( 2 <= szString[ ++iPos ] <= ' ' ) {} // Trim the beginning of the string. if ( --iParam == 0 ) // Wether or not we're looking for the first parameter. { if ( ( iSearchPos = strfind( szString, " ", _, iPos ) ) != -1 // Search for a space/tab || ( iSearchPos = strfind( szString, "\t", _, iPos ) ) != -1 ) strcat( szReturn, szString[ iPos ], iSearchPos + 1 - iPos ); // Put the found part into the return. else strcat( szReturn, szString[ iPos ] ); // Put the whole thing (except for the first tabs/spaces, if any) into the return. } else { while ( ( iSearchPos = strfind( szString, " ", _, iPos ) ) != -1 // Search for a space/tab || ( iSearchPos = strfind( szString, "\t", _, iPos ) ) != -1 ) { back_in_action: iPos = iSearchPos; while ( 2 <= szString[ ++iPos ] <= ' ' ) {} // Skip any whitespace. if ( iFoundParam != -1 ) // If the previous iteration found a param.. { strcat( szReturn, szString[ iFoundParam ], iPos - iFoundParam ); // Put it into the return string. iFoundParam = -1; break; // Then BREAK YOSELF. } if ( ++iHoles == iParam ) // If this current "hole" is in front of the param we're looking for.. iFoundParam = iPos; // ..let the script know that. } if ( iFoundParam != -1 ) // If a param was found in the last iteration.. (end of the string) { iSearchPos = strlen( szString ); // Set the next position to the end of the string. goto back_in_action; } } if ( szReturn[ 0 ] ) { // Trim any whitespace on the right side. for ( iPos = strlen( szReturn ) - 1; iPos >= 0 && szReturn[ iPos ] <= ' '; iPos-- ) szReturn[ iPos ] = 0; } return szReturn; }
|
Is it really that wise to use a goto? I've seen some really strange behaviour when using goto structures before in PAWN.