Ejemplo n.º 1
0
void TGgSchRef::GetAuthNmVPubStr(
 const TStr& AuthNmVPubStr, TStrV& AuthNmV, TStr& PubNm, TStr& PubYearStr){
  // split input string into two parts
  TStr AuthNmVStr; TStr PubStr;
  AuthNmVPubStr.SplitOnStr(AuthNmVStr, " - ", PubStr);
  // author-names string
  AuthNmVStr.SplitOnAllCh(',', AuthNmV, true);
  for (int AuthN=0; AuthN<AuthNmV.Len(); AuthN++){
    AuthNmV[AuthN].ToTrunc();
  }
  if ((!AuthNmV.Empty())&&
   ((AuthNmV.Last().IsStrIn("..."))||(AuthNmV.Last().Len()<=2))){
    AuthNmV.DelLast();
  }
  // publication-name & publication-year string
  TStr OriginStr; TStr LinkStr;
  PubStr.SplitOnStr(OriginStr, " - ", LinkStr);
  OriginStr.SplitOnLastCh(PubNm, ',', PubYearStr);
  PubNm.ToTrunc(); PubYearStr.ToTrunc();
  if ((PubYearStr.Len()>=4)&&(PubYearStr.GetSubStr(0, 3).IsInt())){
    PubYearStr=PubYearStr.GetSubStr(0, 3);
  } else
  if ((PubNm.Len()>=4)&&(PubNm.GetSubStr(0, 3).IsInt())){
    PubYearStr=PubNm.GetSubStr(0, 3); PubNm="";
  } else {
    PubYearStr="";
  }
}
Ejemplo n.º 2
0
///// Split on last occurrence of SplitCh, return Pair of Left/Right strings
///// if the character is not found the whole string is returned as the right side
//void SplitOnLastCh(TStr& LStr, const char& SplitCh, TStr& RStr) const;
TEST(TStr, SplitOnLastCh) {
	const TStr Str = "abcd";
	const TStr Str2 = "a";
	const TStr EmptyStr = "";
	TStr LStr, RStr;

	// left empty
	Str.SplitOnLastCh(LStr, 'a', RStr);
	EXPECT_EQ(LStr, "");
	EXPECT_EQ(RStr, "bcd");

	// right empty
	Str.SplitOnLastCh(LStr, 'd', RStr);
	EXPECT_EQ(LStr, "abc");
	EXPECT_EQ(RStr, "");

	// both
	Str2.SplitOnLastCh(LStr, 'a', RStr);
	EXPECT_EQ(LStr, "");
	EXPECT_EQ(RStr, "");

	// both nonempty
	Str.SplitOnLastCh(LStr, 'b', RStr);
	EXPECT_EQ(LStr, "a");
	EXPECT_EQ(RStr, "cd");

	// no-match
	Str.SplitOnLastCh(LStr, 'x', RStr);
	EXPECT_EQ(LStr, "");
	EXPECT_EQ(RStr, Str);

	// empty
	EmptyStr.SplitOnLastCh(LStr, 'a', RStr);
	EXPECT_EQ(LStr, "");
	EXPECT_EQ(RStr, "");
}