本文整理汇总了C++中StringPool::makeRef方法的典型用法代码示例。如果您正苦于以下问题:C++ StringPool::makeRef方法的具体用法?C++ StringPool::makeRef怎么用?C++ StringPool::makeRef使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringPool
的用法示例。
在下文中一共展示了StringPool::makeRef方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST(StringPoolTest, SortAndMaintainIndexesInReferences) {
StringPool pool;
StringPool::Ref ref = pool.makeRef(u"z");
StringPool::StyleRef ref2 = pool.makeRef(StyleString{ {u"a"} });
StringPool::Ref ref3 = pool.makeRef(u"m");
EXPECT_EQ(*ref, u"z");
EXPECT_EQ(0u, ref.getIndex());
EXPECT_EQ(*(ref2->str), u"a");
EXPECT_EQ(1u, ref2.getIndex());
EXPECT_EQ(*ref3, u"m");
EXPECT_EQ(2u, ref3.getIndex());
pool.sort([](const StringPool::Entry& a, const StringPool::Entry& b) -> bool {
return a.value < b.value;
});
EXPECT_EQ(*ref, u"z");
EXPECT_EQ(2u, ref.getIndex());
EXPECT_EQ(*(ref2->str), u"a");
EXPECT_EQ(0u, ref2.getIndex());
EXPECT_EQ(*ref3, u"m");
EXPECT_EQ(1u, ref3.getIndex());
}
示例2: buffer
TEST(StringPoolTest, FlattenUtf8) {
StringPool pool;
StringPool::Ref ref1 = pool.makeRef(u"hello");
StringPool::Ref ref2 = pool.makeRef(u"goodbye");
StringPool::Ref ref3 = pool.makeRef(sLongString);
StringPool::StyleRef ref4 = pool.makeRef(StyleString{
{ u"style" },
{ Span{ { u"b" }, 0, 1 }, Span{ { u"i" }, 2, 3 } }
});
EXPECT_EQ(0u, ref1.getIndex());
EXPECT_EQ(1u, ref2.getIndex());
EXPECT_EQ(2u, ref3.getIndex());
EXPECT_EQ(3u, ref4.getIndex());
BigBuffer buffer(1024);
StringPool::flattenUtf8(&buffer, pool);
std::unique_ptr<uint8_t[]> data = util::copy(buffer);
{
android::ResStringPool test;
ASSERT_EQ(test.setTo(data.get(), buffer.size()), android::NO_ERROR);
EXPECT_EQ(util::getString(test, 0), u"hello");
EXPECT_EQ(util::getString(test, 1), u"goodbye");
EXPECT_EQ(util::getString(test, 2), sLongString);
EXPECT_EQ(util::getString(test, 3), u"style");
const ResStringPool_span* span = test.styleAt(3);
ASSERT_NE(nullptr, span);
EXPECT_EQ(util::getString(test, span->name.index), u"b");
EXPECT_EQ(0u, span->firstChar);
EXPECT_EQ(1u, span->lastChar);
span++;
ASSERT_NE(ResStringPool_span::END, span->name.index);
EXPECT_EQ(util::getString(test, span->name.index), u"i");
EXPECT_EQ(2u, span->firstChar);
EXPECT_EQ(3u, span->lastChar);
span++;
EXPECT_EQ(ResStringPool_span::END, span->name.index);
}
}