Skip to content
Permalink
Browse files

let VariantToBoolean() handle text input as potential boolean value

- properly implement #229
  • Loading branch information...
Arnaud Bouchez
Arnaud Bouchez committed Aug 3, 2019
1 parent 8a55fb3 commit 99e8896c0bed259fe37d32436799e8c9e6db4f39
Showing with 12 additions and 3 deletions.
  1. +11 −2 SynCommons.pas
  2. +1 −1 SynopseCommit.inc
@@ -1500,6 +1500,7 @@ function VariantToDoubleDef(const V: Variant; const default: double=0): double;
function VariantToCurrency(const V: Variant; var Value: currency): boolean;

/// convert any numerical Variant into a boolean value
// - text content will return true after case-insensitive 'true' comparison
function VariantToBoolean(const V: Variant; var Value: Boolean): boolean;

/// convert any numerical Variant into an integer


var
/// JSON compatible representation of a boolean value
/// JSON compatible representation of a boolean value, i.e. 'false' and 'true'
// - can be used when a RawUTF8 string is expected
BOOL_UTF8: array[boolean] of RawUTF8;

const
/// JSON compatible representation of a boolean value
/// JSON compatible representation of a boolean value, i.e. 'false' and 'true'
// - can be used e.g. in logs, or anything accepting a shortstring
BOOL_STR: array[boolean] of string[7] = ('false','true');

Value := TVarData(V).VBoolean;
varInteger: // coming e.g. from GetJsonField()
Value := TVarData(V).VInteger=1;
varString:
Value := IdemPropNameU(RawUTF8(TVarData(V).VAny),BOOL_UTF8[true]);
varOleStr:
Value := WideCompareText(WideString(TVarData(V).VAny),'true')=0;
{$ifdef HASVARUSTRING}
varUString: Value := {$ifdef FPC}UnicodeCompareText{$else}CompareText{$endif}(
UnicodeString(TVarData(V).VAny),'true')=0;
{$endif HASVARUSTRING}
else
if SetVariantUnRefSimpleValue(V,tmp) then
if tmp.VType=varBoolean then
@@ -1 +1 @@
'1.18.5303'
'1.18.5304'

0 comments on commit 99e8896

Please sign in to comment.
You can’t perform that action at this time.