Permalink
Browse files

Bug fix with parsed floats

  • Loading branch information...
1 parent 6f4458d commit d1a34d30c95868bfec21bfc61bc335e20c2a021a @robrighter committed Aug 13, 2010
Showing with 14 additions and 4 deletions.
  1. +8 −3 currentcost.js
  2. +6 −1 lib/xml2json.js
View
@@ -9,9 +9,14 @@
var that = this;
var dataprocess = spawn("python", ["./python/tailserial.py", device]);
dataprocess.stdout.on('data', function (data) {
- var tosend = formatData(xml.parse(new String(data), "", false));
- if(tosend)
- that.emit(( tosend.hasOwnProperty('hist')? 'history' : 'incremental' ), tosend);
+ try{
+ var tosend = formatData(xml.parse(new String(data), "", false));
+ if(tosend)
+ that.emit(( tosend.hasOwnProperty('hist')? 'history' : 'incremental' ), tosend);
+ }
+ catch(err){
+ that.emit('error', data+"");
+ }
});
dataprocess.stderr.on('data', function (data) {
that.emit('error', data+"");
View
@@ -75,7 +75,7 @@ Software Foundation. It is distributed without any warranty.
if (already && !eval(objname+".sort")){preeval+=objname+"=["+objname+"];\n"};
var before="=";after="";
if (already){before=".push(";after=")"};
- var toeval=preeval+objname+before+(((rest+"").indexOf('.')!=-1 ) ? '"'+rest+'"' : rest)+after;
+ var toeval=preeval+objname+before+(isDecimal(rest+"") ? 'parseFloat("'+rest+'")' : rest)+after;
eval(toeval);
if(eval(objname+".sort")){objname+="["+eval(objname+".length-1")+"]"};
oldniva=niva
@@ -154,6 +154,11 @@ Software Foundation. It is distributed without any warranty.
}
};
+ var isDecimal_re = /^\s*(\+|-)?((\d+(\.\d+)?)|(\.\d+))\s*$/;
+ function isDecimal (s) {
+ return String(s).search (isDecimal_re) != -1
+ }
+
exports.parse = function(xmlcode, ignoretags, debug) {
return xml2json.parser(xmlcode, ignoretags, debug);
}

0 comments on commit d1a34d3

Please sign in to comment.