From 04704b051f63bc01f02ec370c4449db8c027f83f Mon Sep 17 00:00:00 2001 From: Ding Li Date: Sat, 16 Jun 2018 15:30:12 +0800 Subject: [PATCH] Refactor ParseUtils and add ParseBooleans function --- Utils/ParseUtils.mqh | 92 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 16 deletions(-) diff --git a/Utils/ParseUtils.mqh b/Utils/ParseUtils.mqh index 40a7b4e..5ea4fc4 100644 --- a/Utils/ParseUtils.mqh +++ b/Utils/ParseUtils.mqh @@ -53,16 +53,51 @@ bool ParseTimeRange(string s,long &time) return true; // accept: all digits } //+------------------------------------------------------------------+ -//| | +//| Convert a string representation of boolean to the real value | +//| Y y 1 T t are true | +//| all other values are false | //+------------------------------------------------------------------+ -bool ParseToPositiveIntegers(string s,int &target[]) +bool StringToBoolean(const string s) + { + if(StringLen(s)!=1) return false; + ushort c= s[0]; + return c=='Y' || c=='y' || c=='1' || c=='T' || c=='t'; + } +//+------------------------------------------------------------------+ +//| Parse a (default comma separated) list of booleans | +//+------------------------------------------------------------------+ +bool ParseBooleans(const string s,bool &target[],short sep=',') + { + string t[]; + StringSplit(s,sep,t); + int size=ArraySize(t); + if(ArraySize(t)<=0) + { + PrintFormat(">>> Error: %s is not a list of booleans!",s); + return false; + } + bool isSeries=ArrayGetAsSeries(target); + ArraySetAsSeries(target,false); + + ArrayResize(target,size); + for(int i=0; i