Add StringRef::{slice, split}, two convenient string operations which are simple

and efficient on a StringRef.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77117 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar
2009-07-26 03:18:15 +00:00
parent abb477f663
commit d61918fc68
2 changed files with 53 additions and 3 deletions

View File

@ -64,6 +64,21 @@ TEST(StringRefTest, Utilities) {
EXPECT_TRUE(Str.substr(0, 100) == "hello");
EXPECT_TRUE(Str.substr(4, 10) == "o");
EXPECT_TRUE(Str.slice(2, 3) == "l");
EXPECT_TRUE(Str.slice(1, 4) == "ell");
EXPECT_TRUE(Str.slice(2, 100) == "llo");
EXPECT_TRUE(Str.slice(2, 1) == "");
EXPECT_TRUE(Str.slice(10, 20) == "");
EXPECT_TRUE(Str.split('X') == std::make_pair(StringRef("hello"),
StringRef("")));
EXPECT_TRUE(Str.split('e') == std::make_pair(StringRef("h"),
StringRef("llo")));
EXPECT_TRUE(Str.split('h') == std::make_pair(StringRef(""),
StringRef("ello")));
EXPECT_TRUE(Str.split('o') == std::make_pair(StringRef("hell"),
StringRef("")));
EXPECT_TRUE(Str.startswith("he"));
EXPECT_FALSE(Str.startswith("helloworld"));
EXPECT_FALSE(Str.startswith("hi"));