HTMLUtilities.st
changeset 2500 c67839870a9c
parent 2464 ebff59707514
child 2522 a7ff39418d38
equal deleted inserted replaced
2499:9a5dcca2130a 2500:c67839870a9c
     7  inclusion of the above copyright notice.   This software may not
     7  inclusion of the above copyright notice.   This software may not
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 'From Smalltalk/X, Version:6.1.1 on 13-07-2010 at 09:19:13'                     !
       
    13 
       
    14 "{ Package: 'stx:libbasic2' }"
    12 "{ Package: 'stx:libbasic2' }"
    15 
    13 
    16 Object subclass:#HTMLUtilities
    14 Object subclass:#HTMLUtilities
    17 	instanceVariableNames:''
    15 	instanceVariableNames:''
    18 	classVariableNames:'EscapeControlCharacters'
    16 	classVariableNames:'EscapeControlCharacters'
   212     "
   210     "
   213 
   211 
   214     "Modified: / 08-07-2009 / 12:40:56 / sr"
   212     "Modified: / 08-07-2009 / 12:40:56 / sr"
   215 !
   213 !
   216 
   214 
   217 urlEncoded: aString
   215 urlEncode:aStringOrStream on:ws
   218     "helper to escape invalid/dangerous characters in an urls arguments or post-fields.
   216     "helper to escape invalid/dangerous characters in an urls arguments or post-fields.
   219         see: application/x-www-form-urlencoded
   217         see: application/x-www-form-urlencoded"
   220     "
   218 
   221 
   219     |rs c space|
   222 "
       
   223 self unEscape:(self urlEncoded:'_-.*Frankfurt(Main) Hbf')
       
   224 self urlEncoded:'_-.*Frankfurt(Main) Hbf') unescape
       
   225 
       
   226 self unEscape:(self urlEncoded:'-_.*%exept;')
       
   227 self urlEncoded:'-_.*%exept;'
       
   228 "
       
   229 
       
   230     | rs ws c space|
       
   231 
   220 
   232     space := Character space.
   221     space := Character space.
   233     rs := ReadStream on: aString.
   222     rs := aStringOrStream readStream.
   234     ws := WriteStream on: ''.
   223 
   235 
   224     [rs atEnd] whileFalse: [
   236     [ rs atEnd ] whileFalse: [
       
   237         c := rs next.
   225         c := rs next.
   238 
   226 
   239         c isLetterOrDigit ifTrue:[
   227         c isLetterOrDigit ifTrue:[
   240             ws nextPut:c.
   228             ws nextPut:c.
   241         ] ifFalse:[
   229         ] ifFalse:[
   249                     c codePoint printOn:ws base:16 size:2 fill:$0.
   237                     c codePoint printOn:ws base:16 size:2 fill:$0.
   250                 ].
   238                 ].
   251             ].
   239             ].
   252         ].
   240         ].
   253     ].
   241     ].
       
   242 !
       
   243 
       
   244 urlEncoded: aString
       
   245     "helper to escape invalid/dangerous characters in an urls arguments or post-fields.
       
   246         see: application/x-www-form-urlencoded "
       
   247 
       
   248     |ws|
       
   249 
       
   250     ws := WriteStream on: ''.
       
   251     self urlEncode:aString on:ws.
   254     ^ ws contents
   252     ^ ws contents
   255 
   253 
   256 
   254 
   257     "
   255     "
   258      self escape:'a b'      
   256       self unEscape:(self urlEncoded:'_-.*Frankfurt(Main) Hbf')
   259      self escape:'a%b'    
   257       self urlEncoded:'_-.*Frankfurt(Main) Hbf'
   260      self escape:'a b'      
   258 
   261      self escape:'a+b'      
   259       self unEscape:(self urlEncoded:'-_.*%exept;')
       
   260       self urlEncoded:'-_.*%exept;'
   262     "
   261     "
   263 
   262 
   264     "Modified: / 12-07-2010 / 16:49:44 / cg"
   263     "Modified: / 12-07-2010 / 16:49:44 / cg"
   265 !
   264 !
   266 
   265 
   428 ! !
   427 ! !
   429 
   428 
   430 !HTMLUtilities class methodsFor:'documentation'!
   429 !HTMLUtilities class methodsFor:'documentation'!
   431 
   430 
   432 version
   431 version
   433     ^ '$Header: /cvs/stx/stx/libbasic2/HTMLUtilities.st,v 1.11 2010-07-13 12:16:28 stefan Exp $'
   432     ^ '$Header: /cvs/stx/stx/libbasic2/HTMLUtilities.st,v 1.12 2010-11-01 20:35:57 stefan Exp $'
   434 !
   433 !
   435 
   434 
   436 version_CVS
   435 version_CVS
   437     ^ '$Header: /cvs/stx/stx/libbasic2/HTMLUtilities.st,v 1.11 2010-07-13 12:16:28 stefan Exp $'
   436     ^ '$Header: /cvs/stx/stx/libbasic2/HTMLUtilities.st,v 1.12 2010-11-01 20:35:57 stefan Exp $'
   438 ! !
   437 ! !