@@ -1000,24 +1000,30 @@ create or replace package body ut_utils is
10001000 return l_result;
10011001 end;
10021002
1003+ function tokenize_tags_string(a_tags in varchar2) return ut_varchar2_list is
1004+ l_tags_tokens ut_varchar2_list := ut_varchar2_list();
1005+ begin
1006+ --Tokenize a string into operators and tags
1007+ select regexp_substr(a_tags,'([^!()|&]+)|([!()|&])', 1, level) as string_parts
1008+ bulk collect into l_tags_tokens
1009+ from dual connect by regexp_substr (a_tags, '([^!()|&]+)|([!()|&])', 1, level) is not null;
1010+
1011+ return l_tags_tokens;
1012+ end;
1013+
10031014 /*
10041015 https://stackoverflow.com/questions/29634992/shunting-yard-validate-expression
10051016 */
10061017 function shunt_logical_expression(a_tags in varchar2) return ut_varchar2_list is
10071018 l_tags varchar2(32767) := a_tags;
10081019 l_operator_stack ut_stack := ut_stack();
1009- l_input_tokens ut_varchar2_list := ut_varchar2_list( );
1020+ l_input_tokens ut_varchar2_list := tokenize_tags_string(a_tags );
10101021 l_rnp_tokens ut_varchar2_list := ut_varchar2_list();
10111022 l_token varchar2(32767);
10121023 l_expect_operand boolean := true;
10131024 l_expect_operator boolean := false;
10141025 l_idx pls_integer;
10151026 begin
1016- --Tokenize a string into operators and tags
1017- select regexp_substr(l_tags,'([^!()|&]+)|([!()|&])', 1, level) as string_parts
1018- bulk collect into l_input_tokens
1019- from dual connect by regexp_substr (l_tags, '([^!()|&]+)|([!()|&])', 1, level) is not null;
1020-
10211027 l_idx := l_input_tokens.first;
10221028 --Exuecute modified shunting algorithm
10231029 WHILE (l_idx is not null) loop
@@ -1071,7 +1077,7 @@ create or replace package body ut_utils is
10711077 l_idx := l_input_tokens.next(l_idx);
10721078 end loop;
10731079
1074- while l_operator_stack.top > 0 loop
1080+ while l_operator_stack.peek is not null loop
10751081 if l_operator_stack.peek in ('(',')') then
10761082 raise ex_invalid_tag_expression;
10771083 end if;
@@ -1082,12 +1088,6 @@ create or replace package body ut_utils is
10821088 return l_rnp_tokens;
10831089 end shunt_logical_expression;
10841090
1085- procedure shunt_logical_expression(a_tags in varchar2) is
1086- a_postfix ut_varchar2_list;
1087- begin
1088- a_postfix := ut_utils.shunt_logical_expression(a_tags);
1089- end shunt_logical_expression;
1090-
10911091 function convert_postfix_to_infix(a_postfix_exp in ut_varchar2_list)
10921092 return varchar2 is
10931093 l_infix_stack ut_stack := ut_stack();
@@ -1112,8 +1112,6 @@ create or replace package body ut_utils is
11121112 l_left_side := l_infix_stack.pop;
11131113 l_infix_exp := '('||l_left_side||a_postfix_exp(l_idx)||l_right_side||')';
11141114 l_infix_stack.push(l_infix_exp);
1115- else
1116- null;
11171115 end if;
11181116 l_idx := a_postfix_exp.next(l_idx);
11191117 end loop;
@@ -1149,8 +1147,6 @@ create or replace package body ut_utils is
11491147 l_left_side := l_infix_stack.pop;
11501148 l_infix_exp := '('||l_left_side||a_postfix_exp(l_idx)||l_right_side||')';
11511149 l_infix_stack.push(l_infix_exp);
1152- else
1153- null;
11541150 end if;
11551151 l_idx := a_postfix_exp.next(l_idx);
11561152 end loop;
0 commit comments