void ScreenSelectMode::UpdateSelectableChoices() { CStringArray GraphicPaths; m_iNumChoices = 0; unsigned i=0; unsigned j=0; for( i=0; i<m_aModeChoices.size(); i++ ) { const ModeChoice& mc = m_aModeChoices[i]; CString modename = mc.m_sName; modename.MakeUpper(); // FIXME for new premium prefs const int SidesJoinedToPlay = (mc.m_pStyle == NULL) ? 1 : 1; if( PREFSMAN->GetPremium()!=PrefsManager::JOINT_PREMIUM || ( (PREFSMAN->GetPremium()==PrefsManager::JOINT_PREMIUM) && ( (INCLUDE_DOUBLE_IN_JP == 1 && (GAMESTATE->GetNumSidesJoined() == SidesJoinedToPlay)) || ( INCLUDE_DOUBLE_IN_JP == 0 && ( GAMESTATE->GetNumSidesJoined() == SidesJoinedToPlay || (modename.substr(0, 6) == "DOUBLE" || modename.substr(0, 13) == "ARCADE-DOUBLE" || modename.substr(0, 10) == "HALFDOUBLE" || modename.substr(0, 17) == "ARCADE-HALFDOUBLE") && GAMESTATE->GetNumSidesJoined() != 2 ) ) ) ) ) { m_iNumChoices++; if(j<=MAX_ELEMS) { m_iSelectableChoices[j] = i; j++; } else { ASSERT(0); // too many choices, can't track them all. Quick Fix: If You Get This Just Increase MAX_ELEMS } GraphicPaths.push_back(arrayLocations[i]); } } m_ScrollingList.SetSelection(0); m_ScrollingList.Unload(); m_ScrollingList.Load(GraphicPaths); if(USE_MODE_SPECIFIC_BGS == 1) { // TODO: Finish implementing this! (Got exams no time to finish...) } }
bool CKeyMap::parseModifiers(CString& x, KeyModifierMask& mask) { // initialize tables initKeyNameMaps(); mask = 0; CString::size_type tb = x.find_first_not_of(" \t", 0); while (tb != CString::npos) { // get next component CString::size_type te = x.find_first_of(" \t+)", tb); if (te == CString::npos) { te = x.size(); } CString c = x.substr(tb, te - tb); if (c.empty()) { // missing component return false; } if (s_nameToModifierMap->count(c) > 0) { KeyModifierMask mod = s_nameToModifierMap->find(c)->second; if ((mask & mod) != 0) { // modifier appears twice return false; } mask |= mod; } else { // unknown string x.erase(0, tb); CString::size_type tb = x.find_first_not_of(" \t"); CString::size_type te = x.find_last_not_of(" \t"); if (tb == CString::npos) { x = ""; } else { x = x.substr(tb, te - tb + 1); } return true; } // check for '+' or end of string tb = x.find_first_not_of(" \t", te); if (tb != CString::npos) { if (x[tb] != '+') { // expected '+' return false; } tb = x.find_first_not_of(" \t", tb + 1); } } // parsed the whole thing x = ""; return true; }
void StepManiaLanServer::AnalizeChat(PacketFunctions &Packet, const unsigned int clientNum) { CString message = Packet.ReadNT(); if (message.at(0) == '/') { CString command = message.substr(1, message.find(" ")-1); if ((command.compare("list") == 0)||(command.compare("have") == 0)) { if (command.compare("list") == 0) { Reply.ClearPacket(); Reply.Write1(NSCCM + NSServerOffset); Reply.WriteNT(ListPlayers()); SendNetPacket(clientNum, Reply); } else { message = ""; message += Client[clientNum]->Player[0].name; if (Client[clientNum]->twoPlayers) message += "&"; message += Client[clientNum]->Player[1].name; message += " forces has song."; Client[clientNum]->forceHas = true; ServerChat(message); } } else { if (clientNum == 0) { if (command.compare("force_start") == 0) ForceStart(); if (command.compare("kick") == 0) { CString name = message.substr(message.find(" ")+1); Kick(name); } if (command.compare("ban") == 0) { CString name = message.substr(message.find(" ")+1); Ban(name); } } else { Reply.ClearPacket(); Reply.Write1(NSCCM + NSServerOffset); Reply.WriteNT("You do not have permission to use server commands."); SendNetPacket(clientNum, Reply); } } } else RelayChat(message, clientNum); }
void CDragInformation::parseDragInfo(CDragFileList& dragFileList, UInt32 fileNum, CString data) { size_t startPos = 0; size_t findResult1 = 0; size_t findResult2 = 0; dragFileList.clear(); CString slash("\\"); if (data.find("/", startPos) != string::npos) { slash = "/"; } UInt32 index = 0; while (index < fileNum) { findResult1 = data.find(',', startPos); findResult2 = data.find_last_of(slash, findResult1); if (findResult1 == startPos) { //TODO: file number does not match, something goes wrong break; } // set filename if (findResult1 - findResult2 > 1) { CString filename = data.substr(findResult2 + 1, findResult1 - findResult2 - 1); CDragInformation di; di.setFilename(filename); dragFileList.push_back(di); } startPos = findResult1 + 1; //set filesize findResult2 = data.find(',', startPos); if (findResult2 - findResult1 > 1) { CString filesize = data.substr(findResult1 + 1, findResult2 - findResult1 - 1); size_t size = stringToNum(filesize); dragFileList.at(index).setFilesize(size); } startPos = findResult1 + 1; ++index; } LOG((CLOG_DEBUG "drag info received, total drag file number: %i", dragFileList.size())); for (size_t i = 0; i < dragFileList.size(); ++i) { LOG((CLOG_DEBUG2 "dragging file %i name: %s", i + 1, dragFileList.at(i).getFilename().c_str())); } }
CString CTemplate::ResolveLiteral(const CString& sString) { if (sString.Left(2) == "**") { // Allow string to start with a literal * by using two in a row return sString.substr(1); } else if (sString.Left(1) == "*") { // If it starts with only one * then treat it as a var and do a lookup return GetValue(sString.substr(1)); } return sString; }
void CIniFile::Path(const CString& newPath){ //альтернатива basename, dirname int lastSlashPos = newPath.rfind('/'); CString fname = newPath.substr(lastSlashPos+1, CString::npos); archive_path = backup_path = newPath.substr(0, lastSlashPos); backup_path += "/backup/" + fname; archive_path += "/archive/" + fname; path = newPath; };
void CClient::ParsePass(const CString& sAuthLine) { // [user[@identifier][/network]:]password const size_t uColon = sAuthLine.find(":"); if (uColon != CString::npos) { m_sPass = sAuthLine.substr(uColon + 1); ParseUser(sAuthLine.substr(0, uColon)); } else { m_sPass = sAuthLine; } }
void CClient::ParseUser(const CString& sAuthLine) { // user[@identifier][/network] const size_t uSlash = sAuthLine.rfind("/"); if (uSlash != CString::npos) { m_sNetwork = sAuthLine.substr(uSlash + 1); ParseIdentifier(sAuthLine.substr(0, uSlash)); } else { ParseIdentifier(sAuthLine); } }
CModule::EModRet TwitchTMI::OnUserJoin(CString& sChannel, CString& sKey) { CString chname = sChannel.substr(1); CThreadPool::Get().addJob(new TwitchTMIJob(this, chname)); return CModule::CONTINUE; }
CString CArgParser::assembleCommand(std::vector<CString>& argsArray, CString ignoreArg, int parametersRequired) { CString result; for (std::vector<CString>::iterator it = argsArray.begin(); it != argsArray.end(); ++it) { if (it->compare(ignoreArg) == 0) { it = it + parametersRequired; continue; } // if there is a space in this arg, use double quotes surround it if ((*it).find(" ") != CString::npos) { (*it).insert(0, "\""); (*it).push_back('\"'); } result.append(*it); // add space to saperate args result.append(" "); } if (!result.empty()) { // remove the tail space result = result.substr(0, result.size() - 1); } return result; }
void CDragInformation::parseDragInfo(CDragFileList& dragFileList, UInt32 fileNum, CString data) { size_t startPos = 0; size_t findResult1 = 0; size_t findResult2 = 0; dragFileList.clear(); CString slash("\\"); if (data.find("/", startPos) != -1) { slash = "/"; } while (fileNum) { findResult1 = data.find('\0', startPos); findResult2 = data.find_last_of(slash, findResult1); if (findResult1 == startPos) { //TODO: file number does not match, something goes wrong break; } if (findResult1 - findResult2 > 1) { dragFileList.push_back(data.substr(findResult2 + 1, findResult1 - findResult2)); } startPos = findResult1 + 1; --fileNum; } }
// this function helps imprint out. it checks if there is a substitution token at 'caret' in 'alias_data' // and if it finds one, pulls the appropriate token out of 'line' and appends it to 'output', and updates 'caret'. // 'skip' is updated based on the logic that we should skip the % at the caret if we fail to parse the token. static void ParseToken(const CString &alias_data, const CString &line, CString &output, size_t &caret, size_t &skip) { bool optional = false; bool subsequent = false; size_t index = caret + 1; int token = -1; skip = 1; if (alias_data.length() > index && alias_data[index] == '?') { optional = true; ++index; } // try to read optional flag if (alias_data.length() > index && CString(alias_data.substr(index)).Convert(&token)) // try to read integer { while(alias_data.length() > index && alias_data[index] >= '0' && alias_data[index] <= '9') ++index; // skip any numeric digits in string } // (supposed to fail if whitespace precedes integer) else return; // token was malformed. leave caret unchanged, and flag first character for skipping if (alias_data.length() > index && alias_data[index] == '+') { subsequent = true; ++index; } // try to read subsequent flag if (alias_data.length() > index && alias_data[index] == '%') { ++index; } // try to read end-of-substitution marker else return; CString stok = line.Token(token, subsequent, " "); // if we get here, we're definitely dealing with a token, so get the token's value if (stok.empty() && !optional) throw std::invalid_argument(CString("missing required parameter: ") + CString(token)); // blow up if token is required and also empty output.append(stok); // write token value to output skip = 0; // since we're moving the cursor after the end of the token, skip no characters caret = index; // advance the cursor forward by the size of the token }
CString Directory::GetFolderPath(const CString& strFolderPath) { int n1 = strFolderPath.rfind(FILE_SEPARATOR_STR); if (n1 < 0 ) return _T(""); return strFolderPath.substr(0,n1); }
bool getline(CString &_str, CString &line){ if(_str.size()==0) return false; CString::size_type pLeft=0, pRight = _str.find('\n'); line = _str.substr( pLeft, pRight ); _str = _str.erase(0,pRight+1); return true; };
void CClient::ParseIdentifier(const CString& sAuthLine) { // user[@identifier] const size_t uAt = sAuthLine.rfind("@"); if (uAt != CString::npos) { const CString sId = sAuthLine.substr(uAt + 1); if (IsValidIdentifier(sId)) { m_sIdentifier = sId; m_sUser = sAuthLine.substr(0, uAt); } else { m_sUser = sAuthLine; } } else { m_sUser = sAuthLine; } }
void CArgParser::splitCommandString(CString& command, std::vector<CString>& argv) { if (command.empty()) { return ; } size_t leftDoubleQuote = 0; size_t rightDoubleQuote = 0; searchDoubleQuotes(command, leftDoubleQuote, rightDoubleQuote); size_t startPos = 0; size_t space = command.find(" ", startPos); while (space != CString::npos) { bool ignoreThisSpace = false; // check if the space is between two double quotes if (space > leftDoubleQuote && space < rightDoubleQuote) { ignoreThisSpace = true; } else if (space > rightDoubleQuote){ searchDoubleQuotes(command, leftDoubleQuote, rightDoubleQuote, rightDoubleQuote + 1); } if (!ignoreThisSpace) { CString subString = command.substr(startPos, space - startPos); removeDoubleQuotes(subString); argv.push_back(subString); } // find next space if (ignoreThisSpace) { space = command.find(" ", rightDoubleQuote + 1); } else { startPos = space + 1; space = command.find(" ", startPos); } } CString subString = command.substr(startPos, command.size()); removeDoubleQuotes(subString); argv.push_back(subString); }
void ScreenPackages::HTMLParse() { m_Links.clear(); m_LinkTitles.clear(); m_Links.push_back( " " ); m_LinkTitles.push_back( "--Visit URL--" ); //XXX: VERY DIRTY HTML PARSER! //Only designed to find links on websites. int i = m_sBUFFER.Find( "<A " ); int j = 0; int k = 0; int l = 0; int m = 0; for ( int mode = 0; mode < 2; mode++ ) { while ( i>=0 ) { k = m_sBUFFER.Find( ">", i+1 ); l = m_sBUFFER.Find( "HREF", i+1); m = m_sBUFFER.Find( "=", l ); if ( ( l > k ) || ( m > k ) ) //no "href" in this tag. { if ( mode == 0 ) i = m_sBUFFER.Find( "<A ", i+1 ); else i = m_sBUFFER.Find( "<a ", i+1 ); continue; } l = m_sBUFFER.Find( "</", m+1 ); //Special case: There is exactly one extra tag in the link. j = m_sBUFFER.Find( ">", k+1 ); if ( j < l ) k = j; CString TempLink = StripOutContainers( m_sBUFFER.substr(m+1,k-m-1) ); if ( TempLink.substr(0,7).compare("http://") != 0 ) TempLink = m_sBaseAddress + TempLink; CString TempTitle = m_sBUFFER.substr( k+1, l-k-1 ); m_Links.push_back( TempLink ); m_LinkTitles.push_back( TempTitle ); if ( mode == 0 ) i = m_sBUFFER.Find( "<A ", i+1 ); else i = m_sBUFFER.Find( "<a ", i+1 ); } if ( mode == 0 ) i = m_sBUFFER.Find( "<a " ); } UpdateLinksList(); }
void CArgParser::removeDoubleQuotes(CString& arg) { // if string is surrounded by double quotes, remove them if (arg[0] == '\"' && arg[arg.size() - 1] == '\"') { arg = arg.substr(1, arg.size() - 2); } }
void CNick::Parse(const CString& sNickMask) { if (sNickMask.empty()) { return; } CString::size_type uPos = sNickMask.find('!'); if (uPos == CString::npos) { m_sNick = sNickMask.substr((sNickMask[0] == ':')); return; } m_sNick = sNickMask.substr((sNickMask[0] == ':'), uPos); m_sHost = sNickMask.substr(uPos +1); if ((uPos = m_sHost.find('@')) != CString::npos) { m_sIdent = m_sHost.substr(0, uPos); m_sHost = m_sHost.substr(uPos +1); } }
void CPrimaryClient::setClipboard(ClipboardID id, const IClipboard* clipboard) { LOG((CLOG_INFO "xCprimaryClient::setClipboard call. Name: %s", getName().c_str())); // ignore if this clipboard is already clean if (m_clipboardDirty[id]) { // this clipboard is now clean m_clipboardDirty[id] = false; CClipboard Clipboard; Clipboard.copy(&Clipboard,clipboard); Clipboard.open(0); CString content, new_content; if(Clipboard.has(IClipboard::kFilePath)) { CString prefix, source; content = Clipboard.get(IClipboard::kFilePath); size_t pos = content.find("\n"); source = content.substr(0,pos); //content = content.substr(pos+1, content.size()); CScreenMounts *map = ((CServerApp*) &ARCH->app())->args().m_config->getMounts(source, getName()); LOG((CLOG_INFO "X_PAS1 setClipboard: %s %s",source.c_str(), content.c_str())); if (map!=NULL && !map->empty()) { while (pos < content.size()) { ++pos; CString line = content.substr(pos, content.find("\n", pos)-pos+1); pos = content.find("\n", pos); LOG ((CLOG_INFO "X_PAS2 The line is: %s\n", line.c_str())); for( CScreenMounts::iterator it = map->begin(); it != map->end(); it++) { int p = line.find(it->first); if( p != std::string::npos) { line = it->second + line.substr(p + it->first.size() ); break; } } LOG ((CLOG_INFO "it changed to: %s\n", line.c_str())); new_content.append(line); } Clipboard.add(IClipboard::kFilePath, new_content); LOG((CLOG_INFO "X_PAS3 setClipboard: %s %s",source.c_str(), Clipboard.get(IClipboard::kFilePath).c_str())); } LOG((CLOG_INFO "X_PAS4 Changed2 clipboard: %s", new_content.c_str())); } Clipboard.close(); // set clipboard m_screen->setClipboard(id, &Clipboard); } }
void CDaemonApp::handleIpcMessage(const CEvent& e, void*) { CIpcMessage* m = static_cast<CIpcMessage*>(e.getDataObject()); switch (m->type()) { case kIpcCommand: { CIpcCommandMessage* cm = static_cast<CIpcCommandMessage*>(m); CString command = cm->command(); LOG((CLOG_DEBUG "new command, elevate=%d command=%s", cm->elevate(), command.c_str())); CString debugArg("--debug"); UInt32 debugArgPos = static_cast<UInt32>(command.find(debugArg)); if (debugArgPos != CString::npos) { UInt32 from = debugArgPos + static_cast<UInt32>(debugArg.size()) + 1; UInt32 nextSpace = static_cast<UInt32>(command.find(" ", from)); CString logLevel(command.substr(from, nextSpace - from)); try { // change log level based on that in the command string // and change to that log level now. ARCH->setting("LogLevel", logLevel); CLOG->setFilter(logLevel.c_str()); } catch (XArch& e) { LOG((CLOG_ERR "failed to save LogLevel setting, %s", e.what().c_str())); } } try { // store command in system settings. this is used when the daemon // next starts. ARCH->setting("Command", command); // TODO: it would be nice to store bools/ints... ARCH->setting("Elevate", CString(cm->elevate() ? "1" : "0")); } catch (XArch& e) { LOG((CLOG_ERR "failed to save settings, %s", e.what().c_str())); } #if SYSAPI_WIN32 // tell the relauncher about the new command. this causes the // relauncher to stop the existing command and start the new // command. m_relauncher->command(command, cm->elevate()); #endif break; } case kIpcHello: m_ipcLogOutputter->notifyBuffer(); break; } }
TEST(CClipboardTests, marshall_withTextAdded_endsWithAdded) { CClipboard clipboard; clipboard.open(0); clipboard.add(IClipboard::kText, "synergy rocks!"); clipboard.close(); CString actual = clipboard.marshall(); // string contains other data, but should end in the string we added. EXPECT_EQ("synergy rocks!", actual.substr(12)); }
CString CDragInformation::getDragFileExtension(CString fileName) { size_t findResult = -1; findResult = fileName.find_last_of(".", fileName.size()); if (findResult != -1) { return fileName.substr(findResult + 1, fileName.size() - findResult - 1); } else { return ""; } }
virtual EModRet OnRaw(CString& sLine) { if (sLine.Equals("ERROR ", false, 6)) { //ERROR :Closing Link: nick[24.24.24.24] (Excess Flood) //ERROR :Closing Link: nick[24.24.24.24] Killer (Local kill by Killer (reason)) CString sError(sLine.substr(7)); if (sError.Left(1) == ":") sError.LeftChomp(); Log("[" + m_pUser->GetUserName() + "] disconnected from IRC: " + m_pUser->GetCurrentServer()->GetName() + " [" + sError + "]", LOG_NOTICE); } return CONTINUE; }
CString GetExtension( const CString &sPath ) { size_t pos = sPath.rfind( '.' ); if( pos == sPath.npos ) return ""; size_t slash = sPath.find( '/', pos ); if( slash != sPath.npos ) return ""; /* rare: path/dir.ext/fn */ return sPath.substr( pos+1, sPath.size()-pos+1 ); }
bool IsOnlineModNick(const CString& sNick) { const CString& sPrefix = m_pUser->GetStatusPrefix(); if (!sNick.Equals(sPrefix, false, sPrefix.length())) return false; CString sModNick = sNick.substr(sPrefix.length()); if (!sModNick.Equals("status") && !m_pUser->GetModules().FindModule(sModNick) && !CZNC::Get().GetModules().FindModule(sModNick)) return false; return true; }
EModRet OnRaw(CString& sLine) override { if (sLine.StartsWith("ERROR ")) { //ERROR :Closing Link: nick[24.24.24.24] (Excess Flood) //ERROR :Closing Link: nick[24.24.24.24] Killer (Local kill by Killer (reason)) CString sError(sLine.substr(6)); if (sError.Left(1) == ":") sError.LeftChomp(); Log("[" + GetUser()->GetUserName() + "/" + GetNetwork()->GetName() + "] disconnected from IRC: " + GetNetwork()->GetCurrentServer()->GetName() + " [" + sError + "]", LOG_NOTICE); } return CONTINUE; }
bool IsOnlineModNick(const CString& sNick) { const CString& sPrefix = GetUser()->GetStatusPrefix(); if (!sNick.StartsWith(sPrefix)) return false; CString sModNick = sNick.substr(sPrefix.length()); if (sModNick.Equals("status") || GetNetwork()->GetModules().FindModule(sModNick) || GetUser()->GetModules().FindModule(sModNick) || CZNC::Get().GetModules().FindModule(sModNick)) return true; return false; }
// nb: i tried to use InternetCrackUrl here, but couldn't quite get that to // work. here's some (less robust) code to split the url into components. // this works fine with simple urls, but doesn't consider the full url spec. static CWinINetUrl parseUrl(const CString& url) { CWinINetUrl parsed; size_t schemeEnd = url.find("://"); size_t hostEnd = url.find('/', schemeEnd + 3); parsed.m_scheme = url.substr(0, schemeEnd); parsed.m_host = url.substr(schemeEnd + 3, hostEnd - (schemeEnd + 3)); parsed.m_path = url.substr(hostEnd); parsed.m_port = INTERNET_DEFAULT_HTTP_PORT; parsed.m_flags = 0; if (parsed.m_scheme.find("https") != CString::npos) { parsed.m_port = INTERNET_DEFAULT_HTTPS_PORT; parsed.m_flags = INTERNET_FLAG_SECURE; } return parsed; }
EModRet OnUserRaw(CString& sLine) override { if (sLine.StartsWith("schat ")) { OnModCommand("chat " + sLine.substr(6)); return (HALT); } else if (sLine.Equals("schat")) { PutModule("SChat User Area ..."); OnModCommand("help"); return (HALT); } return (CONTINUE); }