CString ResolveEntity (ParserCtx *pCtx, const CString &sName, bool *retbFound) // ResolveEntity // // Resolves the entity from the parser table { *retbFound = true; CString sResult; // Check to see if the name is one of the standard entities CString sNameLC = strToLower(sName); if (strEquals(sNameLC, ENTITY_AMP)) return ENTITY_AMP_SUB; else if (strEquals(sNameLC, ENTITY_LT)) return ENTITY_LT_SUB; else if (strEquals(sNameLC, ENTITY_GT)) return ENTITY_GT_SUB; else if (strEquals(sNameLC, ENTITY_QUOT)) return ENTITY_QUOT_SUB; else if (strEquals(sNameLC, ENTITY_APOS)) return ENTITY_APOS_SUB; // If the entity is a hex number, then this is a character char *pPos = sName.GetParsePointer(); if (*pPos == '#') { pPos++; if (*pPos == 'x' || *pPos == 'X') { *pPos++; char chChar = (char)strParseIntOfBase(pPos, 16, 0x20, NULL, NULL); return CString(&chChar, 1); } else { char chChar = (char)strParseInt(pPos, 0x20); return CString(&chChar, 1); } } // Otherwise, it is a general attribute bool bFound; CString sValue = pCtx->LookupEntity(sName, &bFound); if (bFound) { // Parse the value to resolve embedded entities ParserCtx SubCtx(pCtx, sValue); ParseToken(&SubCtx, ParseEntityState); if (SubCtx.iToken == tkText) sResult = SubCtx.sToken; else { bFound = false; sResult = sName; } } if (retbFound) *retbFound = bFound; return sResult; }
ALERROR CMultiverseCatalogEntry::CreateFromJSON (const CJSONValue &Entry, CMultiverseCatalogEntry **retpEntry, CString *retsResult) // CreateFromJSON // // Creates a new entry from a JSON value. { int i; CMultiverseCatalogEntry *pNewEntry = new CMultiverseCatalogEntry; pNewEntry->m_sUNID = Entry.GetElement(FIELD_UNID).AsString(); if (pNewEntry->m_sUNID.IsBlank()) { delete pNewEntry; *retsResult = ERR_INVALID_UNID; return ERR_FAIL; } pNewEntry->m_dwRelease = (DWORD)Entry.GetElement(FIELD_RELEASE).AsInt32(); pNewEntry->m_dwVersion = (DWORD)Entry.GetElement(FIELD_VERSION).AsInt32(); pNewEntry->m_sName = Entry.GetElement(FIELD_NAME).AsString(); pNewEntry->m_sDesc = Entry.GetElement(FIELD_DESCRIPTION).AsString(); // Parse the fully qualified UNID and get just the hex UNID. if (strStartsWith(pNewEntry->m_sUNID, STR_UNID_PREFIX)) { pNewEntry->m_dwUNID = strParseIntOfBase(pNewEntry->m_sUNID.GetASCIIZPointer() + STR_UNID_PREFIX.GetLength(), 16, 0); if (pNewEntry->m_dwUNID == 0) { delete pNewEntry; *retsResult = ERR_INVALID_UNID; return ERR_FAIL; } } else { delete pNewEntry; *retsResult = ERR_INVALID_UNID; return ERR_FAIL; } // Get the type CString sType = Entry.GetElement(FIELD_TYPE).AsString(); if (strEquals(sType, TYPE_ADVENTURE)) pNewEntry->m_iType = extAdventure; else if (strEquals(sType, TYPE_LIBRARY)) pNewEntry->m_iType = extLibrary; else pNewEntry->m_iType = extExtension; // Get the license type CString sLicense = Entry.GetElement(FIELD_LICENSE_TYPE).AsString(); if (strEquals(sLicense, LICENSE_AUTO)) pNewEntry->m_iLicenseType = licenseAuto; else if (strEquals(sLicense, LICENSE_CORE)) pNewEntry->m_iLicenseType = licenseCore; else if (strEquals(sLicense, LICENSE_FREE)) pNewEntry->m_iLicenseType = licenseFree; else if (strEquals(sLicense, LICENSE_PAID)) pNewEntry->m_iLicenseType = licensePaid; else pNewEntry->m_iLicenseType = licenseUnknown; // Get the TDB file (only if not core) if (pNewEntry->m_iLicenseType != licenseCore) { if (pNewEntry->m_TDBFile.InitFromJSON(Entry.GetElement(FIELD_FILE_TDB), retsResult) != NOERROR) { delete pNewEntry; return ERR_FAIL; } } // Get the resources const CJSONValue &Resources = Entry.GetElement(FIELD_RESOURCES); if (Resources.GetType() == CJSONValue::typeArray) { pNewEntry->m_Resources.InsertEmpty(Resources.GetCount()); for (i = 0; i < Resources.GetCount(); i++) { if (pNewEntry->m_Resources[i].InitFromJSON(Resources.GetElement(i), retsResult) != NOERROR) { delete pNewEntry; return ERR_FAIL; } } } // Initialize status pNewEntry->m_iStatus = statusUnknown; pNewEntry->m_pIcon = NULL; // Done *retpEntry = pNewEntry; return NOERROR; }