/// Search for a character. /// Search for the position of the needle in the haystack. /// Default mode is StrCase | StrLeft, mode also accepts StrNoCase and StrRight. /// If pos is non-zero, then in mode StrLeft the search starts at (hay + pos) and /// in mode StrRight the search starts at (hay + pos - 1) /// @return Returns a pointer to the location of the character in the haystack or 0 static const char* StrFind(const char* hay, char needle, S32 pos, U32 mode) { if (mode & String::Right) { // Go to the end first, then search backwards const char *he = hay; if (pos) { he += pos - 1; } else { while (*he) he++; } if (mode & String::NoCase) { needle = dTolower(needle); for (; he >= hay; he--) { if (dTolower(*he) == needle) return he; } } else { for (; he >= hay; he--) { if (*he == needle) return he; } } return 0; } else { if (mode & String::NoCase) { needle = dTolower(needle); for (hay += pos; *hay && dTolower(*hay) != needle;) hay++; } else { for (hay += pos; *hay && *hay != needle;) hay++; } return *hay ? hay : 0; } }
bool BanList::isTAEq(const char *bannedTA, const char *TA) { char a, b; for(;;) { a = *bannedTA++; b = *TA++; if(a == '*' || (!a && b == ':')) // ignore port return true; if(dTolower(a) != dTolower(b)) return false; if(!a) return true; } }
void XMLExport::exportNamespaces() { // keep track of which enumTables are in use Vector < const EnumTable*> enumTables; mXML->pushNewElement("Namespaces"); for (Namespace *walk = Namespace::mNamespaceList; walk; walk = walk->mNext) { if ( walk->mName && !walk->isClass() ) continue; const char *name = walk->mName ? walk->mName : ""; mXML->pushNewElement("Namespace"); mXML->setAttribute("name", name); Namespace *p = walk->mParent; mXML->pushNewElement("Parents"); while (p) { if (p->mName == walk->mName) { p = p->mParent; continue; } const char* pname = p->mName ? p->mName : ""; mXML->pushNewElement("Parent"); mXML->setAttribute("name", pname); mXML->popElement(); // Parent p = p->mParent; } mXML->popElement(); // Parents // Entries (Engine/Script Methods/Functions) mXML->pushNewElement("Entries"); Namespace::Entry *entry; VectorPtr<Namespace::Entry *> vec; walk->getEntryList(&vec); for( NamespaceEntryListIterator compItr = vec.begin(); compItr != vec.end(); compItr++ ) { entry = *compItr; if (entry->mNamespace != walk) continue; if (entry->mNamespace->mName != walk->mName) continue; mXML->pushNewElement("Entry"); //consistently name functions char functionName[512]; dSprintf(functionName, 512, entry->mFunctionName); functionName[0] = dTolower(functionName[0]); S32 minArgs = entry->mMinArgs; S32 maxArgs = entry->mMaxArgs; if (maxArgs < minArgs) maxArgs = minArgs; mXML->setAttribute("name", functionName); mXML->setAttribute("minArgs", avar("%i", minArgs)); mXML->setAttribute("maxArgs", avar("%i", maxArgs)); const char* usage = ""; if (entry->mUsage && entry->mUsage[0]) usage = entry->mUsage; mXML->setAttribute("usage", usage); mXML->setAttribute("package", entry->mPackage ? entry->mPackage : ""); mXML->setAttribute("entryType", avar("%i", entry->mType)); mXML->popElement(); // Entry } mXML->popElement(); // Entries // Fields mXML->pushNewElement("Fields"); AbstractClassRep *rep = walk->mClassRep; Vector<U32> classFields; if (rep) { AbstractClassRep *parentRep = rep->getParentClass(); const AbstractClassRep::FieldList& flist = rep->mFieldList; for(U32 i = 0; i < flist.size(); i++) { if (parentRep) { if (parentRep->findField(flist[i].pFieldname)) continue; } classFields.push_back(i); } for(U32 i = 0; i < classFields.size(); i++) { U32 index = classFields[i]; char fieldName[256]; dSprintf(fieldName, 256, flist[index].pFieldname); //consistently name fields fieldName[0] = dToupper(fieldName[0]); mXML->pushNewElement("Field"); mXML->setAttribute("name", fieldName); mXML->setAttribute("type", avar("%i", flist[index].type)); // RD: temporarily deactivated; TypeEnum is no more; need to sync this up // if (flist[index].type == TypeEnum && flist[index].table && dStrlen(flist[index].table->name)) // { // if (!enumTables.contains(flist[index].table)) // enumTables.push_back(flist[index].table); // // mXML->setAttribute("enumTable", flist[index].table->name); // // } const char* pFieldDocs = ""; if (flist[index].pFieldDocs && flist[index].pFieldDocs[0]) pFieldDocs = flist[index].pFieldDocs; mXML->setAttribute("docs", pFieldDocs); mXML->setAttribute("elementCount", avar("%i", flist[index].elementCount)); mXML->popElement(); // Field } } mXML->popElement(); // Fields mXML->popElement(); // Namespace } mXML->popElement(); // Namespaces mXML->pushNewElement("EnumTables"); // write out the used EnumTables for (S32 i = 0; i < enumTables.size(); i++) { mXML->pushNewElement("EnumTable"); const EnumTable* table = enumTables[i]; mXML->setAttribute("name", table->name); mXML->setAttribute("firstFlag", avar("%i", table->firstFlag)); mXML->setAttribute("mask", avar("%i", table->mask)); mXML->pushNewElement("Enums"); for (S32 j = 0; j < table->size; j++) { mXML->pushNewElement("Enum"); mXML->setAttribute("name", table->table[j].label); mXML->setAttribute("index", avar("%i", table->table[j].index)); mXML->popElement(); // Enum } mXML->popElement(); //Enums mXML->popElement(); // EnumTable } mXML->popElement(); // EnumTables }
/// Search for a StringData. /// Search for the position of the needle in the haystack. /// Default mode is StrCase | StrLeft, mode also accepts StrNoCase and StrRight. /// If pos is non-zero, then in mode StrLeft the search starts at (hay + pos) and /// in mode StrRight the search starts at (hay + pos - 1) /// @return Returns a pointer to the StringData in the haystack or 0 static const char* StrFind(const char* hay, const char* needle, S32 pos, U32 mode) { if (mode & String::Right) { const char *he = hay; if (pos) { he += pos - 1; } else { while (*he) he++; } if (mode & String::NoCase) { AutoPtr<char,DeleteString> ln(dStrlwr(dStrdup(needle))); for (; he >= hay; he--) { if (dTolower(*he) == *ln) { U32 i = 0; while (ln[i] && ln[i] == dTolower(he[i])) i++; if (!ln[i]) return he; if (!hay[i]) return 0; } } } else { for (; he >= hay; he--) { if (*he == *needle) { U32 i = 0; while (needle[i] && needle[i] == he[i]) i++; if (!needle[i]) return he; if (!hay[i]) return 0; } } } return 0; } else { if (mode & String::NoCase) { AutoPtr<char,DeleteString> ln(dStrlwr(dStrdup(needle))); for (hay += pos; *hay; hay++) { if (dTolower(*hay) == *ln) { U32 i = 0; while (ln[i] && ln[i] == dTolower(hay[i])) i++; if (!ln[i]) return hay; if (!hay[i]) return 0; } } } else { for (hay += pos; *hay; hay++) { if (*hay == *needle) { U32 i = 0; while (needle[i] && needle[i] == hay[i]) i++; if (!needle[i]) return hay; if (!hay[i]) return 0; } } } } return 0; }