Example #1
0
TEST(StringTest, Split) {
	EXPECT_EQ("a", CS("a b c").Token(0));
	EXPECT_EQ("b", CS("a b c").Token(1));
	EXPECT_EQ("", CS("a b c").Token(100));
	EXPECT_EQ("b c", CS("a b c").Token(1, true));
	EXPECT_EQ("c", CS("a  c").Token(1));
	EXPECT_EQ("", CS("a  c").Token(1, false, " ", true));
	EXPECT_EQ("c", CS("a  c").Token(1, false, "  "));
	EXPECT_EQ(" c", CS("a   c").Token(1, false, "  "));
	EXPECT_EQ("c", CS("a    c").Token(1, false, "  "));
	EXPECT_EQ("b c", CS("a (b c) d").Token(1, false, " ", false, "(", ")"));
	EXPECT_EQ("(b c)", CS("a (b c) d").Token(1, false, " ", false, "(", ")", false));
	EXPECT_EQ("d", CS("a (b c) d").Token(2, false, " ", false, "(", ")", false));

	VCString vexpected;
	VCString vresult;

	vexpected.push_back("a");
	vexpected.push_back("b");
	vexpected.push_back("c");
	CS("a b c").Split(" ", vresult);
	EXPECT_EQ(vexpected, vresult);

	MCString mexpected;
	MCString mresult;

	mexpected["a"] = "b";
	mexpected["c"] = "d";
	CS("a=x&c=d&a=b").URLSplit(mresult);
	EXPECT_EQ(mexpected, mresult) << "URLSplit";
}
Example #2
0
void CWebSock::GetAvailSkins(VCString& vRet) const {
	vRet.clear();

	CString sRoot(GetSkinPath("_default_"));

	sRoot.TrimRight("/");
	sRoot.TrimRight("_default_");
	sRoot.TrimRight("/");

	if (!sRoot.empty()) {
		sRoot += "/";
	}

	if (!sRoot.empty() && CFile::IsDir(sRoot)) {
		CDir Dir(sRoot);

		for (unsigned int d = 0; d < Dir.size(); d++) {
			const CFile& SubDir = *Dir[d];

			if (SubDir.IsDir() && SubDir.GetShortName() == "_default_") {
				vRet.push_back(SubDir.GetShortName());
				break;
			}
		}

		for (unsigned int e = 0; e < Dir.size(); e++) {
			const CFile& SubDir = *Dir[e];

			if (SubDir.IsDir() && SubDir.GetShortName() != "_default_" && SubDir.GetShortName() != ".svn") {
				vRet.push_back(SubDir.GetShortName());
			}
		}
	}
}
Example #3
0
void CWebSock::GetAvailSkins(VCString& vRet) const {
	vRet.clear();

	CString sRoot(GetSkinPath("_default_"));

	sRoot.TrimRight("/");
	sRoot.TrimRight("_default_");
	sRoot.TrimRight("/");

	if (!sRoot.empty()) {
		sRoot += "/";
	}

	if (!sRoot.empty() && CFile::IsDir(sRoot)) {
		CDir Dir(sRoot);

		for (const CFile* pSubDir : Dir) {
			if (pSubDir->IsDir() && pSubDir->GetShortName() == "_default_") {
				vRet.push_back(pSubDir->GetShortName());
				break;
			}
		}

		for (const CFile* pSubDir : Dir) {
			if (pSubDir->IsDir() && pSubDir->GetShortName() != "_default_" && pSubDir->GetShortName() != ".svn") {
				vRet.push_back(pSubDir->GetShortName());
			}
		}
	}
}
Example #4
0
TEST(StringTest, Split) {
    EXPECT_EQ(CS("a b c").Token(0), "a");
    EXPECT_EQ(CS("a b c").Token(1), "b");
    EXPECT_EQ(CS("a b c").Token(100), "");
    EXPECT_EQ(CS("a b c").Token(1, true), "b c");
    EXPECT_EQ(CS("a  c").Token(1), "c");
    EXPECT_EQ(CS("a  c").Token(1, false, " ", true), "");
    EXPECT_EQ(CS("a  c").Token(1, false, "  "), "c");
    EXPECT_EQ(CS("a   c").Token(1, false, "  "), " c");
    EXPECT_EQ(CS("a    c").Token(1, false, "  "), "c");
    EXPECT_EQ(CS("a (b c) d").Token(1, false, " ", false, "(", ")"), "b c");
    EXPECT_EQ(CS("a (b c) d").Token(1, false, " ", false, "(", ")", false),
              "(b c)");
    EXPECT_EQ(CS("a (b c) d").Token(2, false, " ", false, "(", ")", false),
              "d");

    VCString vexpected;
    VCString vresult;

    vexpected.push_back("a");
    vexpected.push_back("b");
    vexpected.push_back("c");
    CS("a b c").Split(" ", vresult);
    EXPECT_EQ(vresult, vexpected);

    MCString mexpected = {{"a", "b"}, {"c", "d"}};
    MCString mresult;

    CS("a=x&c=d&a=b").URLSplit(mresult);
    EXPECT_EQ(mexpected, mresult) << "URLSplit";
}
void CUrlBufferModule::CheckLineForLink(const CString& sMessage, const CString& sOrigin)
{
	if(sOrigin != m_pUser->GetUserName() && GetNV("enable").ToBool() )
	{	
		VCString words;
		CString output;
		sMessage.Split(" ", words, false, "", "", true, true);
		for (size_t a = 0; a < words.size(); a++) 
		{
			CString& word = words[a];
			if(word.Left(4) == "http" || word.Left(4) == "www.")
			{            
				//if you find an image download it, save it in the www directory and keep the new link in buffer
				VCString tokens;
				word.Split("/", tokens, false, "", "", true, true);
				CString name = tokens[tokens.size()-1];
				word.Split(".", tokens, false, "", "", true, true);

				//if it's an image link download/upload it else just keep the link
                time_t curtime;
                time(&curtime);
                CString dir = GetNV("directory") + CUtils::FormatTime(curtime,"%Y-%m-%d", m_pUser->GetTimezone()) + "/";
                CString nickname = (sOrigin.empty())? m_pUser->GetUserName() : sOrigin;
                if(!CFile::Exists(dir) && !CFile::IsDir(dir, false))
                {
                        CDir::MakeDir(dir, 0775);
                }

				if(isValidExtension( tokens[tokens.size()-1] ))
				{

                    std::stringstream ss;
					if( GetNV("enablelocal").ToBool())
					{
						ss << "wget -b -O " << dir.c_str() << name <<" -q " << word.c_str() << " 2>&1";
                        getStdoutFromCommand(ss.str());
					}
					ss.str("");
					if (!word.WildCmp("*imgur*") && GetNV("reupload").ToBool()) {
						ss << "curl -d \"image=" << word.c_str() << "\" -d \"key=5ce86e7f95d8e58b18931bf290f387be\" http://api.imgur.com/2/upload.xml | sed -n 's/.*<original>\\(.*\\)<\\/original>.*/\\1/p' 2>&1";
						output = getStdoutFromCommand(ss.str());
						lastUrls.push_back(output);
					} else {
						lastUrls.push_back(word);
					}
				} else if(GetNV("bufferalllinks").ToBool()){
					lastUrls.push_back(word);
                    //append nick:link to file
                    CString filename = dir + "links.txt";
                    std::ofstream log(filename.c_str() , std::ios_base::app | std::ios_base::out);
                    log << nickname << ": " << word << "\n"; 
				}
                                nicks.push_back( nickname );
			}
		}
	}
}
Example #6
0
File: log.cpp Project: Adam-/znc
CString CLogMod::JoinRules(const CString& sSeparator) const {
    VCString vsRules;
    for (const CLogRule& Rule : m_vRules) {
        vsRules.push_back(Rule.ToString());
    }

    return sSeparator.Join(vsRules.begin(), vsRules.end());
}
Example #7
0
CString CChan::GetOptions() const {
    VCString vsRet;

    if (IsDetached()) {
        vsRet.push_back("Detached");
    }

    if (AutoClearChanBuffer()) {
        if (HasAutoClearChanBufferSet()) {
            vsRet.push_back("AutoClearChanBuffer");
        } else {
            vsRet.push_back("AutoClearChanBuffer (default)");
        }
    }

    return CString(", ").Join(vsRet.begin(), vsRet.end());
}
Example #8
0
VCString CWebSock::GetDirs(CModule* pModule, bool bIsTemplate) {
	CString sHomeSkinsDir(CZNC::Get().GetZNCPath() + "/webskins/");
	CString sSkinName(GetSkinName());
	VCString vsResult;

	// Module specific paths

	if (pModule) {
		const CString& sModName(pModule->GetModName());

		// 1. ~/.znc/webskins/<user_skin_setting>/mods/<mod_name>/
		//
		if (!sSkinName.empty()) {
			vsResult.push_back(GetSkinPath(sSkinName) + "/mods/" + sModName + "/");
		}

		// 2. ~/.znc/webskins/_default_/mods/<mod_name>/
		//
		vsResult.push_back(GetSkinPath("_default_") + "/mods/" + sModName + "/");

		// 3. ./modules/<mod_name>/tmpl/
		//
		vsResult.push_back(pModule->GetModDataDir() + "/tmpl/");

		// 4. ~/.znc/webskins/<user_skin_setting>/mods/<mod_name>/
		//
		if (!sSkinName.empty()) {
			vsResult.push_back(GetSkinPath(sSkinName) + "/mods/" + sModName + "/");
		}

		// 5. ~/.znc/webskins/_default_/mods/<mod_name>/
		//
		vsResult.push_back(GetSkinPath("_default_") + "/mods/" + sModName + "/");
	}

	// 6. ~/.znc/webskins/<user_skin_setting>/
	//
	if (!sSkinName.empty()) {
		vsResult.push_back(GetSkinPath(sSkinName) + CString(bIsTemplate ? "/tmpl/" : "/"));
	}

	// 7. ~/.znc/webskins/_default_/
	//
	vsResult.push_back(GetSkinPath("_default_") + CString(bIsTemplate ? "/tmpl/" : "/"));

	return vsResult;
}
Example #9
0
size_t CHTTPSock::GetParamValues(const CString& sName, VCString& vsRet, const map<CString, VCString>& msvsParams, const CString& sFilter) {
	vsRet.clear();

	map<CString, VCString>::const_iterator it = msvsParams.find(sName);

	if (it != msvsParams.end()) {
		for (CString sParam : it->second) {
			sParam.Trim();

			for (size_t i = 0; i < sFilter.length(); i++) {
				sParam.Replace(CString(sFilter.at(i)), "");
			}
			vsRet.push_back(sParam);
		}
	}

	return vsRet.size();
}
Example #10
0
File: Message.cpp Project: BtbN/znc
CString CMessage::GetParamsColon(unsigned int uIdx, unsigned int uLen) const {
    if (m_vsParams.empty() || uLen == 0) {
        return "";
    }
    if (uLen > m_vsParams.size() - uIdx - 1) {
        uLen = m_vsParams.size() - uIdx;
    }
    VCString vsParams;
    unsigned uParams = m_vsParams.size();
    for (unsigned int i = uIdx; i < uIdx + uLen; ++i) {
        CString sParam = m_vsParams[i];
        if (i == uParams - 1 &&
            (m_bColon || sParam.empty() || sParam.StartsWith(":") ||
             sParam.Contains(" "))) {
            sParam = ":" + sParam;
        }
        vsParams.push_back(sParam);
    }
    return CString(" ").Join(vsParams.begin(), vsParams.end());
}