Skip to content

Commit

Permalink
Quote string literals
Browse files Browse the repository at this point in the history
  • Loading branch information
tikonen committed Dec 2, 2011
1 parent 6b01e8a commit 89dfbc9
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions lib/sprintf.js
Expand Up @@ -87,22 +87,29 @@ var sprintf = (function() {
// l = []
// l[4] = 1
// Would be printed as "[1]" instead of "[, , , , 1]"
//
//
str_format.object_stringify = function(obj) {
var str = '';
if (obj != null && typeof(obj) == 'object') {
if (obj.length != null) { //array
str += '[';
var arr = []
for (var i in obj) arr.push(str_format.object_stringify(obj[i]))
str += arr.join(', ') + ']';
} else { // object
str += '{';
var arr = []
for (var k in obj) { if(obj.hasOwnProperty(k)) arr.push(k +': ' +str_format.object_stringify(obj[k])) }
str += arr.join(', ') + '}';
if (obj != null) {
switch( typeof(obj) ) {
case 'object':
if (obj.length != null) { //array
str += '[ ';
var arr = []
for (var i in obj) arr.push(str_format.object_stringify(obj[i]))
str += arr.join(', ') + ' ]';
} else { // object
str += '{ ';
var arr = []
for (var k in obj) { if(obj.hasOwnProperty(k)) arr.push(k +': ' +str_format.object_stringify(obj[k])) }
str += arr.join(', ') + ' }';
}
return str;
break;
case 'string':
return '"' + obj + '"';
break
}
return str;
}
return '' + obj;
}
Expand Down

0 comments on commit 89dfbc9

Please sign in to comment.