本文整理汇总了C++中TStr::ChangeStrAll方法的典型用法代码示例。如果您正苦于以下问题:C++ TStr::ChangeStrAll方法的具体用法?C++ TStr::ChangeStrAll怎么用?C++ TStr::ChangeStrAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TStr
的用法示例。
在下文中一共展示了TStr::ChangeStrAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST(TStr, ChangeStrAll) {
TStr Str = "abac";
TStr Empty;
int Changes = 0;
Changes = Empty.ChangeStrAll("ab", "ac");
EXPECT_EQ(Empty, "");
EXPECT_EQ(Changes, 0);
Changes = Str.ChangeStrAll("", "a"); // replacing and empty string should do nothing
EXPECT_EQ(Str, "abac");
EXPECT_EQ(Changes, 0);
Changes = Str.ChangeStrAll("ab", "abab");
EXPECT_EQ(Str, "ababac");
EXPECT_EQ(Changes, 1);
Changes = Str.ChangeStrAll("ab", "abab");
EXPECT_EQ(Str, "ababababac");
EXPECT_EQ(Changes, 2);
Changes = Str.ChangeStrAll("ababababac", "");
EXPECT_EQ(Str, "");
EXPECT_EQ(Changes, 1);
Changes = Str.ChangeStrAll("", "a"); // replacing and empty string should do nothing
EXPECT_EQ(Str, "");
EXPECT_EQ(Changes, 0);
}
示例2: CreatePlotFile
void TGnuPlot::CreatePlotFile(const TStr& Comment) {
time_t ltime; time(<ime);
char* TimeStr = ctime(<ime); TimeStr[strlen(TimeStr) - 1] = 0;
// rearrange columns so that longest are on the left
//SeriesV.Sort(false);
TIntV SerIdV(SeriesV.Len(), 0);
for (int i = 0; i < SeriesV.Len(); i++) { SerIdV.Add(i); }
SerIdV.SortCmp(TGpSeriesCmp(SeriesV));
// set columns
int ColCnt = 1;
bool SaveData = false;
for (int s = 0; s < SeriesV.Len(); s++) {
TGpSeries& Plt = SeriesV[SerIdV[s]];
if (Plt.XYValV.Empty()) { continue; }
Plt.DataFNm = DataFNm;
// plots use same X column
const int PrevCol = s > 0 ? IsSameXCol(SerIdV[s], SerIdV[s-1]) : -1;
if (PrevCol != -1) { Plt.XCol = PrevCol; }
else { Plt.XCol = ColCnt; ColCnt++; }
Plt.YCol = ColCnt; ColCnt++;
if (! Plt.ZValV.Empty()) { Plt.ZCol = ColCnt; ColCnt++; }
if (! Plt.XYValV.Empty()) { SaveData=true; }
}
// save data file (skip duplicate X columns)
if (SaveData) {
FILE *F = fopen(DataFNm.CStr(), "wt");
EAssertR(F != NULL, TStr("Can not open data file ")+DataFNm);
fprintf(F, "#\n");
fprintf(F, "# %s (%s)\n", Comment.CStr(), TimeStr);
fprintf(F, "#\n");
// column names
for (int i = 0; i < SerIdV.Len(); i++) {
const TGpSeries& Ser = SeriesV[SerIdV[i]];
if (Ser.XYValV.Empty()) { continue; }
if (i == 0) { fprintf(F, "# "); } else { fprintf(F, "\t"); }
if (Ser.SaveXVals()) {
if (! LblX.Empty()) { fprintf(F, "%s\t", LblX.CStr()); }
else { fprintf(F, "XVals\t"); }
}
if (Ser.Label.Empty()) { fprintf(F, "%s", LblY.CStr()); }
else { fprintf(F, "%s", SeriesV[SerIdV[i]].Label.CStr()); }
if (Ser.ZCol > 0) fprintf(F, "\tDeltaY");
}
fprintf(F, "\n");
// data
for (int row = 0; row < SeriesV[SerIdV[0]].XYValV.Len(); row++) {
for (int i = 0; i < SeriesV.Len(); i++) {
const TGpSeries& Ser = SeriesV[SerIdV[i]];
if (row < Ser.XYValV.Len()) {
if (i > 0) { fprintf(F, "\t"); }
if (Ser.SaveXVals()) { fprintf(F, "%g\t%g", Ser.XYValV[row].Key(), Ser.XYValV[row].Dat()); }
else { fprintf(F, "%g", Ser.XYValV[row].Dat()); }
if (! Ser.ZValV.Empty()) { fprintf(F, "\t%g", Ser.ZValV[row]()); }
}
}
fprintf(F, "\n");
}
fclose(F);
}
// save plot file
FILE *F = fopen(PlotFNm.CStr(), "wt");
EAssertR(F != 0, TStr("Can not open plot file ")+PlotFNm);
TStr CurDir = TDir::GetCurDir();
CurDir.ChangeStrAll("\\", "\\\\");
fprintf(F, "#\n");
fprintf(F, "# %s (%s)\n", Comment.CStr(), TimeStr);
fprintf(F, "#\n\n");
if (! Title.Empty()) fprintf(F, "set title \"%s\"\n", Title.CStr());
fprintf(F, "set key bottom right\n");
fprintf(F, "%s\n", GetScaleStr(ScaleTy).CStr());
if (ScaleTy==gpsLog || ScaleTy==gpsLog10X || ScaleTy==gpsLog10XY) {
fprintf(F, "set format x \"10^{%%L}\"\n");
fprintf(F, "set mxtics 10\n"); }
if (ScaleTy==gpsLog || ScaleTy==gpsLog10Y || ScaleTy==gpsLog10XY) {
fprintf(F, "set format y \"10^{%%L}\"\n");
fprintf(F, "set mytics 10\n"); }
if (ScaleTy==gpsLog2X || ScaleTy==gpsLog2XY) { fprintf(F, "set format x \"2^{%%L}\"\n"); }
if (ScaleTy==gpsLog2Y || ScaleTy==gpsLog2XY) { fprintf(F, "set format y \"2^{%%L}\"\n"); }
if (SetGrid) fprintf(F, "set grid\n");
if (XRange.Val1 != XRange.Val2) fprintf(F, "set xrange [%g:%g]\n", XRange.Val1(), XRange.Val2());
if (YRange.Val1 != YRange.Val2) fprintf(F, "set yrange [%g:%g]\n", YRange.Val1(), YRange.Val2());
if (! LblX.Empty()) fprintf(F, "set xlabel \"%s\"\n", LblX.CStr());
if (! LblY.Empty()) fprintf(F, "set ylabel \"%s\"\n", LblY.CStr());
if (Tics42 < -1) {
Tics42 = GetTics42();
}
if (Tics42) {
fprintf(F, "set tics scale 2\n"); // New in version 4.2
} else {
fprintf(F, "set ticscale 2 1\n"); // Old (deprecated)
}
// custom commands
for (int i = 0; i < MoreCmds.Len(); i++) {
fprintf(F, "%s\n", MoreCmds[i].CStr()); }
// plot
if (! SeriesV.Empty()) {
fprintf(F, "plot \t");
for (int i = 0; i < SeriesV.Len(); i++) {
fprintf(F, "%s", GetSeriesPlotStr(i).CStr()); }
fprintf(F, "\n");
//.........这里部分代码省略.........
示例3: LoadAsfaVoc
PLwOnto TLwOnto::LoadAsfaVoc(const TStr& FPath){
// normalize path
TStr NrFPath=TStr::GetNrFPath(FPath);
// create ontology
PLwOnto LwOnto=TLwOnto::New();
// create language object
int EnLangId=LwOnto->GetLangBs()->AddLang("EN", "English");
// create term-types
{PLwTermType D_TermType=TLwTermType::New(0, "Descriptor", EnLangId);
PLwTermType ND_TermType=TLwTermType::New(1, "Non-descriptor", EnLangId);
LwOnto->GetTermTypeBs()->AddTermType(D_TermType);
LwOnto->GetTermTypeBs()->AddTermType(ND_TermType);}
// create link-types
{PLwLinkType BT_LinkType=TLwLinkType::New(0, "BT", EnLangId, "Broader-Term");
PLwLinkType NT_LinkType=TLwLinkType::New(1, "NT", EnLangId, "Narrower-Term");
PLwLinkType RT_LinkType=TLwLinkType::New(2, "RT", EnLangId, "Related-Term");
PLwLinkType UF_LinkType=TLwLinkType::New(3, "UF", EnLangId, "Used-For");
PLwLinkType USE_LinkType=TLwLinkType::New(4, "USE", EnLangId, "Used-By");
LwOnto->GetLinkTypeBs()->AddLinkType(BT_LinkType);
LwOnto->GetLinkTypeBs()->AddLinkType(NT_LinkType);
LwOnto->GetLinkTypeBs()->AddLinkType(RT_LinkType);
LwOnto->GetLinkTypeBs()->AddLinkType(UF_LinkType);
LwOnto->GetLinkTypeBs()->AddLinkType(USE_LinkType);}
// load ontology file
TStr AsfaOntoFNm=NrFPath+"asfa_xml_20060522.xml";
printf("Loading '%s' ...", AsfaOntoFNm.CStr());
PXmlDoc AsfaXmlDoc=TXmlDoc::LoadTxt(AsfaOntoFNm);
IAssert(AsfaXmlDoc->IsOk());
TXmlTokV ConceptXmlTokV;
AsfaXmlDoc->GetTagTokV("THESAURUS|CONCEPT", ConceptXmlTokV);
printf(" Done.\n");
// create terms
{printf("Creating terms ...");
for (int ConceptN=0; ConceptN<ConceptXmlTokV.Len(); ConceptN++){
PXmlTok ConceptXmlTok=ConceptXmlTokV[ConceptN];
// term-name
TStr TermNm;
if (ConceptXmlTok->IsSubTag("NON-DESCRIPTOR")){
TermNm=ConceptXmlTok->GetTagTokStr("NON-DESCRIPTOR");}
else if (ConceptXmlTok->IsSubTag("DESCRIPTOR")){
TermNm=ConceptXmlTok->GetTagTokStr("DESCRIPTOR");}
// term-type
TStr TermTypeNm=ConceptXmlTok->GetTagTokStr("TYP");
int TermTypeId=LwOnto->GetTermTypeBs()->GetTermTypeId(TermTypeNm, EnLangId);
// description
TStr DescStr;
if (ConceptXmlTok->IsSubTag("SN")){
DescStr=ConceptXmlTok->GetTagTokStr("SN");
DescStr.ChangeChAll('\r', ' '); DescStr.ChangeChAll('\n', ' ');
DescStr.ChangeStrAll(" ", " "); DescStr.ToTrunc();
}
// create term
PLwTerm Term=TLwTerm::New(-1, TermNm, EnLangId, TermTypeId, DescStr);
LwOnto->GetTermBs()->AddTermGetTermId(Term);
}
printf(" Done. (%d)\n", LwOnto->GetTermBs()->GetTerms());}
// create links
{printf("Creating links ...");
for (int ConceptN=0; ConceptN<ConceptXmlTokV.Len(); ConceptN++){
PXmlTok ConceptXmlTok=ConceptXmlTokV[ConceptN];
// source-term-name
TStr TermNm1;
if (ConceptXmlTok->IsSubTag("NON-DESCRIPTOR")){
TermNm1=ConceptXmlTok->GetTagTokStr("NON-DESCRIPTOR");}
else if (ConceptXmlTok->IsSubTag("DESCRIPTOR")){
TermNm1=ConceptXmlTok->GetTagTokStr("DESCRIPTOR");}
int TermId1=LwOnto->GetTermBs()->GetTermId(TermNm1, EnLangId);
// links
for (int SubTokN=0; SubTokN<ConceptXmlTok->GetSubToks(); SubTokN++){
PXmlTok SubTok=ConceptXmlTok->GetSubTok(SubTokN);
if (SubTok->IsTag()){
TStr LinkTypeNm=SubTok->GetTagNm();
if (LwOnto->GetLinkTypeBs()->IsLinkType(LinkTypeNm, EnLangId)){
// destination-term-name
TStr TermNm2=ConceptXmlTok->GetTagTokStr(LinkTypeNm);
int TermId2=LwOnto->GetTermBs()->GetTermId(TermNm2, EnLangId);
int LinkTypeId=LwOnto->GetLinkTypeBs()->GetLinkTypeId(LinkTypeNm, EnLangId);
LwOnto->GetLinkBs()->AddLink(TermId1, LinkTypeId, TermId2);
}
}
}
}
printf(" Done. (%d)\n", LwOnto->GetLinkBs()->GetLinks());}
// return ontology
return LwOnto;
}