From fe515e52298a09ac40a356dde2de1676180bff7d Mon Sep 17 00:00:00 2001 From: Will Budicm Date: Tue, 5 Jan 2021 06:14:33 +1100 Subject: [PATCH] Made parseAutonom use regex. --- htdocs/cgi-bin/system/modules/Settings.pm | 25 +++++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/htdocs/cgi-bin/system/modules/Settings.pm b/htdocs/cgi-bin/system/modules/Settings.pm index f9b8421..4f8dba9 100644 --- a/htdocs/cgi-bin/system/modules/Settings.pm +++ b/htdocs/cgi-bin/system/modules/Settings.pm @@ -39,8 +39,6 @@ use constant VW_LOG_WITH_EXCLUDES => 'VW_LOG_WITH_EXCLUDES'; # use constant VW_LOG_OVERRIDE_WHERE => 'VW_LOG_OVR_WHERE'; - - #DEFAULT SETTINGS HERE! our $RELEASE_VER = '2.1'; our $TIME_ZONE = 'Australia/Sydney'; @@ -604,7 +602,9 @@ sub obtainProperty { return 0; } } - +# The config property can't be set to empty string "", set to 0 to disable is the mechanism. +# So we have an shortcut when checking condition, zero is not set, false or empty. So to kick in then the app settings default. +# Setting to zero, is similar having the property (anon) disabled in config file. Which in the db must be reflected to zero. sub configProperty { my($db, $id, $name, $value) = @_; $id = '0' if not $id; @@ -666,15 +666,22 @@ sub connectDB { LifeLogException->throw(error=>"

Error->$@


$DSN

", show_trace=>1); } } +my $reg_autonom = qr/(^<<)(.+?<)(.+)(>{3,})/mp; sub parseAutonom { #Parses autonom tag for its crest value, returns undef if tag not found or wrong for passed line. - my $t = '<<'.shift.'<'; - my $line = shift; - if(rindex ($line, $t, 0)==0){#@TODO change the following to regex parsing: - my $l = length $t; - my $e = index $line, ">", $l + 1; - return substr $line, $l, $e - $l; + + my $t = shift; + + if($t =~ /$reg_autonom/g){ + my ($tag,$val) = ($2,$3); + $tag =~ s/<$//g; + $val =~ s/""$//g; #empty is like not set + $val =~ s/^"|"$//g; + if($tag&&$val){ + return $val; + } } + return; } -- 2.34.1