Skip to content

Commit

Permalink
Drop bloq
Browse files Browse the repository at this point in the history
  • Loading branch information
morgan3d committed Oct 2, 2023
1 parent 7889c4d commit 2ad2a97
Show file tree
Hide file tree
Showing 103 changed files with 877 additions and 702 deletions.
4 changes: 2 additions & 2 deletions README.md

Large diffs are not rendered by default.

34 changes: 23 additions & 11 deletions console/WorkJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,28 @@ if (! String.prototype.replaceAll) {
}

const WorkJSON = (function () {
const doubleQuoteProtection = String.fromCharCode(0xE000);
const protectionBlockStart = 0xE010;

const NaNSymbol = '\uE001', InfinitySymbol = '\uE002', NegInfinitySymbol = '\uE003', UndefinedSymbol = '\uE004';


// Use the Multilinguial plane Unicode private use area,
// which has room for over 6000 strings that should not be
// in use by the source text.
//
// https://en.wikipedia.org/wiki/Private_Use_Areas
//
// Must also match hardcoded values below in regexps
const doubleQuoteProtection = '\uE000';
const NaNSymbol = '\uE001';
const InfinitySymbol = '\uE002';
const NegInfinitySymbol = '\uE003';
const UndefinedSymbol = '\uE004';
const ESCAPED_ESCAPE = '\uE009';
const protectionBlockStart = 0xE010;

return {
/** Returns the new string and a remapping array. If an array is
provided, then it is extended. */
protectQuotedStrings: function protectQuotedStrings(src, protectionMap) {
protectionMap = protectionMap || [];

const ESCAPED_ESCAPE = String.fromCharCode(0xE009);
// Hide escaped escapes momentarily
src = src.replace(/\\\\/g, ESCAPED_ESCAPE);

Expand All @@ -89,11 +98,14 @@ return {

// Restore escaped escapes
src = src.replace(/\uE009/g, '\\\\');

// Protect strings

// TODO: i = 97 string is being replaced with "if"

// Protect all strings
src = src.replace(/"((?:[^"\\]|\\.)*)"/g, function (match, str) {
const i = protectionMap.length;
protectionMap.push(str);
return '"' + String.fromCharCode(protectionMap.length - 1 + protectionBlockStart) + '"';
return '"' + String.fromCharCode(i + protectionBlockStart) + '"';
});

return [src, protectionMap];
Expand All @@ -102,15 +114,15 @@ return {
unprotectQuotedStrings : function unprotectQuotedStrings(s, protectionMap) {
// Unprotect strings
for (let i = 0; i < protectionMap.length; ++i) {
s = s.replace(String.fromCharCode(protectionBlockStart + i), protectionMap[i]);
s = s.replace(String.fromCharCode(i + protectionBlockStart), protectionMap[i]);
}

// Unprotect escaped quotes
return s.replaceAll(doubleQuoteProtection, '\\"');
},

stringify: function stringify(value, replacer, space) {
// Allow IEEE numeric constants by temporarily hiding them
// Allow IEEE numeric constants by temporarily hiding them in strings
function betterReplacer(key, value) {
if (replacer) { value = replacer(key, value); }

Expand Down
Loading

0 comments on commit 2ad2a97

Please sign in to comment.