本文整理汇总了C++中TStr::DelSubStr方法的典型用法代码示例。如果您正苦于以下问题:C++ TStr::DelSubStr方法的具体用法?C++ TStr::DelSubStr怎么用?C++ TStr::DelSubStr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TStr
的用法示例。
在下文中一共展示了TStr::DelSubStr方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetIfArgPrefixBool
bool TEnv::GetIfArgPrefixBool(const TStr& PrefixStr,
const bool& DfVal,
const TStr& DNm) const {
if (Env.GetArgs() <= MnArgs) {
// 'usage' argument message
if (!SilentP) {
printf(" %s%s (default:'%s')\n",
PrefixStr.CStr(), DNm.CStr(),
TBool::GetStr(DfVal).CStr());
}
return DfVal;
} else {
// argument & value message
bool Val;
if ((PrefixStr.Len() > 0) &&
(PrefixStr.LastCh() == ':')) {
if (Env.IsArgPrefix(PrefixStr)) {
// try to find one of boolean string value
// representations
TStr ValStr = Env.GetArgPostfix(PrefixStr);
Val = TBool::GetValFromStr(ValStr, DfVal);
} else {
// remove ':' and try to find option
TStr RedPrefixStr = PrefixStr;
RedPrefixStr.DelSubStr(PrefixStr.Len() - 1,
PrefixStr.Len() - 1);
if (Env.IsArgPrefix(RedPrefixStr)) {
Val = true;
} else {
Val = DfVal;
}
}
} else {
if (Env.IsArgPrefix(PrefixStr)) {
Val = true;
} else {
Val = DfVal;
}
}
TStr MsgStr = DNm + " (" + PrefixStr + ")=" +
TBool::GetYesNoStr(Val);
if (!SilentP) {
TNotify::OnStatus(Notify, MsgStr);
}
return Val;
}
}
示例2:
TEST(TStr, Del) {
TStr Str = "aabbaabb";
TStr Empty = "";
TStr Test = Str;
Test.DelChAll('a');
EXPECT_EQ(Test, "bbbb");
Test.DelChAll('c');
EXPECT_EQ(Test, "bbbb");
Test = Str;
Test.DelSubStr(2, 3);
EXPECT_EQ(Test, "aaaabb");
Test.DelSubStr(0, 1);
EXPECT_EQ(Test, "aabb");
Test.DelSubStr(2, 3);
EXPECT_EQ(Test, "aa");
EXPECT_ANY_THROW(Test.DelSubStr(-1, 5));
Test.DelSubStr(0, 1);
EXPECT_EQ(Test, "");
Test = Str;
Test.DelSubStr(0, 0);
EXPECT_EQ(Test, "abbaabb");
Test = Str;
EXPECT_TRUE(Test.DelStr("ab"));
EXPECT_EQ(Test, "abaabb");
EXPECT_FALSE(Test.DelStr("fs"));
EXPECT_EQ(Test, "abaabb");
Test = Str;
EXPECT_EQ(2, Test.DelStrAll("ab"));
EXPECT_EQ(Test, "abab");
}
示例3: OnHttpRq
void TMongSrv::OnHttpRq(const int& SockId, const PHttpRq& HttpRq) {
// check http-request correctness - return if error
if (!HttpRq->IsOk()) {
TNotify::OnNotify(Notify, ntInfo, "Web-Server: Bad Http Request.");
return;
}
// check url correctness - return if error
PUrl RqUrl = HttpRq->GetUrl();
if (!RqUrl->IsOk()) {
TNotify::OnNotify(Notify, ntInfo, "Web-Server: Bad Url Requested.");
return;
}
// construct http-response
PHttpResp HttpResp;
if (!RqUrl->GetPathStr().Empty()) {
// get request-file-name
TStr ExeFPath = TSysProc::GetExeFNm().GetFPath();
TStr RqFNm = RqUrl->GetPathStr();
if (RqFNm.LastCh() == '/') {
RqFNm = RqFNm + "default.htm";
}
if ((RqFNm[0] == '/') || (RqFNm[0] == '\\')) {
RqFNm.DelSubStr(0, 0);
}
RqFNm = ExeFPath + RqFNm;
// open file
bool RqFOpened = false;
PSIn RqSIn = TFIn::New(RqFNm, RqFOpened);
if (!RqFOpened) {
// prepare default html with time
TChA HtmlChA;
HtmlChA += "<html><title>Error - Not Found</title><body>";
HtmlChA += "File: ";
HtmlChA += RqUrl->GetPathStr();
HtmlChA += " not found.";
HtmlChA += "</body></html>";
PSIn BodySIn = TMIn::New(HtmlChA);
HttpResp = PHttpResp(
new THttpResp(THttp::ErrNotFoundStatusCd,
THttp::TextHtmlFldVal, false, BodySIn, ""));
} else {
// file successfully opened
PSIn BodySIn = RqSIn;
if (THttp::IsHtmlFExt(RqFNm.GetFExt())) {
// send text/html mime type if Html filemg_callback_t
HttpResp = PHttpResp(
new THttpResp(THttp::OkStatusCd, THttp::TextHtmlFldVal,
false, BodySIn, ""));
} else if (THttp::IsGifFExt(RqFNm.GetFExt())) {
// send image/gif mime type if Gif file
HttpResp = PHttpResp(
new THttpResp(THttp::OkStatusCd, THttp::ImageGifFldVal,
false, BodySIn, ""));
} else {
// send application/octet mime type
HttpResp = PHttpResp(
new THttpResp(THttp::OkStatusCd, THttp::AppOctetFldVal,
false, BodySIn, ""));
}
}
} else {
// prepare default html with time
TChA HtmlChA;
HtmlChA += "<html><title>Welcome to TWebSrv (powered by mongoose 3.1)</title><body>";
HtmlChA += TSecTm::GetCurTm().GetStr();
HtmlChA += "</body></html>";
PSIn BodySIn = TMIn::New(HtmlChA);
HttpResp = THttpResp::New(THttp::OkStatusCd, THttp::TextHtmlFldVal,
false, BodySIn);
}
// construct & send response
SendHttpResp(SockId, HttpResp);
// notify
if (RqUrl->IsOk()) {
TChA MsgChA;
MsgChA += "Web-Server: Request for '";
MsgChA += RqUrl->GetUrlStr();
MsgChA += "'.";
TNotify::OnNotify(Notify, ntInfo, MsgChA);
}
}