Warning: session_start(): open(/var/lib/php/sessions/sess_omsa0urmbvif5og60u1d4min1l, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
// supports 8 different character classes
sclass JSONSpecialIntegral {
int minLevel = 1, maxLevel = 8;
byte[] input;
int[] bracketLevel; // diff +1 for opening bracket, diff -1 for closing bracket
int[] bracketCount; // diff +1 for any bracket
byte[] quotesBitSet; // is character within string? (byte[] = faster replacement for BitSet)
*() {}
*(byte[] *input) {}
void analyze(S input) {
this.input = toUtf8(input); // XXX probably wrong
analyze();
}
void analyze(byte[] input) {
this.input = input;
analyze();
}
void analyze {
byte[] input = this.input;
int n = input.length;
bracketLevel = new int[n];
bracketCount = new int[n];
quotesBitSet = byteArrayBitSet_new(n);
int bracketLvl = 0, bracketCnt = 0;
bool inQuotes;
for i to n: {
byte b = input[i];
if (isOpener(b)) {
if (!inQuotes) { ++bracketLvl; ++bracketCount; }
} else if (isCloser(b)) {
if (!inQuotes) { --bracketLvl; ++bracketCount; }
} else if (b == '\'') {
// TODO if (inQuotes) ...
} else if (b == '"') {
inQuotes = !inQuotes;
}
bracketLevel[i] = bracketLvl;
bracketCount[i] = bracketCnt;
setBit(quotesBitSet, i, inQuotes);
}
}
int bracketLevel(int idx) {
if (idx < 0) ret 0;
ret bracketLevel[min(bracketLevel.length-1, idx)];
}
int bracketCount(int idx) {
if (idx < 0) ret 0;
ret bracketCount[min(bracketLevel.length-1, idx)];
}
bool inQuoteBit(int idx) {
ret getBit(quotesBitSet, idx);
}
bool isOpener(byte b) {
ret b == '{' || b == '[';
}
bool isCloser(byte b) {
ret b == '}' || b == ']';
}
S stats() {
ret renderVars(
inputLength := l(input),
sizeFactor := formatDouble((elementSize(bracketLevel)+elementSize(bracketCount)+1/8.0), 2);
}
int n() { ret input.length; }
}