Sviluppo4d.it
Sito indipendente di informazioni tecniche per sviluppatori 4th Dimension italiani  

Sviluppatori 4D

Utility 4D

Risorse 4D



4d logo
Naviga: Prev Next

Titolo: Trovare errori nei TAG html [2]

Categoria: Codice Ultimo Aggiornamento: 05/06/06


` ======================================
    ` CHECK HTML TAGS di Roberto Vergani (05-2006)
    ` ======================================

C_TEXT($info;$sourceText;$resultText;$tag)
C_INTEGER($X;$J;$k;$n;$size;$vLineNumber;$startLine;$offset)
C_STRING(2;$char)
C_BOOLEAN($notFound)

ARRAY TEXT($vtErrorText;0)

$size:=Test clipboard("TEXT")

Case of
  : ($size<=0)
    ALERT("Gli appunti non contengono testo, elaborazione interrotta.")
  : ($size>31000)
    ALERT("Il contenuto degli appunti supera i 31K, elaborazione interrotta.")
  Else
    $info:="Questa procedura controlla la parità dei tags HTML"+Char(13)
    $info:=$info+"Procedi dopo avere copiato in appunti il codice sorgente."
    CONFIRM($info;"Procedi";"Annulla")
    
    If (OK=1)
      
          ` ECCEZIONI: questi TAG usualmente non hanno chiusura, SONO IGNORATI
          ` aggiungi o togli quello che vuoi, inserisci senza i delimitatori < >
          ` tutti i tags che iniziano con       
      ARRAY TEXT($vtExceptions;13)
      $vtExceptions{1}:="img"
      $vtExceptions{2}:="br"
      $vtExceptions{3}:="br/"
      $vtExceptions{4}:="input"
      $vtExceptions{5}:="link"
      $vtExceptions{6}:="meta"
      $vtExceptions{7}:="?xml"
      $vtExceptions{8}:="area"
      $vtExceptions{9}:="param"
      $vtExceptions{10}:="base"
      $vtExceptions{11}:="hr"
      $vtExceptions{12}:="frame"
      $vtExceptions{13}:="spacer"
          
      
      ARRAY TEXT($vtRighe;0)
      $SourceText:=Get text from clipboard
      
      If (OK=0)
        ALERT("Si è verificato un errore nel leggere gli appunti (procedura interrotta).")
      Else
        SET CURSOR(4)
        
        ARRAY TEXT($vtTags;0)
        ARRAY INTEGER($vtCount;0)
        ARRAY INTEGER($vtLine;0;0)
        ARRAY INTEGER($vtPosition;0;0)
        $vLineNumber:=1
        $startLine:=1
        $X:=1
        
        If ($size>3000)
          Open window((Screen width-300)/2;(Screen height-150)/2;((Screen width-300)/2)+300;((Screen height-150)/2)+150;1)
        End if
        
        Repeat
          
          $char:=($SourceText?$X?)
          GOTO XY(10;6)
          MESSAGE("Parsing: "+String($X)+" / "+String($size)+" bytes")
          
          Case of
          
           : ($char=Char(13))
           $vLineNumber:=$vLineNumber+1
           $X:=$X+1
           $startLine:=$X
          
           : ($char="<") & (($SourceText?$X+Num($X<($size+1))?)#"!") ` ignora tutti i tag che iniziano con           
           $offset:=1
           Repeat
           $offset:=$offset+1
           Until (($SourceText?$X+$offset?=">") | ($SourceText?$X+$offset?=Char(32)) | ($SourceText?$X+$offset?=Char(13)))
           $tag:=Substring($SourceText;$X+1;$offset-1)
          
           $n:=Find in array($vtExceptions;$tag)
           If ($n=-1) ` se il tag non è un'eccezione da ignorare
           If (Ascii($tag)=47) ` se il tag inizia con ascii 47 = /
           $notFound:=False
           $tag:=Substring($tag;2)
           $n:=Find in array($vtTags;$tag)
           If ($n=-1) ` è chiuso un tag che compare per la prima volta e non è presente nell'elenco dei tag esistenti
           $notFound:=True
           Else
           If (Size of array($vtLine{$n})=0)
           $notFound:=True
           Else
           DELETE ELEMENT($vtLine{$n};Size of array($vtLine{$n}))
           DELETE ELEMENT($vtPosition{$n};Size of array($vtPosition{$n}))
           End if
           End if
           If ($notFound=True)
           INSERT ELEMENT($vtErrorText;Size of array($vtErrorText)+1)
           $vtErrorText{Size of array($vtErrorText)}:=" tag chiuso senza apertura, linea "+String($vLineNumber)+" posizione "+String($X-$startLine+1)
           End if
           Else
           $n:=Find in array($vtTags;$tag)
           If ($n=-1)
           $n:=Size of array($vtTags)+1
           INSERT ELEMENT($vtTags;$n)
           INSERT ELEMENT($vtCount;$n)
           INSERT ELEMENT($vtLine;$n)
           INSERT ELEMENT($vtPosition;$n)
           End if
           $J:=Size of array($vtLine{$n})+1
           INSERT ELEMENT($vtLine{$n};$J)
           INSERT ELEMENT($vtPosition{$n};$J)
           $vtTags{$n}:=$tag
           $vtCount{$n}:=$vtCount{$n}+1
           $vtLine{$n}{$J}:=$vLineNumber
           $vtPosition{$n}{$J}:=$X-$startLine+1
           End if
          
           End if
           $X:=$X+$offset-1
           Else
           $X:=$X+1
          End case
        Until ($X>Length($SourceText))
        
        If ($size>8000)
          CLOSE WINDOW
        End if
        
        $resultText:="CHECK HTML TAGS di Roberto Vergani (05-2006)"+(Char(13)*3)
        $n:=Size of array($vtErrorText)
        $k:=0
        For ($X;1;Size of array($vtLine))
          $k:=$k+Size of array($vtLine{$X})
        End for
        If ($n>0) | ($k>0)
          $resultText:=$resultText+"### SONO STATI RILEVATI ERRORI :"+(Char(13)*2)
          For ($X;1;Size of array($vtLine))
           If (Size of array($vtLine{$X})>0)
           For ($J;1;Size of array($vtLine{$X}))
           $resultText:=$resultText+"<"+$vtTags{$X}+"> tag aperto e non chiuso, linea "+String($vtLine{$X}{$J})+" posizione "+String($vtPosition{$X}{$J})+Char(13)
           End for
           End if
          End for
          $resultText:=$resultText+Char(13)
          For ($X;1;$n)
           $resultText:=$resultText+$vtErrorText{$X}+Char(13)
          End for
          $info:="### RILEVATI ERRORI."+Char(13)
        Else
          $resultText:=$resultText+"Il codice esaminato sembra essere OK."
          $info:="Nessun errore."+Char(13)
        End if
        $resultText:=$resultText+(Char(13)*3)
        $resultText:=$resultText+"Sono stati esaminati:"+(Char(13)*2)
        For ($X;1;Size of array($vtTags))
          $value:=String($vtCount{$X}) ` riutilizzo di variabile
          $resultText:=$resultText+(" "*(5-Length($value)))+$value+" tag <"+$vtTags{$X}+">"+Char(13)
        End for
        SET TEXT TO CLIPBOARD($resultText)
        SET CURSOR(0)
        ALERT($info+"L'esito dell'elaborazione è contenuto negli appunti, incolla dove vuoi.")
      End if
    End if
End case




Inviato da: Roberto Vergani Visite: 12899

Se accedi con utente e password, puoi aggiungere dei commenti.


Accesso

User:
Pass: Accedi

Cerca

Se non trovi le informazioni che cerchi scrivi a aiuto@sviluppo4d.it

4D Principali

4D Discussioni

Faq random


Crediti

Dominio registrato da ZetaNet
Sito realizzato da Nexus srl
4D SQL 11.9.0 offerto da 4D & Italsoftware
Icone di FAMFAMFAM
Moderato da Umberto Migliore
301 utenti registrati

Pagina servita il 19/03/24 alle 09:22:46 Valid HTML 4.01! Valid CSS!

Mutuo Facile, iDigitalScout, iDigitalTags e altre app di Nexid srl per iPhone e iPad

Cidroid, distributore italiano lettori barcode per IOS Apple iPhone, iPod, iPad