Here is my 'Icon' solution:

procedure Flatten(sTag)

    local   sBegin
    local   sEnd
    local   sIn
    local   sOut
    local   iNest
    local   iBegin
    
    sBegin := "<" || sTag || ">"
    sEnd := "</" || sTag || ">"
    iNest := 0
        
    while sIn := read() do sIn ? {
        sOut := ""
        while sOut ||:= tab(find("<")) do {
            iBegin := if match(sBegin) then 1 else 0
            if match(sEnd) then iNest -:= 1
            ((0 ~= iNest) & =(sBegin | sEnd)) | (sOut ||:= move(1))
            iNest +:= iBegin
        }
        suspend sOut || tab(0)
    }
    
end


procedure main(LArguments)

    every write(Flatten(LArguments[1]))

end



The algorithm basically works as follows:

For each "<" on each line:
 a. If we have an end tag, decrement the nesting level
 b. If we are nested and there is begin or end tag, skip the tag
 c. If we have a begin tag, increment the nesting level
-- 
 Nevin ":-)" Liber      <mailto:[EMAIL PROTECTED]>      (773) 961-1620


-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
Unicon-group mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to