Bonjour tout le monde!
Alors j'aimerai savoir un truc tout simple. Je switch() sur une case de tableau alors qu'il n'y a que deux cas possibles. Je trouve cela plus lisible. De plus, si je rajoute des options, cela sera plus rapide, et il n'y aura pour le coup plus à hésiter entre switch et if.
Qu'est-ce qui est le mieux? switch ou if() et else if() ?
Voici mon code qui lit un fichier de conf pour vous faire une idée:
PHP Code:
public iChatConfig( )
{
new szCfgFile[ 128 ];
get_configsdir( szCfgFile, charsmax( szCfgFile ) );
formatex( szCfgFile, charsmax( szCfgFile ), "%s/config.ichat", szCfgFile );
new fp = fopen( szCfgFile, "rt" );
if ( !fp )
{
return;
}
new szLineData[ 364 ], szLineKey[ 96 ], szLineValue[ 264 ];
while ( !feof( fp ) )
{
fgets( fp, szLineData, charsmax( szLineData ) );
trim( szLineData );
if ( szLineData[ 0 ] == ';' || szLineData[ 0 ] == '#' || ( szLineData[ 0 ] == '/' && szLineData[ 1 ] == '/' ) || !szLineData[ 0 ] )
{
continue;
}
parse( szLineData, szLineKey, charsmax( szLineKey ), szLineValue, charsmax( szLineValue ) );
switch ( szLineKey[ 0 ] )
{
case 'F':
{
switch ( szLineKey[ 7 ] )
{
case 'D':
{
switch ( szLineKey[ 11 ] )
{
case 'A':
{
if ( equal( szLineKey, "FORMAT_DEF_ALIVE" ) )
{
copy( formatAllDefAlive, charsmax( formatAllDefAlive ), szLineValue );
}
}
case 'D':
{
if ( equal( szLineKey, "FORMAT_DEF_DEAD" ) )
{
copy( formatAllDefAlive, charsmax( formatAllDefAlive ), szLineValue );
}
}
}
}
case 'A':
{
switch ( szLineKey[ 13 ] )
{
case 'A':
{
if ( equal( szLineKey, "FORMAT_ADMIN_ALIVE" ) )
{
copy( formatAllAdminAlive, charsmax( formatAllAdminAlive ), szLineValue );
}
}
case: 'D':
{
if ( equal( szLineKey, "FORMAT_ADMIN_DEAD" ) )
{
copy( formatAllAdminAlive, charsmax( formatAllAdminAlive ), szLineValue );
}
}
}
}
case 'T':
{
switch ( szLineKey[ 12 ] )
{
case 'D':
{
switch ( szLineKey[ 16 ] )
{
case 'A':
{
if ( equal( szLineKey, "FORMAT_TEAM_DEF_ALIVE" ) )
{
copy( formatTeamDefAlive, charsmax( formatTeamDefAlive ), szLineValue );
}
}
case 'D':
{
if ( equal( szLineKey, "FORMAT_TEAM_DEF_DEAD" ) )
{
copy( formatTeamDefAlive, charsmax( formatTeamDefAlive ), szLineValue );
}
}
}
}
case 'A':
{
switch ( szLineKey[ 18 ] )
{
case 'A'
{
if ( equal( szLineKey, "FORMAT_TEAM_ADMIN_ALIVE" ) )
{
copy( formatTeamAdminAlive, charsmax( formatTeamAdminAlive ), szLineValue );
}
}
case 'D':
{
if ( equal( szLineKey, "FORMAT_TEAM_ADMIN_DEAD" ) )
{
copy( formatTeamAdminAlive, charsmax( formatTeamAdminAlive ), szLineValue );
}
}
}
}
}
}
}
}
case 'C':
{
switch ( szLineKey[ 5 ] )
{
case 'C':
{
if ( equal( szLineKey, "CHAT_CLCMD_REMOVE" ) )
{
removeOnSlash = str_to_num( szLineValue );
}
}
case 'A':
{
if ( equal( szLineKey, "CHAT_ADMIN_SPY" ) )
{
adminsSpy = str_to_num( szLineValue );
}
}
case 'N':
{
if ( equal( szLineKey, "CHAT_NOTIFY" ) )
{
userNotify = str_to_num( szLineValue );
}
}
case 'R':
{
switch ( szLineKey[ 12 ] )
{
case 'A':
{
if ( equal( szLineKey, "CHAT_RADIUS_ALL" ) )
{
printRadiusAll = str_to_float( szLineValue );
}
}
case 'T':
{
if ( equal( szLineKey, "CHAT_RADIUS_TEAM" ) )
{
printRadiusTeam = str_to_float( szLineValue );
}
}
}
}
}
}
}
}
fclose( fp );
}
Merci d'avance
__________________