[PATCH] D109603: add a new API seek for the Cursor class in the DataExtractor.cpp
Digger Lin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 10 06:28:07 PDT 2021
DiggerLin created this revision.
DiggerLin added reviewers: jhenderson, MaskRay, hubert.reinterpretcast.
Herald added a subscriber: dexonsmith.
DiggerLin requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
add a new API seek to set the Cursor to a new position.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D109603
Files:
llvm/include/llvm/Support/DataExtractor.h
llvm/unittests/Support/DataExtractorTest.cpp
Index: llvm/unittests/Support/DataExtractorTest.cpp
===================================================================
--- llvm/unittests/Support/DataExtractorTest.cpp
+++ llvm/unittests/Support/DataExtractorTest.cpp
@@ -177,6 +177,18 @@
consumeError(C.takeError());
}
+TEST(DataExtractorTest, Cursor_seek) {
+ DataExtractor DE(StringRef("ABCDEF"), false, 8);
+ DataExtractor::Cursor C(0);
+ EXPECT_EQ('A', DE.getU8(C));
+
+ C.seek(2);
+ EXPECT_EQ('C', DE.getU8(C));
+ EXPECT_EQ(3u, C.tell());
+
+ consumeError(C.takeError());
+}
+
TEST(DataExtractorTest, Cursor_takeError) {
DataExtractor DE(StringRef("AB"), false, 8);
DataExtractor::Cursor C(0);
Index: llvm/include/llvm/Support/DataExtractor.h
===================================================================
--- llvm/include/llvm/Support/DataExtractor.h
+++ llvm/include/llvm/Support/DataExtractor.h
@@ -70,6 +70,9 @@
/// the position of the Cursor before the first error was encountered.
uint64_t tell() const { return Offset; }
+ /// Set the cursor to the new offset.
+ void seek(uint64_t NewOffSet) { Offset = NewOffSet; }
+
/// Return error contained inside this Cursor, if any. Clears the internal
/// Cursor state.
Error takeError() { return std::move(Err); }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109603.371909.patch
Type: text/x-patch
Size: 1278 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210910/2d0b0898/attachment.bin>
More information about the llvm-commits
mailing list