Skip to content

Commit

Permalink
Refactor gpc_string_to_bool
Browse files Browse the repository at this point in the history
Avoid repeated calls to strcasecmp
  • Loading branch information
cproensa authored and dregad committed Jan 9, 2019
1 parent afee374 commit 620fe73
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion core/filter_form_api.php
Expand Up @@ -1172,7 +1172,7 @@ function print_filter_values_sticky_issues( array $p_filter ) {
?>
<input type="hidden" name="<?php
echo FILTER_PROPERTY_STICKY; ?>" value="<?php
echo $t_sticky_filter_state ? 'on' : 'off'; ?>" />
echo $t_sticky_filter_state ? ON : OFF; ?>" />
<?php
}

Expand Down
21 changes: 11 additions & 10 deletions core/gpc_api.php
Expand Up @@ -464,15 +464,16 @@ function gpc_make_array( $p_var_name ) {
* @return boolean
*/
function gpc_string_to_bool( $p_string ) {
if( 0 == strcasecmp( 'off', $p_string )
|| 0 == strcasecmp( 'no', $p_string )
|| 0 == strcasecmp( 'n', $p_string )
|| 0 == strcasecmp( 'false', $p_string )
|| 0 == strcasecmp( '', $p_string )
|| 0 == strcasecmp( '0', $p_string )
) {
return false;
} else {
return true;
$t_value = trim( strtolower( $p_string ) );
switch ( $t_value ) {
case 'off':
case 'no':
case 'n':
case 'false':
case '0':
case '':
return false;
default:
return true;
}
}

0 comments on commit 620fe73

Please sign in to comment.