static void __stdcall DoExtractString(char* scriptData, UInt32 dataLen, char* dest, ScriptEventList* eventList) { // copy the string memcpy(dest, scriptData, dataLen); dest[dataLen] = 0; if (dataLen && dest[0] == '$' && eventList && eventList->m_script) // variable name { Script::VariableInfo* varInfo = NULL; varInfo = eventList->m_script->GetVariableByName(dest + 1); if (varInfo) { ScriptEventList::Var* var; var = eventList->GetVariable(varInfo->idx); if (var) { StringVar* strVar; strVar = g_StringMap.Get(var->data); if (strVar) if (strVar->GetLength() < 0x100) // replace string with contents of string var strcpy_s(dest, strVar->GetLength() + 1, strVar->GetCString()); } } } // "%e" becomes an empty string else if (dataLen == 2 && dest[0] == '%' && toupper(dest[1]) == 'E') dest[0] = 0; }
AssignableStringVarToken::AssignableStringVarToken(UInt32 _id, UInt32 lbound, UInt32 ubound) : AssignableStringToken(_id, lbound, ubound) { StringVar* strVar = g_StringMap.Get(value.arrID); if (strVar) { upper = (upper > strVar->GetLength()) ? strVar->GetLength() - 1 : upper; substring = strVar->SubString(lower, upper - lower + 1); } }
bool Cmd_sv_Length_Execute(COMMAND_ARGS) { *result = -1; // sentinel value if extraction fails UInt32 strID = 0; if (ExtractArgs(EXTRACT_ARGS, &strID)) { StringVar* str = g_StringMap.Get(strID); if (str) *result = str->GetLength(); } return true; }
bool StringVar_Find_Execute(COMMAND_ARGS, UInt32 mode, CommandInfo* commandInfo) { *result = -1; UInt32 strID = 0; UInt32 startPos = 0; UInt32 numChars = -1; UInt32 bCaseSensitive = 0; UInt32 numToReplace = -1; //replace all by default char toFind[kMaxMessageLength] = { 0 }; UInt32 intResult = -1; if (!ExtractFormatStringArgs(0, toFind, PASS_FMTSTR_ARGS, commandInfo->numParams, &strID, &startPos, &numChars, &bCaseSensitive, &numToReplace)) return true; StringVar* strVar = g_StringMap.Get(strID); if (strVar) { if (numChars == -1) numChars = strVar->GetLength() - startPos; switch (mode) { case eMode_svFind: intResult = strVar->Find(toFind, startPos, numChars, bCaseSensitive ? true : false); break; case eMode_svCount: intResult = strVar->Count(toFind, startPos, numChars, bCaseSensitive ? true : false); break; case eMode_svReplace: { std::string str(toFind); UInt32 splitPoint = str.find(GetSeparatorChar(scriptObj)); if (splitPoint != -1 && splitPoint < str.length()) { toFind[splitPoint] = '\0'; char* replaceWith = (splitPoint == str.length() - 1) ? "" : toFind + splitPoint + 1; intResult = strVar->Replace(toFind, replaceWith, startPos, numChars, bCaseSensitive ? true : false, numToReplace); } break; } } } if (intResult != -1) *result = intResult; return true; }
static UInt32 __stdcall DoExtractString(char* scriptData, UInt32 dataLen, char* dest, ScriptEventList* eventList) { // copy the string memcpy(dest, scriptData, dataLen); UInt32 newDataLen = dataLen; if (newDataLen && dest[0] == '$' && eventList && eventList->m_script) // variable name { VariableInfo* varInfo = NULL; if ((newDataLen < 0x100) && (dest[newDataLen])) dest[newDataLen] = 0; varInfo = eventList->m_script->GetVariableByName(dest + 1); if (varInfo) { ScriptEventList::Var* var; var = eventList->GetVariable(varInfo->idx); if (var) { StringVar* strVar; strVar = g_StringMap.Get(var->data); if (strVar) if (strVar->GetLength() < 0x100) { // replace string with contents of string var strcpy_s(dest, strVar->GetLength() + 1, strVar->GetCString()); newDataLen = strVar->GetLength(); } } } } // "%e" becomes an empty string else if (newDataLen == 2 && dest[0] == '%' && toupper(dest[1]) == 'E') { newDataLen = 0; } // force zero terminated string if ((newDataLen < 0x100) && (dest[newDataLen])) dest[newDataLen] = 0; return dataLen; }
bool AssignableStringVarToken::Assign(const char* str) { StringVar* strVar = g_StringMap.Get(value.arrID); if (strVar) { UInt32 len = strVar->GetLength(); if (lower <= upper && upper < len) { strVar->Erase(lower, upper-lower + 1); if (str) { strVar->Insert(str, lower); substring = strVar->String(); } return true; } } return false; }
bool Cmd_sv_Erase_Execute(COMMAND_ARGS) { *result = 0; UInt32 strID = 0; UInt32 startPos = 0; UInt32 howMany = -1; if (!ExtractArgs(EXTRACT_ARGS, &strID, &startPos, &howMany)) return true; StringVar* strVar = g_StringMap.Get(strID); if (strVar) { if (howMany == -1) howMany = strVar->GetLength() - startPos; strVar->Erase(startPos, howMany); } return true; }
bool Cmd_sv_SubString_Execute(COMMAND_ARGS) { UInt32 rhStrID = 0; UInt32 startPos = 0; UInt32 howMany = -1; std::string subStr; if (ExtractArgs(EXTRACT_ARGS, &rhStrID, &startPos, &howMany)) { StringVar* rhVar = g_StringMap.Get(rhStrID); if (!rhVar) return true; if (howMany == -1) howMany = rhVar->GetLength() - startPos; subStr = rhVar->SubString(startPos, howMany); } AssignToStringVar(PASS_COMMAND_ARGS, subStr.c_str()); return true; }