int ERFFile::readKeyList(void) { uint16 type; if(!inited.isMax(0) && init(1)) return errcode; if(seek(offkeylist)) return errcode; resrefs.resize(entrycount); restypes.resize(entrycount); resids.resize(entrycount); offsets.resize(entrycount); sizes.resize(entrycount); for(uint32 i=0;i<entrycount;i++) { if(rawRead(resrefs[i], 16)) return errcode; if(binRead(resids[i])) return errcode; if(binRead(type)) return errcode; restypes[i] = (NWNFileType) type; lowerStr(resrefs[i]); if(seek(2, std::ios::cur)) return errcode; } if(seek(offreslist)) return errcode; for(uint32 i=0;i<entrycount;i++) if(binRead(2, &offsets[i], &sizes[i])) return errcode; inited.set(2); return errcode = 0; }
int TLKFile::add(uint16 flag, std::string sndresref, float32 sndlen, std::string str) { lowerStr(sndresref); flags.push_back(flag); sndresrefs.push_back(sndresref); sndlengths.push_back(sndlen); strings.push_back(str); return errcode = 0; }
uint32 ERFFile::getEntryNum(std::string resref, NWNFileType restype) { if(!inited.isMax(2) && init(3)) return ERROR; lowerStr(resref); for(uint32 i=0;i<entrycount;i++) if((resrefs[i] == resref) && (restypes[i] == restype)) return i; aderrstr = resref; return NOTFOUND; }
int TLKFile::set(uint32 n, uint16 flag, std::string sndresref, float32 sndlen, std::string str) { if(n >= strcount) return errcode = 13; lowerStr(sndresref); flags[n] = flag; sndresrefs[n] = sndresref; sndlengths[n] = sndlen; strings[n] = str; return errcode = 0; }
int ERFFile::finalWriteKeyList(void) { int l; if(seek(offkeylist)) return errcode; for(uint32 i=0;i<entrycount;i++) { // ResRefs have to have at most 16 characters if(resrefs[i].length() > 16) resrefs[i].erase(16); lowerStr(resrefs[i]); if(rawWrite((char*) resrefs[i].c_str(), l=resrefs[i].length())) return errcode; // Pad to a total of 16 bytes for(l=l;l<16;l++) if(binWrite((uint8) 0)) return errcode; if(binWrite(i)) return errcode; if(binWrite((uint16) restypes[i])) return errcode; if(binWrite((uint16) 0)) return errcode; // Overflow check, if that fires, something really bad happened if(tell() > offreslist) return errcode = 23; } return errcode = 0; }
int TLKFile::readTable(void) { uint32 flag, tmp; if(!inited.isMax(0) && init(1)) return errcode; if(seek(20)) return errcode; flags.resize(strcount); sndresrefs.resize(strcount); sndlengths.resize(strcount); offsets.resize(strcount); strlengths.resize(strcount); for(uint32 i=0;i<strcount;i++) { if(binRead(flag)) return errcode; if(rawRead(sndresrefs[i], 16)) return errcode; if(binRead(4, &tmp, &tmp, &offsets[i], &strlengths[i])) return errcode; if(binRead(sndlengths[i])) return errcode; lowerStr(sndresrefs[i]); flags[i] = (uint16) flag; } inited.set(1); return errcode = 0; }
std::string LDAPExpr::ToLower(const std::string& str) { std::string lowerStr(str); std::transform(str.begin(), str.end(), lowerStr.begin(), ::tolower); return lowerStr; }
String StringUtils::toLower(const String& str) { String lowerStr(str); toLower(lowerStr); return lowerStr; }