MATLAB Python

trueDat

Syntax

truth = trueDat(mysteryInput, [strict]) [] = optional variables

Description

Robust truth-checker designed for parsing unpredictable user inputs. Can be used in "strict" mode, in which only things that look like a boolean will be handled and other things will make it barf. Otherwise, most things that aren't a non-empty value will return true. See key values for each mode.

Usage

mysteryInput: The input you want to check. strict: A logical indicating which mode should be used (the irony of requiring a logical in this function is not lost on me). If you don't provide strict as an argument it will default to false / non-strict mode. NON-STRICT MODE: Returns the logical 'false' if input is nan, a logical set to false, is not provided (does not exist), is empty, is an empty array, is equal to 0, or is one of the strings 'false', 'f', 'no','n','off', '0' or 'none'. Returns 'true' if input is a logical set to true, a numeric value other than zero, contains a structure, is a multi-element array, a function handle, a non-empty table or is any non-empty string not specified above as a 'false' string. Extracts the contents of any one-cell array and then recursively performs truth-checking as above. STRICT MODE: Returns the logical 'false' if input is a logical set to false, is equal to 0, or is one of the strings 'false', 'f', 'no','n','off', '0' or 'none'. Returns 'true' if input is a logical set to true, is equal to 1, or is one of the strings 'true','t','yes','y','on', or '1'. Extracts the contents of any one-cell array and then recursively performs truth-checking as above. Throws an error with any other input.