[squeak-dev] HtmlParser MNU: ByteString>>replaceHtmlCharRefs

Chris Cunnington brasspen at gmail.com
Sun Oct 22 17:33:08 UTC 2017


>Dear Squeakers,

>I tried to parse an HTML file like this in a trunk image and ran into a MNU:
>FileStream fileNamed: ’some.html’ do: [:stream | HtmlParser parse: stream]

>In HtmlText>>#initialize the message #replaceHtmlCharRefs is sent. I suppose this method was once the image. Otherwise HtmlPar>ser would never have worked. How can I find out, when it got lost? How would you do it?

>Cheers,
>Bernhard
Go to the files archive and start opening old images to find what was removed. Your method is in a 3.2 image. 
I have old images lying around on my desktops and I cannot get off the couch right now, so I thought I’d look for it. 
Googling your selector “replaceHtmlCharRefs” would show that Steph had the same problem in 2009. 

Chris 


String>>#replaceHtmlCharRefs

        | pos ampIndex scIndex special specialValue outString outPos newOutPos |

        outString _ String new: self size.
        outPos _ 0.

        pos _ 1.
        
        [ pos <= self size ] whileTrue: [ 
                "read up to the next ampersand"
                ampIndex _ self indexOf: $& startingAt: pos ifAbsent: [0].
                
                ampIndex = 0 ifTrue: [
                        pos = 1 ifTrue: [ ^self ] ifFalse: [ ampIndex _ self size+1 ] ].

                newOutPos _ outPos + ampIndex - pos.
                outString
                        replaceFrom: outPos + 1
                        to: newOutPos
                        with: self
                        startingAt: pos.
                outPos _ newOutPos.
                pos _ ampIndex.

                ampIndex <= self size ifTrue: [
                        "find the $;"
                        scIndex _ self indexOf: $; startingAt: ampIndex ifAbsent: [ self size + 1 ].

                        special _ self copyFrom: ampIndex+1 to: scIndex-1.       
                        specialValue _ HtmlEntity valueOfHtmlEntity: special. 

                        specialValue
                                ifNil: [
                                        "not a recognized entity.  wite it back"
								  scIndex > self size ifTrue: [ scIndex _ self size ].

                                        newOutPos _ outPos + scIndex - ampIndex + 1.
                                        outString
                                                replaceFrom: outPos+1
                                                to: newOutPos
                                                with: self
                                                startingAt: ampIndex.
                                        outPos _ newOutPos.]
                                ifNotNil: [
                                        outPos _ outPos + 1.
                                        outString at: outPos put: specialValue.].
                        
                        pos _ scIndex + 1. ]. ].


        ^outString copyFrom: 1 to: outPos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20171022/9b224e28/attachment.html>


More information about the Squeak-dev mailing list