本文整理汇总了C++中StdStrBuf::EscapeString方法的典型用法代码示例。如果您正苦于以下问题:C++ StdStrBuf::EscapeString方法的具体用法?C++ StdStrBuf::EscapeString怎么用?C++ StdStrBuf::EscapeString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StdStrBuf
的用法示例。
在下文中一共展示了StdStrBuf::EscapeString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FormatString
C4GUI::Edit::InputResult C4ChatInputDialog::OnChatInput(C4GUI::Edit *edt,
bool fPasting,
bool fPastingMore) {
// no double processing
if (fProcessed) return C4GUI::Edit::IR_CloseDlg;
// get edit text
C4GUI::Edit *pEdt = reinterpret_cast<C4GUI::Edit *>(edt);
char *szInputText = const_cast<char *>(pEdt->GetText());
// Store to back buffer
Game.MessageInput.StoreBackBuffer(szInputText);
// script queried input?
if (fObjInput) {
fProcessed = true;
// check if the target input is still valid
C4Player *pPlr = Game.Players.Get(iPlr);
if (!pPlr) return C4GUI::Edit::IR_CloseDlg;
if (!pPlr->MarkMessageBoardQueryAnswered(pTarget)) {
// there was no associated query!
return C4GUI::Edit::IR_CloseDlg;
}
// then do a script callback, incorporating the input into the answer
if (fUppercase) SCapitalize(szInputText);
StdStrBuf sInput;
sInput.Copy(szInputText);
sInput.EscapeString();
Game.Control.DoInput(
CID_Script,
new C4ControlScript(
FormatString("OnMessageBoardAnswer(Object(%d), %d, \"%s\")",
pTarget ? pTarget->Number : 0, iPlr,
sInput.getData()).getData()),
CDT_Decide);
return C4GUI::Edit::IR_CloseDlg;
} else
// reroute to message input class
Game.MessageInput.ProcessInput(szInputText);
// safety: message board commands may do strange things
if (!C4GUI::IsGUIValid() || this != pInstance) return C4GUI::Edit::IR_Abort;
// select all text to be removed with next keypress
// just for pasting mode; usually the dlg will be closed now anyway
pEdt->SelectAll();
// avoid dlg close, if more content is to be pasted
if (fPastingMore) return C4GUI::Edit::IR_None;
fProcessed = true;
return C4GUI::Edit::IR_CloseDlg;
}
示例2: if
//.........这里部分代码省略.........
else if (szCmdName[0] == 'd' && !Game.Parameters.isLeague()) // deactivate
pCtrl = new C4ControlClientUpdate(pClient->getID(), CUT_Activate, false);
else if (szCmdName[0] == 'o' && !Game.Parameters.isLeague()) // observer
pCtrl = new C4ControlClientUpdate(pClient->getID(), CUT_SetObserver);
// perform it
if (pCtrl)
Game.Control.DoInput(CID_ClientUpdate, pCtrl, CDT_Sync);
else
Log(LoadResStr("IDS_LOG_COMMANDNOTALLOWEDINLEAGUE"));
return TRUE;
}
// control mode
if (SEqual(szCmdName, "centralctrl") || SEqual(szCmdName, "decentralctrl") ||
SEqual(szCmdName, "asyncctrl")) {
if (!Game.Network.isEnabled() || !Game.Network.isHost()) {
Log(LoadResStr("IDS_MSG_CMD_HOSTONLY"));
return FALSE;
}
if (Game.Parameters.isLeague() && *szCmdName == 'a') {
Log(LoadResStr("IDS_LOG_COMMANDNOTALLOWEDINLEAGUE"));
return FALSE;
}
Game.Network.SetCtrlMode(
*szCmdName == 'c' ? CNM_Central : *szCmdName == 'd' ? CNM_Decentral
: CNM_Async);
return TRUE;
}
// show chart
if (Game.IsRunning)
if (SEqual(szCmdName, "chart")) return Game.ToggleChart();
// custom command
C4MessageBoardCommand *pCmd;
if (Game.IsRunning)
if (pCmd = GetCommand(szCmdName)) {
StdStrBuf Script, CmdScript;
// replace %player% by calling player number
if (SSearch(pCmd->Script, "%player%")) {
int32_t iLocalPlr = NO_OWNER;
C4Player *pLocalPlr = Game.Players.GetLocalByIndex(0);
if (pLocalPlr) iLocalPlr = pLocalPlr->Number;
StdStrBuf sLocalPlr;
sLocalPlr.Format("%d", iLocalPlr);
CmdScript.Copy(pCmd->Script);
CmdScript.Replace("%player%", sLocalPlr.getData());
} else {
CmdScript.Ref(pCmd->Script);
}
// insert parameters
if (SSearch(CmdScript.getData(), "%d")) {
// make sure it's a number by converting
Script.Format(CmdScript.getData(), (int)atoi(pCmdPar));
} else if (SSearch(CmdScript.getData(), "%s")) {
// Unrestricted parameters?
// That's kind of a security risk as it will allow anyone to execute
// code
switch (pCmd->eRestriction) {
case C4MessageBoardCommand::C4MSGCMDR_Escaped: {
// escape strings
StdStrBuf Par;
Par.Copy(pCmdPar);
Par.EscapeString();
// compose script
Script.Format(CmdScript.getData(), Par.getData());
} break;
case C4MessageBoardCommand::C4MSGCMDR_Plain:
// unescaped
Script.Format(CmdScript.getData(), pCmdPar);
break;
case C4MessageBoardCommand::C4MSGCMDR_Identifier: {
// only allow identifier-characters
StdStrBuf Par;
while (IsIdentifier(*pCmdPar) || isspace((unsigned char)*pCmdPar))
Par.AppendChar(*pCmdPar++);
// compose script
Script.Format(CmdScript.getData(), Par.getData());
} break;
}
} else
Script = CmdScript.getData();
// add script
Game.Control.DoInput(CID_Script, new C4ControlScript(Script.getData()),
CDT_Decide);
// ok
return TRUE;
}
// unknown command
StdStrBuf sErr;
sErr.Format(LoadResStr("IDS_ERR_UNKNOWNCMD"), szCmdName);
if (pLobby)
pLobby->OnError(sErr.getData());
else
Log(sErr.getData());
return FALSE;
}