本文整理汇总了C++中TStr::LeftOf方法的典型用法代码示例。如果您正苦于以下问题:C++ TStr::LeftOf方法的具体用法?C++ TStr::LeftOf怎么用?C++ TStr::LeftOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TStr
的用法示例。
在下文中一共展示了TStr::LeftOf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetCanonicalPath
TStr TNodeJsFPath::GetCanonicalPath(const TStr& FPath) {
// Get absolute path
TStr AbsFPath = TStr::GetNrAbsFPath(FPath);
// Remove any redundancies
TStrV CanonV; AbsFPath.SplitOnAllCh('/', CanonV);
TSStack<TStr> CanonS; TStr CurrStr;
for (int ElN = 0; ElN < CanonV.Len(); ++ElN) {
CurrStr = CanonV.GetVal(ElN);
if (CurrStr == "..") {
EAssertR(!CanonS.Empty(), "Stack empty");
CanonS.Pop();
} else if (CurrStr != ".") {
CanonS.Push(CurrStr+"/");
}
}
// Assemble the canonical path (from left to right
EAssertR(!CanonS.Empty(), "Stack empty");
// We start with drive letter (Windows) or slash (Unix)
TChA CanonFPath = AbsFPath.LeftOf('/'); CanonFPath += '/';
// Get the rest of the path
for (int CanonN = CanonS.Len() - 1; CanonN >= 0; CanonN--) {
CanonFPath += CanonS[CanonN];
}
// Done
return CanonFPath;
}
示例2:
TEST(TStr, LeftOfRightOf) {
TStr Str = "abcdef";
TStr Empty = "";
EXPECT_EQ(Str.LeftOf('d'), "abc");
EXPECT_EQ(Str.RightOf('c'), "def");
EXPECT_EQ(Str.LeftOf('a'), "");
EXPECT_EQ(Empty.RightOf('c'), "");
// edge cases
EXPECT_EQ(Str.RightOf('f'), "");
EXPECT_EQ(Empty.LeftOf('d'), "");
TStr Str2 = "abcdefabcdef";
EXPECT_EQ(Str2.LeftOfLast('d'), "abcdefabc");
EXPECT_EQ(Str2.RightOfLast('c'), "def");
EXPECT_EQ(Empty.LeftOfLast('d'), "");
EXPECT_EQ(Empty.RightOfLast('c'), "");
// edge cases
Str2 = "xabcdefabcdef";
EXPECT_EQ(Str2.LeftOfLast('x'), "");
EXPECT_EQ(Str2.RightOfLast('f'), "");
}