@@ -1011,15 +1011,17 @@ create or replace package body ut_utils is
10111011 l_token varchar2(32767);
10121012 l_expect_operand boolean := true;
10131013 l_expect_operator boolean := false;
1014+ l_idx pls_integer;
10141015 begin
10151016 --Tokenize a string into operators and tags
10161017 select regexp_substr(l_tags,'([^!()|&]+)|([!()|&])', 1, level) as string_parts
10171018 bulk collect into l_input_tokens
10181019 from dual connect by regexp_substr (l_tags, '([^!()|&]+)|([!()|&])', 1, level) is not null;
10191020
1021+ l_idx := l_input_tokens.first;
10201022 --Exuecute modified shunting algorithm
1021- for token in 1..l_input_tokens.count loop
1022- l_token := l_input_tokens(token );
1023+ WHILE (l_idx is not null) loop
1024+ l_token := l_input_tokens(l_idx );
10231025 if (l_token member of gc_operators and l_token member of gc_binary_operator) then
10241026 if not(l_expect_operator) then
10251027 raise ex_invalid_tag_expression;
@@ -1028,21 +1030,21 @@ create or replace package body ut_utils is
10281030 l_rnp_tokens.extend;
10291031 l_rnp_tokens(l_rnp_tokens.last) := l_operator_stack.pop;
10301032 end loop;
1031- l_operator_stack.push(l_input_tokens(token ));
1033+ l_operator_stack.push(l_input_tokens(l_idx ));
10321034 l_expect_operand := true;
10331035 l_expect_operator:= false;
10341036 elsif (l_token member of gc_operators and l_token member of gc_unary_operator) then
10351037 if not(l_expect_operand) then
10361038 raise ex_invalid_tag_expression;
10371039 end if;
1038- l_operator_stack.push(l_input_tokens(token ));
1040+ l_operator_stack.push(l_input_tokens(l_idx ));
10391041 l_expect_operand := true;
10401042 l_expect_operator:= false;
10411043 elsif l_token = '(' then
10421044 if not(l_expect_operand) then
10431045 raise ex_invalid_tag_expression;
10441046 end if;
1045- l_operator_stack.push(l_input_tokens(token ));
1047+ l_operator_stack.push(l_input_tokens(l_idx ));
10461048 l_expect_operand := true;
10471049 l_expect_operator:= false;
10481050 elsif l_token = ')' then
@@ -1066,6 +1068,7 @@ create or replace package body ut_utils is
10661068 l_expect_operand := false;
10671069 end if;
10681070
1071+ l_idx := l_input_tokens.next(l_idx);
10691072 end loop;
10701073
10711074 while l_operator_stack.top > 0 loop
@@ -1091,25 +1094,28 @@ create or replace package body ut_utils is
10911094 l_right_side varchar2(32767);
10921095 l_left_side varchar2(32767);
10931096 l_infix_exp varchar2(32767);
1097+ l_idx pls_integer;
10941098 begin
1095- for i in 1..a_postfix_exp.count loop
1099+ l_idx := a_postfix_exp.first;
1100+ while (l_idx is not null) loop
10961101 --If token is operand but also single tag
1097- if a_postfix_exp(i ) not member of gc_operators then --its operand
1098- l_infix_stack.push(a_postfix_exp(i ));
1102+ if a_postfix_exp(l_idx ) not member of gc_operators then --its operand
1103+ l_infix_stack.push(a_postfix_exp(l_idx ));
10991104 --If token is unary operator not
1100- elsif a_postfix_exp(i ) member of gc_unary_operator then
1105+ elsif a_postfix_exp(l_idx ) member of gc_unary_operator then
11011106 l_right_side := l_infix_stack.pop;
1102- l_infix_exp := '('||a_postfix_exp(i )||l_right_side||')';
1107+ l_infix_exp := '('||a_postfix_exp(l_idx )||l_right_side||')';
11031108 l_infix_stack.push(l_infix_exp);
11041109 --If token is binary operator
1105- elsif a_postfix_exp(i ) member of gc_binary_operator then
1110+ elsif a_postfix_exp(l_idx ) member of gc_binary_operator then
11061111 l_right_side := l_infix_stack.pop;
11071112 l_left_side := l_infix_stack.pop;
1108- l_infix_exp := '('||l_left_side||a_postfix_exp(i )||l_right_side||')';
1113+ l_infix_exp := '('||l_left_side||a_postfix_exp(l_idx )||l_right_side||')';
11091114 l_infix_stack.push(l_infix_exp);
11101115 else
11111116 null;
11121117 end if;
1118+ l_idx := a_postfix_exp.next(l_idx);
11131119 end loop;
11141120
11151121 return l_infix_stack.pop;
@@ -1122,28 +1128,31 @@ create or replace package body ut_utils is
11221128 l_left_side varchar2(32767);
11231129 l_infix_exp varchar2(32767);
11241130 l_member_token varchar2(20) := ' member of tags';
1131+ l_idx pls_integer;
11251132 begin
1126- for i in 1..a_postfix_exp.count loop
1133+ l_idx := a_postfix_exp.first;
1134+ while ( l_idx is not null) loop
11271135 --If token is operand but also single tag
1128- if regexp_count(a_postfix_exp(i ),'[!()|&]') = 0 then
1129- l_infix_stack.push(q'[']'||a_postfix_exp(i )||q'[']'||l_member_token);
1136+ if regexp_count(a_postfix_exp(l_idx ),'[!()|&]') = 0 then
1137+ l_infix_stack.push(q'[']'||a_postfix_exp(l_idx )||q'[']'||l_member_token);
11301138 --If token is operand but containing other expressions
1131- elsif a_postfix_exp(i ) not member of gc_operators then
1132- l_infix_stack.push(a_postfix_exp(i ));
1139+ elsif a_postfix_exp(l_idx ) not member of gc_operators then
1140+ l_infix_stack.push(a_postfix_exp(l_idx ));
11331141 --If token is unary operator not
1134- elsif a_postfix_exp(i ) member of gc_unary_operator then
1142+ elsif a_postfix_exp(l_idx ) member of gc_unary_operator then
11351143 l_right_side := l_infix_stack.pop;
1136- l_infix_exp := a_postfix_exp(i )||'('||l_right_side||')';
1144+ l_infix_exp := a_postfix_exp(l_idx )||'('||l_right_side||')';
11371145 l_infix_stack.push(l_infix_exp);
11381146 --If token is binary operator
1139- elsif a_postfix_exp(i ) member of gc_binary_operator then
1147+ elsif a_postfix_exp(l_idx ) member of gc_binary_operator then
11401148 l_right_side := l_infix_stack.pop;
11411149 l_left_side := l_infix_stack.pop;
1142- l_infix_exp := '('||l_left_side||a_postfix_exp(i )||l_right_side||')';
1150+ l_infix_exp := '('||l_left_side||a_postfix_exp(l_idx )||l_right_side||')';
11431151 l_infix_stack.push(l_infix_exp);
11441152 else
11451153 null;
11461154 end if;
1155+ l_idx := a_postfix_exp.next(l_idx);
11471156 end loop;
11481157
11491158 return l_infix_stack.pop;
0 commit comments