bool GetBoolArg(const PXmlTok& QueryXml, const TStr& ArgNm, const bool DfVal)
{
	if (QueryXml.Empty()) return DfVal;
	TStr val = QueryXml->GetArgVal(ArgNm, "");
	if (val == "") return DfVal;
	val = val.GetLc();
	if (val == "true" || val == "1")
		return true;
	return false;
}
Example #2
0
PDzsHKwBs TDzsHKwBs::LoadTxt(const TStr& FNm){
  TSStack<PXmlTok> TokS;
  PXmlTok RootTok;
  PSIn SIn=TFIn::New(FNm);
  TILx Lx(SIn, TFSet()|iloTabSep);
  Lx.GetSym(syTab, syStr, syEoln, syEof);
  int PrevLev=-1;
  while (Lx.Sym!=syEof){
    printf(".");
    int Lev=0; while (Lx.Sym==syTab){Lev++; Lx.GetSym(syTab, syStr);}
    IAssert(Lx.Sym==syStr);
    for (int ChN=0; ChN<Lx.Str.Len(); ChN++){
      uchar Ch=Lx.Str[ChN];
      if (Ch>127){printf("%c", Ch); Fail;}}
    // create topic
    PXmlTok TopicTok=TXmlTok::New(xsyTag, "topic");
    //TopicTok->AddArg("title", Lx.Str);
    // topic title
    TStr TitleStr=TXmlLx::GetChRefFromYuEntRef(Lx.Str);
    PXmlTok TitleTok=TXmlTok::New(xsyTag, "title");
    TopicTok->AddSubTok(TitleTok);
    PXmlTok TitleStrTok=TXmlTok::New(xsyStr, TitleStr);
    TitleTok->AddSubTok(TitleStrTok);
    // topic query
    TStr QueryStr=GetQueryStr(TitleStr);
    PXmlTok QueryTok=TXmlTok::New(xsyTag, "query");
    TopicTok->AddSubTok(QueryTok);
    PXmlTok QueryStrTok=TXmlTok::New(xsyStr, QueryStr);
    QueryTok->AddSubTok(QueryStrTok);
    // insert topic into tree
    if (Lev==0){
      IAssert(RootTok.Empty());
      RootTok=TopicTok;
      TokS.Push(RootTok);
    } else
    if (PrevLev+1==Lev){
      TokS.Top()->AddSubTok(TopicTok);
      TokS.Push(TopicTok);
    } else
    if (PrevLev==Lev){
      TokS.Pop();
      TokS.Top()->AddSubTok(TopicTok);
      TokS.Push(TopicTok);
    } else
    if (PrevLev>Lev){
      int UpLev=PrevLev;
      while (UpLev>Lev){UpLev--; TokS.Pop();}
      TokS.Pop();
      TokS.Top()->AddSubTok(TopicTok);
      TokS.Push(TopicTok);
    } else {
      Fail;
    }
    while (Lx.GetSym()!=syEoln){}
    Lx.GetSym(syTab, syStr, syEoln, syEof);
    PrevLev=Lev;
    //if (Lx.SymLnN>100){break;}
  }
  PXmlDoc XmlDoc=TXmlDoc::New(RootTok);
  PDzsHKwBs HKwBs=TDzsHKwBs::New(XmlDoc);
  return HKwBs;
}
TInt GetIntArg(const PXmlTok& QueryXml, const TStr& ArgNm, int DfVal)
{
	if (QueryXml.Empty()) return DfVal;
	return QueryXml->GetIntArgVal(ArgNm, DfVal);
}
TStr GetStrArg(const PXmlTok& QueryXml, const TStr& ArgNm, const TStr& DfVal)
{
	if (QueryXml.Empty()) return DfVal;
	return QueryXml->GetArgVal(ArgNm, DfVal);
}
TStr GetStrArg(const PXmlTok& QueryXml, const TStr& TagPath, const TStr& ArgNm, const TStr& DfVal)
{
	PXmlTok XmlTok = QueryXml->GetTagTok(TagPath);
	if (XmlTok.Empty()) return DfVal;
	return XmlTok->GetArgVal(ArgNm, DfVal);
}