本文整理汇总了C++中SCString类的典型用法代码示例。如果您正苦于以下问题:C++ SCString类的具体用法?C++ SCString怎么用?C++ SCString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SCString类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RandomFromSet
static CString RandomFromSet(const SCString& sSet,
std::default_random_engine& gen) {
std::uniform_int_distribution<> distr(0, sSet.size() - 1);
auto it = sSet.cbegin();
std::advance(it, distr(gen));
return *it;
}
示例2: DelToken
void DelToken(const CString sToken) {
SCString ssTokens = GetUserTokens(m_pUser);
SCString::iterator it = ssTokens.find(sToken);
if (it != ssTokens.end()) {
ssTokens.erase(it);
SetUserTokens(m_pUser, ssTokens);
}
}
示例3: AddToken
void AddToken(CString sToken) {
SCString ssTokens = GetUserTokens(m_pUser);
SCString::iterator it = ssTokens.find(sToken);
if (it == ssTokens.end()) {
ssTokens.insert(sToken);
SetUserTokens(m_pUser, ssTokens);
}
}
示例4: SetUserTokens
void SetUserTokens(CUser *pUser, SCString ssTokens) {
CString sVal;
for (SCString::const_iterator it = ssTokens.begin(); it != ssTokens.end(); ++it) {
sVal += *it + " ";
}
SetNV(pUser->GetUserName(), sVal);
}
示例5: ListTokens
void ListTokens(const CString& sLine) {
SCString ssTokens = GetUserTokens(m_pUser);
CTable table;
table.AddColumn("Tolken");
for (SCString::const_iterator it = ssTokens.begin(); it != ssTokens.end(); ++it) {
table.AddRow();
table.SetCell("Token", *it);
}
if (PutModule(table) == 0) {
PutModule("No tokens set for your user");
}
}
示例6: RandomFrom2SetsWithBias
static std::tuple<CString, bool> RandomFrom2SetsWithBias(const SCString& ss4, const SCString& ss6, std::default_random_engine& gen) {
// It's not quite what RFC says how to choose between IPv4 and IPv6, but proper way is harder to implement.
// It would require to maintain some state between Csock objects.
bool bUseIPv6;
if (ss4.empty()) {
bUseIPv6 = true;
} else if (ss6.empty()) {
bUseIPv6 = false;
} else {
// Let's prefer IPv6 :)
std::discrete_distribution<> d({2, 3});
bUseIPv6 = d(gen);
}
const SCString& sSet = bUseIPv6 ? ss6 : ss4;
return std::make_tuple(RandomFromSet(sSet, gen), bUseIPv6);
}
示例7: ParseURI
void CHTTPSock::ReadLine(const CString& sData) {
if (m_bGotHeader) {
return;
}
CString sLine = sData;
sLine.TrimRight("\r\n");
CString sName = sLine.Token(0);
if (sName.Equals("GET")) {
m_bPost = false;
m_sURI = sLine.Token(1);
m_bHTTP10Client = sLine.Token(2).Equals("HTTP/1.0");
ParseURI();
} else if (sName.Equals("POST")) {
m_bPost = true;
m_sURI = sLine.Token(1);
ParseURI();
} else if (sName.Equals("Cookie:")) {
VCString vsNV;
sLine.Token(1, true).Split(";", vsNV, false, "", "", true, true);
for (const CString& s : vsNV) {
m_msRequestCookies[s.Token(0, false, "=").Escape_n(CString::EURL, CString::EASCII)] =
s.Token(1, true, "=").Escape_n(CString::EURL, CString::EASCII);
}
} else if (sName.Equals("Authorization:")) {
CString sUnhashed;
sLine.Token(2).Base64Decode(sUnhashed);
m_sUser = sUnhashed.Token(0, false, ":");
m_sPass = sUnhashed.Token(1, true, ":");
m_bBasicAuth = true;
// Postpone authorization attempt until end of headers, because cookies should be read before that, otherwise session id will be overwritten in GetSession()
} else if (sName.Equals("Content-Length:")) {
m_uPostLen = sLine.Token(1).ToULong();
if (m_uPostLen > MAX_POST_SIZE)
PrintErrorPage(413, "Request Entity Too Large", "The request you sent was too large.");
} else if (sName.Equals("X-Forwarded-For:")) {
// X-Forwarded-For: client, proxy1, proxy2
if (m_sForwardedIP.empty()) {
const VCString& vsTrustedProxies = CZNC::Get().GetTrustedProxies();
CString sIP = GetRemoteIP();
VCString vsIPs;
sLine.Token(1, true).Split(",", vsIPs, false, "", "", false, true);
while (!vsIPs.empty()) {
// sIP told us that it got connection from vsIPs.back()
// check if sIP is trusted proxy
bool bTrusted = false;
for (const CString& sTrustedProxy : vsTrustedProxies) {
if (sIP.WildCmp(sTrustedProxy)) {
bTrusted = true;
break;
}
}
if (bTrusted) {
// sIP is trusted proxy, so use vsIPs.back() as new sIP
sIP = vsIPs.back();
vsIPs.pop_back();
} else {
break;
}
}
// either sIP is not trusted proxy, or it's in the beginning of the X-Forwarded-For list
// in both cases use it as the endpoind
m_sForwardedIP = sIP;
}
} else if (sName.Equals("If-None-Match:")) {
// this is for proper client cache support (HTTP 304) on static files:
m_sIfNoneMatch = sLine.Token(1, true);
} else if (sName.Equals("Accept-Encoding:") && !m_bHTTP10Client) {
SCString ssEncodings;
// trimming whitespace from the tokens is important:
sLine.Token(1, true).Split(",", ssEncodings, false, "", "", false, true);
m_bAcceptGzip = (ssEncodings.find("gzip") != ssEncodings.end());
} else if (sLine.empty()) {
if (m_bBasicAuth && !m_bLoggedIn) {
m_bLoggedIn = OnLogin(m_sUser, m_sPass, true);
// After successful login ReadLine("") will be called again to trigger "else" block
// Failed login sends error and closes socket, so no infinite loop here
} else {
m_bGotHeader = true;
if (m_bPost) {
m_sPostData = GetInternalReadBuffer();
CheckPost();
} else {
GetPage();
}
DisableReadLine();
}
}
}
示例8: HandleCap
void CClient::HandleCap(const CMessage& Message) {
CString sSubCmd = Message.GetParam(0);
if (sSubCmd.Equals("LS")) {
SCString ssOfferCaps;
for (const auto& it : m_mCoreCaps) {
bool bServerDependent = std::get<0>(it.second);
if (!bServerDependent ||
m_ssServerDependentCaps.count(it.first) > 0)
ssOfferCaps.insert(it.first);
}
GLOBALMODULECALL(OnClientCapLs(this, ssOfferCaps), NOTHING);
CString sRes =
CString(" ").Join(ssOfferCaps.begin(), ssOfferCaps.end());
RespondCap("LS :" + sRes);
m_bInCap = true;
if (Message.GetParam(1).ToInt() >= 302) {
m_bCapNotify = true;
}
} else if (sSubCmd.Equals("END")) {
m_bInCap = false;
if (!IsAttached()) {
if (!m_pUser && m_bGotUser && !m_bGotPass) {
SendRequiredPasswordNotice();
} else {
AuthUser();
}
}
} else if (sSubCmd.Equals("REQ")) {
VCString vsTokens;
Message.GetParam(1).Split(" ", vsTokens, false);
for (const CString& sToken : vsTokens) {
bool bVal = true;
CString sCap = sToken;
if (sCap.TrimPrefix("-")) bVal = false;
bool bAccepted = false;
const auto& it = m_mCoreCaps.find(sCap);
if (m_mCoreCaps.end() != it) {
bool bServerDependent = std::get<0>(it->second);
bAccepted = !bServerDependent ||
m_ssServerDependentCaps.count(sCap) > 0;
}
GLOBALMODULECALL(IsClientCapSupported(this, sCap, bVal),
&bAccepted);
if (!bAccepted) {
// Some unsupported capability is requested
RespondCap("NAK :" + Message.GetParam(1));
return;
}
}
// All is fine, we support what was requested
for (const CString& sToken : vsTokens) {
bool bVal = true;
CString sCap = sToken;
if (sCap.TrimPrefix("-")) bVal = false;
auto handler_it = m_mCoreCaps.find(sCap);
if (m_mCoreCaps.end() != handler_it) {
const auto& handler = std::get<1>(handler_it->second);
handler(bVal);
}
GLOBALMODULECALL(OnClientCapRequest(this, sCap, bVal), NOTHING);
if (bVal) {
m_ssAcceptedCaps.insert(sCap);
} else {
m_ssAcceptedCaps.erase(sCap);
}
}
RespondCap("ACK :" + Message.GetParam(1));
} else if (sSubCmd.Equals("LIST")) {
CString sList =
CString(" ").Join(m_ssAcceptedCaps.begin(), m_ssAcceptedCaps.end());
RespondCap("LIST :" + sList);
} else {
PutClient(":irc.znc.in 410 " + GetNick() + " " + sSubCmd +
" :Invalid CAP subcommand");
}
}
示例9: CheckToken
bool CheckToken(CUser *pUser, CString sToken) {
SCString ssTokens = GetUserTokens(pUser);
return ssTokens.find(sToken) != ssTokens.end();
}
示例10: OnClientCapLs
virtual void OnClientCapLs(CClient* pClient, SCString& ssCaps) {
ssCaps.insert(kPLVCapability);
}
示例11: ParseURI
void CHTTPSock::ReadLine(const CString& sData) {
if (m_bGotHeader) {
return;
}
CString sLine = sData;
sLine.TrimRight("\r\n");
CString sName = sLine.Token(0);
if (sName.Equals("GET")) {
m_bPost = false;
m_sURI = sLine.Token(1);
m_bHTTP10Client = sLine.Token(2).Equals("HTTP/1.0");
ParseURI();
} else if (sName.Equals("POST")) {
m_bPost = true;
m_sURI = sLine.Token(1);
ParseURI();
} else if (sName.Equals("Cookie:")) {
VCString vsNV;
sLine.Token(1, true).Split(";", vsNV, false, "", "", true, true);
for (unsigned int a = 0; a < vsNV.size(); a++) {
CString s(vsNV[a]);
m_msRequestCookies[s.Token(0, false, "=").Escape_n(CString::EURL, CString::EASCII)] =
s.Token(1, true, "=").Escape_n(CString::EURL, CString::EASCII);
}
} else if (sName.Equals("Authorization:")) {
CString sUnhashed;
sLine.Token(2).Base64Decode(sUnhashed);
m_sUser = sUnhashed.Token(0, false, ":");
m_sPass = sUnhashed.Token(1, true, ":");
m_bLoggedIn = OnLogin(m_sUser, m_sPass);
} else if (sName.Equals("Content-Length:")) {
m_uPostLen = sLine.Token(1).ToULong();
if (m_uPostLen > MAX_POST_SIZE)
PrintErrorPage(413, "Request Entity Too Large", "The request you sent was too large.");
} else if (sName.Equals("If-None-Match:")) {
// this is for proper client cache support (HTTP 304) on static files:
m_sIfNoneMatch = sLine.Token(1, true);
} else if (sName.Equals("Accept-Encoding:") && !m_bHTTP10Client) {
SCString ssEncodings;
// trimming whitespace from the tokens is important:
sLine.Token(1, true).Split(",", ssEncodings, false, "", "", false, true);
m_bAcceptGzip = (ssEncodings.find("gzip") != ssEncodings.end());
} else if (sLine.empty()) {
m_bGotHeader = true;
if (m_bPost) {
m_sPostData = GetInternalReadBuffer();
CheckPost();
} else {
GetPage();
}
DisableReadLine();
}
}
示例12: scsf_SC_TradingCrossOverExample
SCSFExport scsf_SC_TradingCrossOverExample(SCStudyInterfaceRef sc) {
SCInputRef dailyLowRef = sc.Input[0];
SCInputRef dailyHighRef = sc.Input[1];
SCInputRef outputFileName = sc.Input[2];
SCInputRef todayLowRef = sc.Input[3];
SCInputRef todayHighRef = sc.Input[4];
//BollingerBangs
SCInputRef topBandRef = sc.Input[5];
SCInputRef movingAverageRef = sc.Input[6];
SCInputRef bottomBandRef = sc.Input[7];
//logTheCurrentDirectory(sc);
if(sc.Index == 0)
{
SCString outputFileStr;
outputFileStr.Format("%s-%d.csv",sc.Symbol.GetChars(), sc.SecondsPerBar / 60);
outputFileName.Name = "Output File";
//outputFileName.SetString(sc.Symbol);
outputFileName.SetString(outputFileStr);
remove(outputFileName.GetString());
}
ofstream outputStream;
outputStream.open (outputFileName.GetString(), std::ofstream::app);
if (sc.SetDefaults) {
dailyLowRef.Name = "Daily Low";
dailyLowRef.SetStudySubgraphValues(1, 2);
dailyHighRef.Name = "Daily High";
dailyHighRef.SetStudySubgraphValues(1, 1);
SCString outputFileStr;
outputFileStr.Format("%s-%d.csv",sc.Symbol.GetChars(), sc.SecondsPerBar / 60);
outputFileName.Name = "Output File";
//outputFileName.SetString(sc.Symbol);
outputFileName.SetString(outputFileStr);
todayLowRef.Name = "Today Low";
todayLowRef.SetStudySubgraphValues(4, 2);
todayHighRef.Name = "Today High";
todayHighRef.SetStudySubgraphValues(4, 1);
//Bollinger Bands
topBandRef.Name = "Top Band";
topBandRef.SetStudySubgraphValues(3, 0);
movingAverageRef.Name = "Moving Average";
movingAverageRef.SetStudySubgraphValues(3, 1);
bottomBandRef.Name = "Bottom Band";
bottomBandRef.SetStudySubgraphValues(3, 2);
sc.GraphName = "DataWriter";
sc.StudyDescription = "Write the data to file";
sc.AutoLoop = 1; // true
sc.GraphRegion = 0;
sc.FreeDLL = 1;
sc.CalculationPrecedence = LOW_PREC_LEVEL;
sc.AllowMultipleEntriesInSameDirection = false;
sc.MaximumPositionAllowed = 5;
sc.SupportReversals = true;
// This is false by default. Orders will go to the simulation system always.
sc.SendOrdersToTradeService = false;
sc.AllowOppositeEntryWithOpposingPositionOrOrders = false;
sc.SupportAttachedOrdersForTrading = false;
sc.CancelAllOrdersOnEntriesAndReversals = true;
sc.AllowEntryWithWorkingOrders = false;
sc.CancelAllWorkingOrdersOnExit = true;
sc.AllowOnlyOneTradePerBar = true;
sc.MaintainTradeStatisticsAndTradesData = true;
return;
}
SCFloatArray dailyLows;
sc.GetStudyArrayUsingID(dailyLowRef.GetStudyID(), dailyLowRef.GetSubgraphIndex(), dailyLows);
float dailyLow = dailyLows[sc.Index];
SCFloatArray dailyHighs;
sc.GetStudyArrayUsingID(dailyHighRef.GetStudyID(), dailyHighRef.GetSubgraphIndex(), dailyHighs);
float dailyHigh = dailyHighs[sc.Index];
SCFloatArray todayLows;
sc.GetStudyArrayUsingID(todayLowRef.GetStudyID(), todayLowRef.GetSubgraphIndex(), todayLows);
float todayLow = todayLows[sc.Index];
//.........这里部分代码省略.........