The Trunk: Collections-mt.630.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Collections-mt.630.mcz

commits-2
Marcel Taeumel uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-mt.630.mcz

==================== Summary ====================

Name: Collections-mt.630
Author: mt
Time: 3 May 2015, 8:49:41.443 pm
UUID: c6ffc6e0-978d-da42-acdb-4917691a695c
Ancestors: Collections-mt.629

HTML escaping added to html read/writer

=============== Diff against Collections-mt.629 ===============

Item was changed:
  ----- Method: HtmlReadWriter>>processEndTag: (in category 'reading') -----
  processEndTag: aTag
 
  | index |
  index := count - offset.
 
+ aTag = '</br>' ifTrue: [
+ string add: Character cr.
+ count := count + 1.
+ ^ self].
+
  "De-Accumulate adjacent tags."
  runStack top at: 4 put: runStack top fourth - 1.
  runStack top fourth > 0
  ifTrue: [^ self "not yet"].
 
  self processRunStackTop.
 
  runStack pop.
  runStack top at: 2 put: index + 1.!

Item was added:
+ ----- Method: HtmlReadWriter>>processHtmlEscape: (in category 'reading') -----
+ processHtmlEscape: aString
+
+ (String htmlEntities at: (aString copyFrom: 2 to: aString size - 1) ifAbsent: [])
+ ifNotNil: [:char |
+ string add: char.
+ count := count + 1].!

Item was changed:
  ----- Method: HtmlReadWriter>>processNextTag (in category 'reading') -----
  processNextTag
 
+ | tag htmlEscape lookForNewTag lookForHtmlEscape tagFound valid |
- | tag lookForNewTag escapeNextCharacter tagFound |
  lookForNewTag := true.
+ lookForHtmlEscape := false.
  tagFound := false.
  tag := OrderedCollection new.
+ htmlEscape := OrderedCollection new.
- escapeNextCharacter := false.
 
  [stream atEnd not and: [tagFound not]] whileTrue: [
  | character |
  character := stream next.
+ valid := (#(10 13) includes: character asciiValue) not.
  count := count + 1.
 
+ character = $< ifTrue: [lookForNewTag := false].
+ character = $& ifTrue: [lookForHtmlEscape := true].
- escapeNextCharacter
- ifTrue: [string add: character. escapeNextCharacter := false]
- ifFalse: [
- character = $\
- ifTrue: [offset := offset + 1. escapeNextCharacter := true]
- ifFalse: [
- character = $< ifTrue: [lookForNewTag := false].
- character = $> ifTrue: [lookForNewTag := true].
 
+ lookForNewTag
+ ifTrue: [
+ lookForHtmlEscape
+ ifFalse: [valid ifTrue: [string add: character] ifFalse: [offset := offset + 1]]
+ ifTrue: [valid ifTrue: [htmlEscape add: character]. offset := offset + 1]]
+ ifFalse: [valid ifTrue: [tag add: character]. offset := offset + 1].
+
+ character = $> ifTrue: [
+ lookForNewTag := true.
+ "Full tag like <b> or </b> found."
+ tag second ~= $/
+ ifTrue: [self processStartTag: (String withAll: tag)]
+ ifFalse: [self processEndTag: (String withAll: tag)].
+ tagFound := true].
+
+ character = $; ifTrue: [
+ lookForHtmlEscape := false.
+ self processHtmlEscape: (String withAll: htmlEscape).
+ htmlEscape := OrderedCollection new]].
- (lookForNewTag and: [character ~= $>])
- ifTrue: [string add: character]
- ifFalse: [tag add: character. offset := offset + 1]..
-
- (tag notEmpty and: [tag last = $>]) ifTrue: [
- "Full tag like <b> or </b> found."
- tag second ~= $/
- ifTrue: [self processStartTag: (String withAll: tag)]
- ifFalse: [self processEndTag: (String withAll: tag)].
- tagFound := true]]]].
  !

Item was changed:
  ----- Method: HtmlReadWriter>>processStartTag: (in category 'reading') -----
  processStartTag: aTag
 
  | index |
  index := count - offset.
 
+ aTag = '<br>' ifTrue: [
+ string add: Character cr.
+ count := count + 1.
+ ^ self].
+
  "Accumulate adjacent tags."
  (runStack size > 1 and: [runStack top second = (index + 1) "= adjacent start tags"])
  ifTrue: [
  runStack top at: 1 put: (runStack top first copy addAll: (self mapTagToAttribute: aTag); yourself).
  runStack top at: 4 put: (runStack top fourth + 1). "increase number of open tags"
  ^self].
 
  self processRunStackTop.
 
  "Remove start/end info to reuse attributes later."
  runStack top at: 2 put: nil.
  runStack top at: 3 put: nil.
  "Copy attr list and add new attr."
  runStack push: ({runStack top first copy addAll: (self mapTagToAttribute: aTag); yourself. index + 1. nil. 1}).!

Item was changed:
  ----- Method: HtmlReadWriter>>writeContent: (in category 'writing') -----
  writeContent: aString
 
+ aString do: [:char |
+ (#(10 13) includes: char asciiValue)
+ ifTrue: [stream nextPutAll: '<br>'; cr]
+ ifFalse: [char = Character tab
+ ifTrue: [stream nextPutAll: '&nbsp;&nbsp;&nbsp;&nbsp;']
+ ifFalse: [(String htmlEntities keyAtValue: char ifAbsent: [])
+ ifNil: [stream nextPut: char]
+ ifNotNil: [:escapeSequence |
+ stream
+ nextPut: $&;
+ nextPutAll: escapeSequence;
+ nextPut: $;]]]].!
- | html |
- html := aString.
- ""
- html := html copyReplaceAll: '&' with: '&amp;'.
- html := html copyReplaceAll: '>' with: '&gt;'.
- html := html copyReplaceAll: '<' with: '&lt;'.
- ""
- html := html copyReplaceAll: '¬¨¬®¬¨¬é¬¨¬®¬¨¦Ö' with: '&aacute;'.
- html := html copyReplaceAll: '¬¨¬Ž¬¨¬©' with: '&eacute;'.
- html := html copyReplaceAll: '¬¨¬®¬¨¬é¬¨¬®¬¶¦ë' with: '&iacute;'.
- html := html copyReplaceAll: '¬¨¬®¬¨¬é¬¨¬®¬¶¦ü' with: '&oacute;'.
- html := html copyReplaceAll: '¬¨¬Ž¬¨¦š' with: '&uacute;'.
- html := html copyReplaceAll: '¬¨¬Ž¬¨¬±' with: '&ntilde;'.
- ""
- html := html copyReplaceAll: '¬¨¬®¬¨¬é¬¨¬Ž¬¶¦±' with: '&Aacute;'.
- html := html copyReplaceAll: '¬¨¬®¬¨¬é¬¨¬Ž¬¨¬¢' with: '&Eacute;'.
- html := html copyReplaceAll: '¬¨¬®¬¨¬é¬¨¬Ž¬¶¦º' with: '&Iacute;'.
- html := html copyReplaceAll: '¬¨¬®¬¨¬é¬¨¬Ž¬¨¬Æ' with: '&Oacute;'.
- html := html copyReplaceAll: '¬¨¬®¬¨¬é¬¨¬Ž¬¨¦©' with: '&Uacute;'.
- html := html copyReplaceAll: '¬¨¬®¬¨¬é¬¨¬Ž¬¨¬·' with: '&Ntilde;'.
- ""
- html := html copyReplaceAll: '
- ' with: '<br>
- '.
- html := html copyReplaceAll: ' ' with: '&nbsp;&nbsp;&nbsp;&nbsp;'.
- ""
- stream nextPutAll: html!

Item was changed:
  ----- Method: HtmlReadWriter>>writeEndTagFor: (in category 'writing') -----
  writeEndTagFor: aTextAttribute
 
+ [aTextAttribute closeHtmlOn: stream]
+ on: MessageNotUnderstood do: []!
- aTextAttribute closeHtmlOn: stream.!

Item was changed:
  ----- Method: HtmlReadWriter>>writeStartTagFor: (in category 'writing') -----
  writeStartTagFor: aTextAttribute
 
+ [aTextAttribute openHtmlOn: stream]
+ on: MessageNotUnderstood do: [].!
- aTextAttribute openHtmlOn: stream.!

Item was added:
+ ----- Method: String class>>htmlEntities (in category 'accessing') -----
+ htmlEntities
+
+ ^ HtmlEntities!