[firebase-br] Ajuda para criar função

Christian e Ana Luiza Britto chriseana em gmail.com
Sex Dez 25 23:32:30 -03 2015


Olá a todos,
 Espero que estejam bem e preparando-se para as festas.
 Sei que a data não é muito oportuna, mas preciso de ajuda.
 Tenho esta função que me ajudaram a escrever para o PostgreSQL e agora
 preciso traduzí-la para o Firebird. Mas, não sei bem como fazer.
 Por favor, alguém pode me ajudar? Trata-se de uma rotina que retira
 todos os córigos HTML de um campo caracter.

 -- Name: strip_html(text); Type: FUNCTION; Schema: public; Owner: postgres
 --

 CREATE FUNCTION strip_html(t text) RETURNS text
     LANGUAGE plpgsql IMMUTABLE
     AS $$
 declare
     r record;
 begin
     for r in
         select distinct ce.ch, ce.name
         from
             character_entity ce
             inner join (
                 select name[1] "name"
                 from regexp_matches(t, '&([A-Za-z]+?);', 'g') r(name)
             ) s on ce.name = s.name
     loop
         t := replace(t, '&' || r.name || ';', r.ch);
     end loop;

     for r in
         select distinct
             hex[1] hex,
             ('x' || repeat('0', 8 - length(hex[1])) ||
 hex[1])::bit(32)::int codepoint
         from regexp_matches(t, '&x([0-9a-f]{1,8}?);', 'gi') s(hex)
     loop
         t := regexp_replace(t, '&x' || r.hex || ';', chr(r.codepoint), 'gi');
     end loop;

     for r in
         select distinct
             chr(codepoint[1]::int) ch,
             codepoint[1] codepoint
         from regexp_matches(t, '&([0-9]{1,10}?);', 'g') s(codepoint)
     loop
         t := replace(t, '&' || r.codepoint || ';', r.ch);
     end loop;

     -- return strip_some_html_codes(t);
     return regexp_replace(regexp_replace(t, E'(?x)<[^>]*?(\s alt \s* =
 \s* ([\'"]) ([^>]*?) \2) [^>]*? >', E'\3'), E'(?x)(< [^>]*? >)', '',
 'g');
 end;

Grande abraço,
Christian




Mais detalhes sobre a lista de discussão lista