MCPcopy Create free account
hub / github.com/apache/pouchdb / parseIndexableString

Function parseIndexableString

lib/index.js:3406–3472  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

3404}
3405
3406function parseIndexableString(str) {
3407 var stack = [];
3408 var metaStack = []; // stack for arrays and objects
3409 var i = 0;
3410
3411 /*eslint no-constant-condition: ["error", { "checkLoops": false }]*/
3412 while (true) {
3413 var collationIndex = str[i++];
3414 if (collationIndex === '\u0000') {
3415 if (stack.length === 1) {
3416 return stack.pop();
3417 } else {
3418 pop(stack, metaStack);
3419 continue;
3420 }
3421 }
3422 switch (collationIndex) {
3423 case '1':
3424 stack.push(null);
3425 break;
3426 case '2':
3427 stack.push(str[i] === '1');
3428 i++;
3429 break;
3430 case '3':
3431 var parsedNum = parseNumber(str, i);
3432 stack.push(parsedNum.num);
3433 i += parsedNum.length;
3434 break;
3435 case '4':
3436 var parsedStr = '';
3437 /*eslint no-constant-condition: ["error", { "checkLoops": false }]*/
3438 while (true) {
3439 var ch = str[i];
3440 if (ch === '\u0000') {
3441 break;
3442 }
3443 parsedStr += ch;
3444 i++;
3445 }
3446 // perform the reverse of the order-preserving replacement
3447 // algorithm (see above)
3448 /* eslint-disable no-control-regex */
3449 parsedStr = parsedStr.replace(/\u0001\u0001/g, '\u0000')
3450 .replace(/\u0001\u0002/g, '\u0001')
3451 .replace(/\u0002\u0002/g, '\u0002');
3452 /* eslint-enable no-control-regex */
3453 stack.push(parsedStr);
3454 break;
3455 case '5':
3456 var arrayElement = { element: [], index: stack.length };
3457 stack.push(arrayElement.element);
3458 metaStack.push(arrayElement);
3459 break;
3460 case '6':
3461 var objElement = { element: {}, index: stack.length };
3462 stack.push(objElement.element);
3463 metaStack.push(objElement);

Callers 1

fetchFromViewFunction · 0.70

Calls 2

popFunction · 0.70
parseNumberFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…