OLD | NEW |
(Empty) | |
| 1 if ( typeof TextEncoder !== "undefined" && typeof TextDecoder !== "undefined" ) |
| 2 { |
| 3 utf8encoder = new TextEncoder('utf-8'); |
| 4 utf8decoder = new TextDecoder('utf-8'); |
| 5 } |
| 6 else |
| 7 { |
| 8 utf8encoder = { encode: function( text ) |
| 9 { |
| 10 var result = new Uint8Array(text.length); |
| 11 for(var i = 0; i < text.length; i++) { result[i] = text.charCodeAt(i); } |
| 12 return result; |
| 13 } }; |
| 14 |
| 15 utf8decoder = { decode: function( buffer ) |
| 16 { |
| 17 return String.fromCharCode.apply(null, new Uint8Array(buffer)); |
| 18 } }; |
| 19 } |
| 20 |
| 21 toUtf8 = function( o ) { return utf8encoder.encode( JSON.stringify( o ) ); } |
| 22 fromUtf8 = function( t ) { return JSON.parse( utf8decoder.decode( t ) ); } |
OLD | NEW |