[Pkg-javascript-commits] [ltx] 315/469: More syntax fixes

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:03:21 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository ltx.

commit d47c5983b1c2ed9899202ccbe37f713e8c1bde90
Author: Lloyd Watkin <lloyd at evilprofessor.co.uk>
Date:   Sun Feb 16 20:27:51 2014 +0000

    More syntax fixes
---
 lib/sax/sax_ltx.js      | 197 ++++++++++++++++++++++++------------------------
 lib/sax/sax_node-xml.js |  70 +++++++++--------
 2 files changed, 136 insertions(+), 131 deletions(-)

diff --git a/lib/sax/sax_ltx.js b/lib/sax/sax_ltx.js
index 5824c2d..5c5b737 100644
--- a/lib/sax/sax_ltx.js
+++ b/lib/sax/sax_ltx.js
@@ -29,110 +29,111 @@ var SaxLtx = module.exports = function SaxLtx() {
         }
         var pos = 0
 
-    /* Anything from previous write()? */
-    if (remainder) {
-        data = remainder + data
-        pos += remainder.length
-        delete remainder
-    }
-
-    function endRecording() {
-        if (typeof recordStart === 'number') {
-        var recorded = data.slice(recordStart, pos)
-        recordStart = undefined
-        return recorded
+        /* Anything from previous write()? */
+        if (remainder) {
+            data = remainder + data
+            pos += remainder.length
+            remainder = null
         }
-    }
 
-    for(; pos < data.length; pos++) {
-        var c = data.charCodeAt(pos)
-        //console.log("state", state, "c", c, data[pos])
-        switch(state) {
-        case STATE_TEXT:
-        if (c === 60 /* < */) {
-            var text = endRecording()
-            if (text)
-            this.emit('text', unescapeXml(text))
-            state = STATE_TAG_NAME
-            recordStart = pos + 1
-            attrs = {}
-        }
-        break
-        case STATE_TAG_NAME:
-        if (c === 47 /* / */ && recordStart === pos) {
-            recordStart = pos + 1
-            endTag = true
-        } else if (c === 33 /* ! */ || c === 63 /* ? */) {
-            recordStart = undefined
-            state = STATE_IGNORE_TAG
-        } else if (c <= 32 || c === 47 /* / */ || c === 62 /* > */) {
-            tagName = endRecording()
-            pos--
-            state = STATE_TAG
-        }
-        break
-        case STATE_IGNORE_TAG:
-        if (c === 62 /* > */) {
-            state = STATE_TEXT
-        }
-        break
-        case STATE_TAG:
-        if (c === 62 /* > */) {
-            if (!endTag) {
-            this.emit('startElement', tagName, attrs)
-            if (selfClosing)
-                this.emit('endElement', tagName)
-            } else
-            this.emit('endElement', tagName)
-            tagName = undefined
-            attrs = undefined
-            endTag = undefined
-            selfClosing = undefined
-            state = STATE_TEXT
-            recordStart = pos + 1
-        } else if (c === 47 /* / */) {
-            selfClosing = true
-        } else if (c > 32) {
-            recordStart = pos
-            state = STATE_ATTR_NAME
-        }
-        break
-        case STATE_ATTR_NAME:
-        if (c <= 32 || c === 61 /* = */) {
-            attrName = endRecording()
-            pos--
-            state = STATE_ATTR_EQ
+        function endRecording() {
+            if (typeof recordStart === 'number') {
+                var recorded = data.slice(recordStart, pos)
+                recordStart = undefined
+                return recorded
+            }
         }
-        break
-        case STATE_ATTR_EQ:
-        if (c === 61 /* = */) {
-            state = STATE_ATTR_QUOT
-        }
-        break
-        case STATE_ATTR_QUOT:
-        if (c === 34 /* " */ || c === 39 /* ' */) {
-            attrQuote = c
-            state = STATE_ATTR_VALUE
-            recordStart = pos + 1
-        }
-        break
-        case STATE_ATTR_VALUE:
-        if (c === attrQuote) {
-            var value = unescapeXml(endRecording())
-            attrs[attrName] = value
-            attrName = undefined
-            state = STATE_TAG
-        }
-        break
+
+        for(; pos < data.length; pos++) {
+            var c = data.charCodeAt(pos)
+            //console.log("state", state, "c", c, data[pos])
+            switch(state) {
+            case STATE_TEXT:
+                if (c === 60 /* < */) {
+                    var text = endRecording()
+                    if (text) {
+                        this.emit('text', unescapeXml(text))
+                    }
+                    state = STATE_TAG_NAME
+                    recordStart = pos + 1
+                    attrs = {}
+                }
+                break
+            case STATE_TAG_NAME:
+                if (c === 47 /* / */ && recordStart === pos) {
+                    recordStart = pos + 1
+                    endTag = true
+                } else if (c === 33 /* ! */ || c === 63 /* ? */) {
+                    recordStart = undefined
+                    state = STATE_IGNORE_TAG
+                } else if (c <= 32 || c === 47 /* / */ || c === 62 /* > */) {
+                    tagName = endRecording()
+                    pos--
+                    state = STATE_TAG
+                }
+                break
+            case STATE_IGNORE_TAG:
+                if (c === 62 /* > */) {
+                    state = STATE_TEXT
+                }
+                break
+            case STATE_TAG:
+                if (c === 62 /* > */) {
+                    if (!endTag) {
+                    this.emit('startElement', tagName, attrs)
+                    if (selfClosing)
+                        this.emit('endElement', tagName)
+                    } else
+                    this.emit('endElement', tagName)
+                    tagName = undefined
+                    attrs = undefined
+                    endTag = undefined
+                    selfClosing = undefined
+                    state = STATE_TEXT
+                    recordStart = pos + 1
+                } else if (c === 47 /* / */) {
+                    selfClosing = true
+                } else if (c > 32) {
+                    recordStart = pos
+                    state = STATE_ATTR_NAME
+                }
+                break
+            case STATE_ATTR_NAME:
+                if (c <= 32 || c === 61 /* = */) {
+                    attrName = endRecording()
+                    pos--
+                    state = STATE_ATTR_EQ
+                }
+                break
+            case STATE_ATTR_EQ:
+                if (c === 61 /* = */) {
+                    state = STATE_ATTR_QUOT
+                }
+                break
+            case STATE_ATTR_QUOT:
+                if (c === 34 /* " */ || c === 39 /* ' */) {
+                    attrQuote = c
+                    state = STATE_ATTR_VALUE
+                    recordStart = pos + 1
+                }
+                break
+            case STATE_ATTR_VALUE:
+                if (c === attrQuote) {
+                    var value = unescapeXml(endRecording())
+                    attrs[attrName] = value
+                    attrName = undefined
+                    state = STATE_TAG
+                }
+                break
+            }
         }
-    }
 
-    if (typeof recordStart === 'number' &&
-        recordStart <= data.length) {
+        if (typeof recordStart === 'number' &&
+            recordStart <= data.length) {
 
-        remainder = data.slice(recordStart)
-        recordStart = 0
-    }
+            remainder = data.slice(recordStart)
+            recordStart = 0
+        }
     }
 
     /*var origEmit = this.emit
diff --git a/lib/sax/sax_node-xml.js b/lib/sax/sax_node-xml.js
index 8a03d13..4a01440 100644
--- a/lib/sax/sax_node-xml.js
+++ b/lib/sax/sax_node-xml.js
@@ -10,40 +10,43 @@ var util = require('util')
  */
 var SaxNodeXML = module.exports = function SaxNodeXML() {
     events.EventEmitter.call(this)
-    var that = this
+    var self = this
     this.parser = new xml.SaxParser(function(handler) {
-    handler.onStartElementNS(function(elem, attrs, prefix, uri, namespaces) {
-        var i, attrsHash = {}
-        if (prefix)
-        elem = prefix + ":" + elem
-        for(i = 0; i < attrs.length; i++) {
-        var attr = attrs[i]
-        attrsHash[attr[0]] = unescapeXml(attr[1])
-        }
-        for(i = 0; i < namespaces.length; i++) {
-        var namespace = namespaces[i]
-        var k = !namespace[0] ? "xmlns" : "xmlns:" + namespace[0]
-        attrsHash[k] = unescapeXml(namespace[1])
-        }
-        that.emit('startElement', elem, attrsHash)
-    })
-    handler.onEndElementNS(function(elem, prefix, uri) {
-        if (prefix)
-        elem = prefix + ":" + elem
-        that.emit('endElement', elem)
-    })
-    handler.onCharacters(function(str) {
-        that.emit('text', str)
-    })
-    handler.onCdata(function(str) {
-        that.emit('text', str)
-    })
-    handler.onError(function(e) {
-        that.emit('error', e)
-    })
-    // TODO: other events, esp. entityDecl (billion laughs!)
+        handler.onStartElementNS(function(elem, attrs, prefix, uri, namespaces) {
+            var i, attrsHash = {}
+            if (prefix) {
+                elem = prefix + ':' + elem
+            }
+            for (i = 0; i < attrs.length; i++) {
+                var attr = attrs[i]
+                attrsHash[attr[0]] = unescapeXml(attr[1])
+            }
+            for(i = 0; i < namespaces.length; i++) {
+                var namespace = namespaces[i]
+                var k = !namespace[0] ? 'xmlns' : 'xmlns:' + namespace[0]
+                attrsHash[k] = unescapeXml(namespace[1])
+            }
+            self.emit('startElement', elem, attrsHash)
+        })
+        handler.onEndElementNS(function(elem, prefix) {
+            if (prefix) {
+                elem = prefix + ':' + elem
+            }
+            self.emit('endElement', elem)
+        })
+        handler.onCharacters(function(str) {
+            self.emit('text', str)
+        })
+        handler.onCdata(function(str) {
+            self.emit('text', str)
+        })
+        handler.onError(function(e) {
+            self.emit('error', e)
+        })
+        // TODO: other events, esp. entityDecl (billion laughs!)
     })
 }
+
 util.inherits(SaxNodeXML, events.EventEmitter)
 
 SaxNodeXML.prototype.write = function(data) {
@@ -51,8 +54,9 @@ SaxNodeXML.prototype.write = function(data) {
 }
 
 SaxNodeXML.prototype.end = function(data) {
-    if (data)
-    this.write(data)
+    if (data) {
+        this.write(data)
+    }
 }
 
 function unescapeXml(s) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git



More information about the Pkg-javascript-commits mailing list