////////////////////////////////////// // URL-Redirect-Function TSASFunRedirect::TSASFunRedirect(const TStr& FunNm, const TStr& SettingFNm): TSAppSrvFun(FunNm, saotUndef) { printf("Loading redirects %s\n", FunNm.CStr()); TFIn FIn(SettingFNm); TStr LnStr, OrgFunNm; while (FIn.GetNextLn(LnStr)) { TStrV PartV; LnStr.SplitOnAllCh('\t', PartV, false); if (PartV.Empty()) { continue; } if (PartV[0].Empty()) { // parameters EAssert(PartV.Len() >= 3); TStr FldNm = PartV[1]; TStr FldVal = PartV[2]; if (FldVal.StartsWith("$")) { MapH.GetDat(OrgFunNm).FldNmMapH.AddDat(FldVal.Right(1), FldNm); } else { MapH.GetDat(OrgFunNm).FldNmValPrV.Add(TStrKd(FldNm, FldVal)); } } else { // new function EAssert(PartV.Len() >= 2); OrgFunNm = PartV[0]; MapH.AddDat(OrgFunNm).FunNm = PartV[1]; printf(" %s - %s\n", PartV[0].CStr(), PartV[1].CStr()); } } printf("Done\n"); }
TEST(TStr, LeftRight) { const TStr As = "aaabbbaaa"; // basic tests EXPECT_EQ(As.Left(3), "aaa"); EXPECT_EQ(As.Right(6), "aaa"); // negative indexes EXPECT_EQ(As.Left(-6), "aaa"); EXPECT_EQ(As.Right(-3), "aaa"); // edge cases EXPECT_ANY_THROW(As.Left(1000)); EXPECT_ANY_THROW(As.Right(1000)); EXPECT_EQ(As.Right(0), "aaabbbaaa"); EXPECT_EQ(As.Left(0), ""); }