@@ -513,7 +513,7 @@ procedure append_to_clob(a_src_clob in out nocopy clob, a_clob_table t_clob_tab,
513513 if a_list is not null then
514514 l_trimmed_list := ut_varchar2_list();
515515 l_index := a_list.first;
516-
516+
517517 while (l_index is not null) loop
518518 l_trimmed_list.extend;
519519 l_trimmed_list(l_trimmed_list.count) := regexp_replace(a_list(l_index), '(^['||a_regexp_to_trim||']*)|(['||a_regexp_to_trim||']*$)');
@@ -531,7 +531,7 @@ procedure append_to_clob(a_src_clob in out nocopy clob, a_clob_table t_clob_tab,
531531 if a_list is not null then
532532 l_filtered_list := ut_varchar2_list();
533533 l_index := a_list.first;
534-
534+
535535 while (l_index is not null) loop
536536 if regexp_like(a_list(l_index), a_regexp_filter) then
537537 l_filtered_list.extend;
@@ -540,9 +540,104 @@ procedure append_to_clob(a_src_clob in out nocopy clob, a_clob_table t_clob_tab,
540540 l_index := a_list.next(l_index);
541541 end loop;
542542 end if;
543-
543+
544544 return l_filtered_list;
545545 end;
546546
547+
548+
549+ function replace_multiline_comments(a_source clob) return clob is
550+ l_result clob;
551+ l_ml_comment_start binary_integer := 1;
552+ l_comment_start binary_integer := 1;
553+ l_text_start binary_integer := 1;
554+ l_escaped_text_start binary_integer := 1;
555+ l_escaped_text_end_char varchar2(1 char);
556+ l_end binary_integer := 1;
557+ l_ml_comment clob;
558+ l_newlines_count binary_integer;
559+ l_offset binary_integer := 1;
560+ l_length binary_integer := coalesce(dbms_lob.getlength(a_source), 0);
561+ function is_before(a_x binary_integer, a_y binary_integer) return boolean is
562+ begin
563+ return a_x < a_y or a_y = 0;
564+ end;
565+ begin
566+ l_ml_comment_start := instr(a_source,'/*');
567+ l_comment_start := instr(a_source,'--');
568+ l_text_start := instr(a_source,'''');
569+ l_escaped_text_start := instr(a_source,q'[q']');
570+ while l_offset > 0 and l_ml_comment_start > 0 loop
571+
572+ if l_ml_comment_start > 0 and (l_ml_comment_start < l_comment_start or l_comment_start = 0)
573+ and (l_ml_comment_start < l_text_start or l_text_start = 0)and (l_ml_comment_start < l_escaped_text_start or l_escaped_text_start = 0)
574+ then
575+ l_end := instr(a_source,'*/',l_ml_comment_start+2);
576+ append_to_clob(l_result, dbms_lob.substr(a_source, l_ml_comment_start-l_offset, l_offset));
577+ if l_end > 0 then
578+ l_ml_comment := substr(a_source, l_ml_comment_start, l_end-l_ml_comment_start);
579+ l_newlines_count := length( l_ml_comment ) - length( translate( l_ml_comment, 'a'||chr(10), 'a') );
580+ if l_newlines_count > 0 then
581+ append_to_clob(l_result, lpad( chr(10), l_newlines_count, chr(10) ) );
582+ end if;
583+ l_end := l_end + 2;
584+ end if;
585+ else
586+
587+ if l_comment_start > 0 and (l_comment_start < l_ml_comment_start or l_ml_comment_start = 0)
588+ and (l_comment_start < l_text_start or l_text_start = 0) and (l_comment_start < l_escaped_text_start or l_escaped_text_start = 0)
589+ then
590+ l_end := instr(a_source,chr(10),l_comment_start+2);
591+ if l_end > 0 then
592+ l_end := l_end + 1;
593+ end if;
594+ elsif l_text_start > 0 and (l_text_start < l_ml_comment_start or l_ml_comment_start = 0)
595+ and (l_text_start < l_comment_start or l_comment_start = 0) and (l_text_start < l_escaped_text_start or l_escaped_text_start = 0)
596+ then
597+ l_end := instr(a_source,q'[']',l_text_start+1);
598+
599+ --skip double quotes while searching for end of quoted text
600+ while l_end > 0 and l_end = instr(a_source,q'['']',l_text_start+1) loop
601+ l_end := instr(a_source,q'[']',l_end+1);
602+ end loop;
603+ if l_end > 0 then
604+ l_end := l_end + 1;
605+ end if;
606+
607+ elsif l_escaped_text_start > 0 and (l_escaped_text_start < l_ml_comment_start or l_ml_comment_start = 0)
608+ 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)
609+ then
610+ --translate char "[" from the start of quoted text "q'[someting]'" into "]"
611+ l_escaped_text_end_char := translate( substr(a_source, l_escaped_text_start + 2, 1), '[{(<', ']})>');
612+ l_end := instr(a_source,l_escaped_text_end_char||'''',l_escaped_text_start + 3 );
613+ if l_end > 0 then
614+ l_end := l_end + 2;
615+ end if;
616+ end if;
617+
618+ if l_end = 0 then
619+ append_to_clob(l_result, dbms_lob.substr(a_source, l_length-l_offset, l_offset));
620+ else
621+ append_to_clob(l_result, dbms_lob.substr(a_source, l_end-l_offset, l_offset));
622+ end if;
623+ end if;
624+ l_offset := l_end;
625+ if l_offset >= l_ml_comment_start then
626+ l_ml_comment_start := instr(a_source,'/*',l_offset);
627+ end if;
628+ if l_offset >= l_comment_start then
629+ l_comment_start := instr(a_source,'--',l_offset);
630+ end if;
631+ if l_offset >= l_text_start then
632+ l_text_start := instr(a_source,'''',l_offset);
633+ end if;
634+ if l_offset >= l_escaped_text_start then
635+ l_escaped_text_start := instr(a_source,q'[q']',l_offset);
636+ end if;
637+ end loop;
638+ append_to_clob(l_result, dbms_lob.substr(a_source, offset=>l_end));
639+ return l_result;
640+ end;
641+
547642end ut_utils;
548643/
0 commit comments