@@ -23,7 +23,8 @@ create or replace package body ut_utils is
2323 gc_invalid_xml_char constant varchar2(50) := '[^_[:alnum:]\.-]';
2424 gc_full_valid_xml_name constant varchar2(50) := '^([[:alpha:]])([_[:alnum:]\.-])*$';
2525 gc_owner_hash constant integer(11) := dbms_utility.get_hash_value( ut_owner(), 0, power(2,31)-1);
26-
26+ gc_open_chars constant varchar2(4):= chr(91) || chr(123) || chr(40) || chr(60); -- [{(
27+ gc_close_chars constant varchar2(4):= chr(93) || chr(125) || chr(41) || chr(62); -- ]})>
2728
2829 function surround_with(a_value varchar2, a_quote_char varchar2) return varchar2 is
2930 begin
@@ -674,10 +675,7 @@ create or replace package body ut_utils is
674675 l_pos binary_integer;
675676 l_end binary_integer;
676677 l_token_count binary_integer;
677- l_has_ml_comment boolean := false;
678-
679- l_open_chars varchar2(4):= chr(91) || chr(123) || chr(40) || chr(60); -- [{(
680- l_close_chars varchar2(4):= chr(93) || chr(125) || chr(41) || chr(62); -- ]})>
678+ l_has_ml_comment boolean := false;
681679 begin
682680
683681 -- Guard: empty source
@@ -686,19 +684,17 @@ create or replace package body ut_utils is
686684 end if;
687685
688686 -- Fast pre-scan: check if any /* exists at all if not, nothing to do — return source as-is
689- <<prescan>>
690687 for i in 1 .. a_source.count loop
691688 if instr(a_source(i), '/*') > 0 then
692689 l_has_ml_comment := true;
693- exit prescan ;
690+ exit;
694691 end if;
695- end loop prescan ;
692+ end loop;
696693
697694 if not l_has_ml_comment then
698695 return a_source;
699696 end if;
700697
701- <<process_lines>>
702698 for i in 1 .. a_source.count loop
703699 l_line := a_source(i);
704700
@@ -711,7 +707,7 @@ create or replace package body ut_utils is
711707 -- fall through to normal scan of remainder of line, in case there are more /* comments on the same line
712708 else
713709 l_result(i) := '';
714- continue process_lines ;
710+ continue;
715711 end if;
716712 end if;
717713
@@ -721,7 +717,7 @@ create or replace package body ut_utils is
721717 and instr(l_line, '''') = 0
722718 then
723719 l_result(i) := l_line;
724- continue process_lines ;
720+ continue;
725721 end if;
726722
727723 -- Normal scan: consume one token at a time, advance l_remaining until end of line
@@ -731,16 +727,11 @@ create or replace package body ut_utils is
731727 <<scan_line>>
732728 loop
733729 exit when l_remaining is null or l_remaining = '';
734-
735730 l_ml_start := instr(l_remaining, '/*');
736731 l_comment_start := instr(l_remaining, '--');
737732 l_text_start := instr(l_remaining, '''');
738733 -- only search for q' if ' was found — q' always contains ' and would be misidentified otherwise
739- l_eq_text_start := case when l_text_start > 0
740- then instr(l_remaining, 'q''')
741- else 0
742- end;
743-
734+ l_eq_text_start := case when l_text_start > 0 then instr(l_remaining, 'q''') else 0 end;
744735 -- count how many tokens are present to decide if we can skip LEAST/GREATEST and just use the one that is present
745736 l_token_count := sign(l_ml_start) + sign(l_comment_start)
746737 + sign(l_text_start) + sign(l_eq_text_start);
@@ -756,55 +747,50 @@ create or replace package body ut_utils is
756747 l_pos := greatest(l_ml_start, l_comment_start, l_text_start, l_eq_text_start);
757748 else
758749 l_pos := least(
759- case when l_ml_start > 0 then l_ml_start else 32767 end,
750+ case when l_ml_start > 0 then l_ml_start else 32767 end,
760751 case when l_comment_start > 0 then l_comment_start else 32767 end,
761- case when l_text_start > 0 then l_text_start else 32767 end,
752+ case when l_text_start > 0 then l_text_start else 32767 end,
762753 case when l_eq_text_start > 0 then l_eq_text_start else 32767 end
763754 );
764755 end if;
765756
766757 -- q-quoted string: checked before plain quote because q' contains ' and would be misidentified
767758 if l_pos = l_eq_text_start
768- and (l_ml_start = 0 or l_eq_text_start < l_ml_start)
759+ and (l_ml_start = 0 or l_eq_text_start < l_ml_start)
769760 and (l_comment_start = 0 or l_eq_text_start < l_comment_start)
770- and (l_text_start = 0 or l_eq_text_start < l_text_start)
761+ and (l_text_start = 0 or l_eq_text_start < l_text_start)
771762 then
772-
773-
774- l_eq_end_char := translate(substr(l_remaining, l_eq_text_start + 2, 1),l_open_chars,l_close_chars);
763+ l_eq_end_char := translate(substr(l_remaining, l_eq_text_start + 2, 1),gc_open_chars,gc_close_chars);
775764 l_end := instr(l_remaining, l_eq_end_char || '''', l_eq_text_start + 3);
776765 if l_end > 0 then
777- l_line := l_line || substr(l_remaining, 1, l_end + 1);
766+ l_line := l_line || substr(l_remaining, 1, l_end + 1);
778767 l_remaining := substr(l_remaining, l_end + 2);
779768 else
780769 l_line := l_line || l_remaining;
781770 exit scan_line;
782771 end if;
783-
784772 -- Multi-line comment start: skip it, look for end of comment, continue scanning line after it
785773 elsif l_pos = l_ml_start
786774 and (l_comment_start = 0 or l_ml_start < l_comment_start)
787- and (l_text_start = 0 or l_ml_start < l_text_start)
775+ and (l_text_start = 0 or l_ml_start < l_text_start)
788776 and (l_eq_text_start = 0 or l_ml_start < l_eq_text_start)
789777 then
790- l_line := l_line || substr(l_remaining, 1, l_ml_start - 1);
778+ l_line := l_line || substr(l_remaining, 1, l_ml_start - 1);
791779 l_ml_end := instr(l_remaining, '*/', l_ml_start + 2);
792780 if l_ml_end > 0 then
793781 l_remaining := substr(l_remaining, l_ml_end + 2);
794782 else
795783 l_in_ml_comment := true;
796784 exit scan_line;
797785 end if;
798-
799786 -- Single-line comment: keep it, stop scanning this line since everything after -- is comment anyway
800787 elsif l_pos = l_comment_start
801- and (l_ml_start = 0 or l_comment_start < l_ml_start)
802- and (l_text_start = 0 or l_comment_start < l_text_start)
788+ and (l_ml_start = 0 or l_comment_start < l_ml_start)
789+ and (l_text_start = 0 or l_comment_start < l_text_start)
803790 and (l_eq_text_start = 0 or l_comment_start < l_eq_text_start)
804791 then
805792 l_line := l_line || l_remaining;
806793 exit scan_line;
807-
808794 -- Regular string literal start: keep it, scan forward for closing quote, handle '' escaped quotes properly by skipping them and keep scanning
809795 else
810796 -- scan forward continuously to handle '' escaped quotes
@@ -820,20 +806,17 @@ create or replace package body ut_utils is
820806 end loop;
821807
822808 if l_end > 0 then
823- l_line := l_line || substr(l_remaining, 1, l_end);
809+ l_line := l_line || substr(l_remaining, 1, l_end);
824810 l_remaining := substr(l_remaining, l_end + 1);
825811 else
826812 l_line := l_line || l_remaining;
827813 exit scan_line;
828814 end if;
829- end if;
830815
816+ end if;
831817 end loop scan_line;
832-
833818 l_result(i) := l_line;
834-
835- end loop process_lines;
836-
819+ end loop;
837820 return l_result;
838821 end replace_multiline_comments;
839822
@@ -895,7 +878,7 @@ create or replace package body ut_utils is
895878 and (l_escaped_text_start < l_comment_start or l_comment_start = 0) and (l_escaped_text_start < l_text_start or l_text_start = 0)
896879 then
897880 --translate char "[" from the start of quoted text "q'[someting]'" into "]"
898- l_escaped_text_end_char := translate(substr(a_source, l_escaped_text_start + 2, 1),l_open_chars,l_close_chars );
881+ l_escaped_text_end_char := translate(substr(a_source, l_escaped_text_start + 2, 1),gc_open_chars,gc_close_chars );
899882 l_end := instr(a_source,l_escaped_text_end_char||'''',l_escaped_text_start + 3 );
900883 if l_end > 0 then
901884 l_end := l_end + 2;
0 commit comments