TEST(TStr, SplitOnCh) { const TStr Str = "abcde"; const TStr EmptyStr = ""; TStr LStr, RStr; // middle Str.SplitOnCh(LStr, 'c', RStr); ASSERT_EQ(LStr, "ab"); ASSERT_EQ(RStr, "de"); // non-existent Str.SplitOnCh(LStr, 'g', RStr); ASSERT_EQ(LStr, "abcde"); ASSERT_EQ(RStr, ""); // first Str.SplitOnCh(LStr, 'a', RStr); ASSERT_EQ(LStr, ""); ASSERT_EQ(RStr, "bcde"); // last Str.SplitOnCh(LStr, 'e', RStr); ASSERT_EQ(LStr, "abcd"); ASSERT_EQ(RStr, ""); // empty EmptyStr.SplitOnCh(LStr, 'a', RStr); ASSERT_EQ(LStr, ""); ASSERT_EQ(RStr, ""); }
void ReadGraph(TStr& InFile, bool& Directed, bool& Weighted, bool& Verbose, PWNet& InNet) { TFIn FIn(InFile); int64 LineCnt = 0; try { while (!FIn.Eof()) { TStr Ln; FIn.GetNextLn(Ln); TStr Line, Comment; Ln.SplitOnCh(Line,'#',Comment); TStrV Tokens; Line.SplitOnWs(Tokens); if(Tokens.Len()<2){ continue; } int64 SrcNId = Tokens[0].GetInt(); int64 DstNId = Tokens[1].GetInt(); double Weight = 1.0; if (Weighted) { Weight = Tokens[2].GetFlt(); } if (!InNet->IsNode(SrcNId)){ InNet->AddNode(SrcNId); } if (!InNet->IsNode(DstNId)){ InNet->AddNode(DstNId); } InNet->AddEdge(SrcNId,DstNId,Weight); if (!Directed){ InNet->AddEdge(DstNId,SrcNId,Weight); } LineCnt++; } if (Verbose) { printf("Read %lld lines from %s\n", (long long)LineCnt, InFile.CStr()); } } catch (PExcept Except) { if (Verbose) { printf("Read %lld lines from %s, then %s\n", (long long)LineCnt, InFile.CStr(), Except->GetStr().CStr()); } } }
void TFtrGenSparseNumeric::Split( const TStr& Str, int& Id, TStr& Val) const { if (!Str.IsChIn(':')) { TExcept::Throw("Wrong sparse numeric '" + Str + "'!"); } //split TStr IdStr; Str.SplitOnCh(IdStr, ':', Val); // parse id if (!IdStr.IsInt(Id)) { TExcept::Throw("Wrong sparse numeric '" + Str + "'!"); } }
void TEnv::GetVarNmV(TStrV& VarNmV) { VarNmV.Clr(); int VarN = 0; while (_environ[VarN] != NULL) { TStr VarNmVal = _environ[VarN++]; TStr VarNm; TStr VarVal; VarNmVal.SplitOnCh(VarNm, '=', VarVal); VarNmV.Add(VarNm); } }
inline TStr getWebsite(TStr fulladdress) { TStr left,right,tmp,res; if(fulladdress.SearchStr(TStr("http"),0)>=0) { fulladdress.SplitOnStr(left,TStr("//"),right); right.SplitOnCh(res,'/',tmp); } else { fulladdress.SplitOnCh(res,'/',tmp); } return res; }
void TWebPgFetchEvent::OnGetHost(const PSockHost& SockHost) { if (SockHost->IsOk()){ UrlStrV.Add(CurUrl->GetUrlStr()); OppSockClosed=false; SockMem.Clr(); Sock=TSock::New(this); int PortN; if (ProxyStr.Empty()){ PortN=CurUrl->GetPortN(); } else { TStr ProxyHostNm; TStr PortNStr; ProxyStr.SplitOnCh(ProxyHostNm, ':', PortNStr); PortN=PortNStr.GetInt(80); } Sock->PutTimeOut(TimeOutMSecs); Sock->Connect(SockHost, PortN); } else { OnFetchError("Invalid Host"); } }