Esempio n. 1
0
TEST(TStr, Search) {
	TStr Str = "abcdaaba";
	int Len = Str.Len();
	EXPECT_EQ(Str.CountCh('a'), 4);
	EXPECT_EQ(Str.CountCh('b'), 2);
	EXPECT_EQ(Str.CountCh('e'), 0);

	EXPECT_TRUE(Str.IsChIn('a'));
	EXPECT_TRUE(Str.IsChIn('b'));
	EXPECT_FALSE(Str.IsChIn('e'));	

	EXPECT_TRUE(Str.IsStrIn(Str));
	EXPECT_TRUE(Str.IsStrIn(""));
	EXPECT_TRUE(Str.IsStrIn("bcd"));
	EXPECT_TRUE(Str.IsStrIn("ab"));
	EXPECT_FALSE(Str.IsStrIn("eba"));


	EXPECT_EQ(Str.CountCh('a', 1), 3);
	EXPECT_ANY_THROW(Str.CountCh('a', 10));
	EXPECT_EQ(Str.CountCh('b', 2), 1);
	EXPECT_EQ(Str.CountCh('e', 1), 0);

	EXPECT_EQ(Str.SearchCh('a'), 0);
	EXPECT_EQ(Str.SearchCh('b'), 1);
	EXPECT_EQ(Str.SearchCh('e'), -1);

	EXPECT_EQ(Str.SearchCh('a', 1), 4);
	EXPECT_EQ(Str.SearchCh('b', 2), 6);
	EXPECT_EQ(Str.SearchCh('e', 1), -1);

	EXPECT_EQ(Str.SearchChBack('a'), Len - 1);
	EXPECT_EQ(Str.SearchChBack('b'), Len - 2);
	EXPECT_EQ(Str.SearchChBack('e'), -1);

	EXPECT_EQ(Str.SearchChBack('a', Len - 2), Len - 3);
	EXPECT_EQ(Str.SearchChBack('b', Len - 3), 1);;
	EXPECT_EQ(Str.SearchChBack('e', 3), -1);	

	EXPECT_EQ(Str.SearchStr("a"), 0);
	EXPECT_EQ(Str.SearchStr("b"), 1);
	EXPECT_EQ(Str.SearchStr("e"), -1);
	EXPECT_EQ(Str.SearchStr(""), 0);

	EXPECT_EQ(Str.SearchStr("a", 1), 4);
	EXPECT_EQ(Str.SearchStr("b", 2), 6);
	EXPECT_EQ(Str.SearchStr("e", 1), -1);
}
Esempio n. 2
0
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 + "'!"); }
}
Esempio n. 3
0
/////////////////////////////////////////////////
// Cyc-Base
int TCycBs::AddVNm(const TStr& VNm){
  int VId;
  if (VNmToVrtxH.IsKey(VNm.CStr(), VId)){
    return VId;
  } else {
    VId=VNmToVrtxH.AddKey(VNm);
    TCycVrtx& Vrtx=VNmToVrtxH[VId];
    Vrtx.PutVId(VId);
    // set flags based on vertex-name string
    if (VNm.IsPrefix("~")){
      Vrtx.SetFlag(cvfBackLink);
    } else
    if (VNm.IsPrefix("#$")&&(!VNm.IsChIn(' '))){
      Vrtx.SetFlag(cvfCycL);
      if (VNm.Len()>2){
        char Ch=VNm[2];
        if (('a'<=Ch)&&(Ch<='z')){
          Vrtx.SetFlag(cvfCycLPred);
        } else {
          Vrtx.SetFlag(cvfCycLConst);
        }
      }
    } else
    if (VNm.IsPrefix("(#$")){
      Vrtx.SetFlag(cvfCycL);
      Vrtx.SetFlag(cvfCycLExpr);
    } else {
      if (VNm.IsFlt()){
        Vrtx.SetFlag(cvfNum);
      } else {
        Vrtx.SetFlag(cvfStr);
      }
    }
    return VId;
  }
}