Exemplo n.º 1
0
TEST(TStr, ChangeStr) {
	TStr Str = "abac";
	TStr Empty;
	int ChangeN = 0;
	ChangeN = Empty.ChangeStr("ab", "ac");
	EXPECT_EQ(Empty, "");
	EXPECT_EQ(ChangeN, -1);
	ChangeN = Str.ChangeStr("ab", "abab");
	EXPECT_EQ(Str, "ababac");
	EXPECT_EQ(ChangeN, 0);
}
Exemplo n.º 2
0
void TDzsBsDoc::GetDocParts(
 const TStr& FNm, const PHtmlDoc& HtmlDoc,
 const TStr& FPath, const TStr& WebAlias,
 bool& Ok, TStr& IdStr, TStr& TitleStr, TStr& DataStr, int& YearN){
  // id
  IdStr=FNm;
  IdStr.ChangeStr(FPath, WebAlias);
  // title & data
  TChA TitleChA; TChA DataChA;
  PHtmlTok Tok; THtmlLxSym Sym; TStr Str; bool InTitleTag=false;
  for (int TokN=0; TokN<HtmlDoc->GetToks(); TokN++){
    Tok=HtmlDoc->GetTok(TokN, Sym, Str);
    if ((Sym==hsyBTag)&&(Str==THtmlTok::TitleTagNm)){InTitleTag=true;}
    else if ((Sym==hsyETag)&&(Str==THtmlTok::TitleTagNm)){InTitleTag=false;}
    else if (Sym==hsyStr){
      if (InTitleTag){TitleChA+=' '; TitleChA+=Str;}
      else {DataChA+=' '; DataChA+=Str;}
    }
  }
  TitleStr=TitleChA;
  DataStr=DataChA;
  YearN=0;
  if (DataStr.Empty()){Ok=false; return;}
  // success
  Ok=true;
}
Exemplo n.º 3
0
TStr TFile::GetUniqueFNm(const TStr& FNm){
  // <name>.#.txt --> <name>.<num>.txt
  int Cnt=1; int ch;
  TStr NewFNm; TStr TmpFNm=FNm;
  if (FNm.SearchCh('#') == -1) {
    for (ch = FNm.Len()-1; ch >= 0; ch--) if (FNm[ch] == '.') break;
    if (ch != -1) TmpFNm.InsStr(ch, ".#");
    else TmpFNm += ".#";
  }
  forever{
    NewFNm=TmpFNm;
	NewFNm.ChangeStr("#", TStr::Fmt("%03d", Cnt)); Cnt++;
    if (!TFile::Exists(NewFNm)){break;}
  }
  return NewFNm;
}
Exemplo n.º 4
0
void TDzsBsDoc::GetDocParts(
 const TStr& FNm, const PXmlDoc& XmlDoc,
 const TStr& FPath, const TStr& WebAlias,
 bool& Ok, TStr& IdStr, TStr& TitleStr, TStr& DataStr, int& YearN){
  Ok=false;
  if (!XmlDoc->IsOk()){return;}
  // id
  IdStr=FNm;
  IdStr.ChangeStr(FPath, WebAlias);
//  PXmlTok IdTok;
//  if (XmlDoc->IsTagTok("term|metadata|identifier", IdTok)){
//    IdStr=IdTok->GetTokStr(false);}
//  else {return;}
  // title
  PXmlTok TitleTok;
  if (XmlDoc->IsTagTok("term|metadata|title", TitleTok)){
    TitleStr=TitleTok->GetTokStr(false);}
  else {return;}
  // timedata
  TXmlTokV TimeDataTokV;
  XmlDoc->GetTagTokV("term|data|frame|timedata|fromyear", TimeDataTokV);
  TStr TimeDataStr=TXmlTok::GetTokVStr(TimeDataTokV, false);
  if (TimeDataStr.IsInt(YearN)){} else {YearN=0;}
  // locdata
  TXmlTokV LocDataTokV;
  XmlDoc->GetTagTokV("term|data|frame|locdata", LocDataTokV);
  TStr LocDataStr=TXmlTok::GetTokVStr(LocDataTokV, true);
  // pages
  TXmlTokV PageTokV; XmlDoc->GetTagTokV("term|data|frame|page", PageTokV);
  DataStr=GetDataTokVStr(PageTokV, "\n")+" "+LocDataStr;
  // character-set transformation
  TitleStr=THtmlLxChDef::GetCSZFromWin1250(TitleStr);
  DataStr=THtmlLxChDef::GetCSZFromWin1250(DataStr);
  // success
  Ok=true;
}