bool JsonParser::extractValue(JsonNode &node) { if (!extractWhitespace()) return false; switch (input[pos]) { case '\"': return extractString(node); case 'n' : return extractNull(node); case 't' : return extractTrue(node); case 'f' : return extractFalse(node); case '{' : return extractStruct(node); case '[' : return extractArray(node); case '-' : return extractFloat(node); default: { if (input[pos] >= '0' && input[pos] <= '9') return extractFloat(node); return error("Value expected!"); } } }
int32_t LogisticsComponent::init(PSTR dataLine) { PSTR line = dataLine; PSTR pLine = line; char pBuffer[1025]; ID = (extractInt(pLine)); // the type extractString(pLine, pBuffer, 1024); int32_t i; for (i = 0; i < NUM_COMPONENT_FORMS; ++i) { if (0 == _stricmp(ComponentFormString[i], pBuffer)) { Type = i; break; } } if (i == NUM_COMPONENT_FORMS) return -1; // name, probably aren't going to use this, they should be in the RC. extractString(pLine, pBuffer, 1024); // name, probably aren't going to use this, they should be in the RC. extractString(pLine, pBuffer, 1024); // ignore critical hits recycleTime = extractFloat(pLine); heat = extractFloat(pLine); // weight weight = extractFloat(pLine); damage = extractFloat(pLine); // ignore battle rating extractString(pLine, pBuffer, 1024); // cost cost = extractInt(pLine); // range extractString(pLine, pBuffer, 1024); if (!isWeapon()) rangeType = NO_RANGE; else if (!strcmp(pBuffer, "int32_t")) rangeType = int32_t; else if (!strcmp(pBuffer, "medium")) rangeType = MEDIUM; else rangeType = int16_t; // we need to figure out where things can go extractString(pLine, pBuffer, 1024); bHead = _stricmp(pBuffer, "Yes") ? false : true; extractString(pLine, pBuffer, 1024); bTorso = _stricmp(pBuffer, "Yes") ? false : true; // ignore the next 4 columns for (i = 0; i < 4; ++i) extractString(pLine, pBuffer, 1024); extractString(pLine, pBuffer, 1024); bLegs = _stricmp(pBuffer, "Yes") ? false : true; // ignore the next 4 columns for (i = 0; i < 4; ++i) extractString(pLine, pBuffer, 1024); Ammo = extractInt(pLine); // now read in icon info extractString(pLine, pBuffer, 1024); if (*pBuffer && (pBuffer[0] != '0')) { iconFileName = new char[strlen(pBuffer) + 1]; strcpy(iconFileName, pBuffer); } else return -1; // fail if no picture extractString(pLine, pBuffer, 1024); if (*pBuffer) { pictureFileName = new char[strlen(pBuffer) + 1]; // Forgot the nullptr all over the place did we? strcpy(pictureFileName, pBuffer); } stringID = extractInt(pLine); helpStringID = extractInt(pLine); iconX = extractInt(pLine); iconY = extractInt(pLine); char nameBuffer[256]; cLoadString(stringID, nameBuffer, 256); name = flavorText = new char[strlen(nameBuffer) + 1]; // Lets not forget the nullptr!!! strcpy(name, nameBuffer); return ID; }
static void XaviLexerLoad(XaviLexer *lexer) { XaviDfaState dfaState = DFA_START; const char *current = lexer->location; if (lexer->token == EOL || lexer->token == ERROR) return; while (dfaState != DFA_END) switch (dfaState) { case DFA_END: break; case DFA_START: if(isOperator(*current)) { current++; dfaState = DFA_TERM_CHAR; } else if (*current == 'd') { current++; dfaState = DFA_DICE; } else if (*current == 'e') { current++; dfaState = DFA_E; } else if (*current == 'p') { current++; dfaState = DFA_PI_1; } else if (isdigit(*current)) { current++; dfaState = DFA_INTEGER; } else if (isalpha(*current)) { current++; dfaState = DFA_ID; } else if (isspace(*current)) { lexer->location++; current++; } else if (*current == '\0') { dfaState = DFA_TERM_EOI; } else { dfaState = DFA_ERROR; } break; case DFA_DICE: if (isalpha(*current)) { current++; dfaState = DFA_ID; } else { dfaState = DFA_TERM_CHAR; } break; case DFA_E: if (isalnum(*current)) { current++; dfaState = DFA_ID; } else { dfaState = DFA_TERM_E; } break; case DFA_PI_1: if (*current == 'i') { current++; dfaState = DFA_PI_2; } else if (isIdCharacter(*current)) { current++; dfaState = DFA_ID; } else { dfaState = DFA_TERM_STRING; } break; case DFA_PI_2: if (isIdCharacter(*current)) { current++; dfaState = DFA_ID; } else { dfaState = DFA_TERM_PI; } break; case DFA_ID: if (isalnum(*current)) { current++; } else { dfaState = DFA_TERM_STRING; } break; case DFA_INTEGER: if (*current == '.') { current++; dfaState = DFA_FLOAT; } else if (isdigit(*current)) { current++; } else { dfaState = DFA_TERM_INTEGER; } break; case DFA_FLOAT: if (isdigit(*current)) { current++; } else { dfaState = DFA_TERM_FLOAT; } break; case DFA_TERM_INTEGER: lexer->token = INTEGER; lexer->value.i = extractInteger(lexer->location, current); dfaState = DFA_END; break; case DFA_TERM_FLOAT: lexer->token = FLOAT; lexer->value.f = extractFloat(lexer->location, current); dfaState = DFA_END; break; case DFA_TERM_E: lexer->token = FLOAT; lexer->value.f = EULER; dfaState = DFA_END; break; case DFA_TERM_PI: lexer->token = FLOAT; lexer->value.f = PI; dfaState = DFA_END; break; case DFA_TERM_CHAR: lexer->token = *lexer->location; lexer->value.i = 0; dfaState = DFA_END; break; case DFA_TERM_STRING: lexer->token = ID; lexer->value.s = extractString(lexer->location, current); dfaState = DFA_END; break; case DFA_TERM_EOI: lexer->token = EOL; lexer->value.i = 0; dfaState = DFA_END; break; case DFA_ERROR: lexer->token = ERROR; lexer->value.i = 0; dfaState = DFA_END; break; } lexer->location = current; }