Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e87d39f

Browse files
committed
Adding validate function, with no calls
1 parent 06cb054 commit e87d39f

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

source/core/ut_utils.pkb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,67 @@ create or replace package body ut_utils is
989989
return l_result;
990990
end;
991991

992+
function valid_tag_expression(a_tags in varchar2) return number is
993+
t_left_side ut_varchar2_list := ut_varchar2_list('|','&',',');
994+
t_right_side ut_varchar2_list := ut_varchar2_list('!','-');
995+
l_left_side_expression varchar2(100) := '[|&,]';
996+
l_left_side_regex varchar(400) := '([^|&,]*)[|&,](.*)';
997+
l_left_side varchar2(4000);
998+
999+
l_rigth_side_expression varchar2(100) := '[!-]';
1000+
l_right_side_regex varchar(400) := '([!-])([^!-].*)';
1001+
l_right_side varchar2(4000);
1002+
1003+
l_tags varchar2(4000) := a_tags;
1004+
l_result number :=1;
1005+
begin
1006+
--Validate that we have closed up all brackets
1007+
if regexp_count(l_tags,'\(') <> regexp_count(l_tags,'\)') then
1008+
l_result := 0;
1009+
end if;
1010+
1011+
--Remove brackets as we dont evaluate expression only validate.
1012+
l_tags := replace(replace(l_tags,'('),')');
1013+
1014+
--Check if there are any left side operators for first in order from left to right
1015+
if regexp_count(l_tags,l_left_side_expression) > 0 then
1016+
--Extract left part of operator and remaining of string to right
1017+
l_left_side := regexp_replace(l_tags,l_left_side_regex,'\1');
1018+
l_right_side := regexp_replace(l_tags,l_left_side_regex,'\2');
1019+
1020+
--If left side is null that means that we used left side operator without
1021+
-- left and right e.g. &test
1022+
if l_left_side is null then
1023+
l_result := 0;
1024+
else
1025+
--Extract right side from left side expression if there is any !-
1026+
--Remove first negation tag to see if there is double negation
1027+
l_left_side := regexp_replace(l_left_side,l_right_side_regex,'\2');
1028+
end if;
1029+
1030+
1031+
--check that on right side there is no extra negation
1032+
if regexp_count(l_left_side,l_rigth_side_expression) > 0 then
1033+
l_result := 0;
1034+
end if;
1035+
1036+
--Now process right side of string
1037+
if l_right_side is not null then
1038+
l_result := least(l_result,valid_tag_expression(l_right_side));
1039+
else
1040+
l_result := 0;
1041+
end if;
1042+
else
1043+
--We just process single tag.
1044+
l_left_side := l_tags;
1045+
l_left_side := regexp_replace(l_left_side,l_right_side_regex,'\2');
1046+
if regexp_count(l_left_side,l_rigth_side_expression) > 0 then
1047+
l_result := 0;
1048+
end if;
1049+
end if;
1050+
1051+
return l_result;
1052+
end;
9921053

9931054
end ut_utils;
9941055
/

source/core/ut_utils.pks

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,11 @@ create or replace package ut_utils authid definer is
476476
* Return value of interval in plain english
477477
*/
478478
function interval_to_text(a_interval yminterval_unconstrained) return varchar2;
479-
479+
480+
/*
481+
* Return number 1 or 0 if the list of tags is valid expression
482+
*/
483+
function valid_tag_expression(a_tags in varchar2) return number;
484+
480485
end ut_utils;
481486
/

0 commit comments

Comments
 (0)