1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-09 03:19:56 +00:00
TiddlyWiki5/test/tiddlywiki.2.6.5/source/tiddlywiki/deprecated/Strings.js
Jeremy Ruston 07df513140 Revised test data
Testing against the output of cook.rb isn't satisfactory because of the
bugs in it; instead we're now going to test against the tiddlywiki.com
build products
2011-12-03 11:41:25 +00:00

30 lines
702 B
JavaScript
Executable File

//--
//-- Deprecated String functions
//--
// @Deprecated: no direct replacement, since not used in core code
String.prototype.toJSONString = function()
{
// Convert a string to it's JSON representation by encoding control characters, double quotes and backslash. See json.org
var m = {
'\b': '\\b',
'\f': '\\f',
'\n': '\\n',
'\r': '\\r',
'\t': '\\t',
'"' : '\\"',
'\\': '\\\\'
};
var replaceFn = function(a,b) {
var c = m[b];
if(c)
return c;
c = b.charCodeAt();
return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
};
if(/["\\\x00-\x1f]/.test(this))
return '"' + this.replace(/([\x00-\x1f\\"])/g,replaceFn) + '"';
return '"' + this + '"';
};