diff --git a/llvm/include/llvm/Support/DataExtractor.h b/llvm/include/llvm/Support/DataExtractor.h --- a/llvm/include/llvm/Support/DataExtractor.h +++ b/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); } diff --git a/llvm/unittests/Support/DataExtractorTest.cpp b/llvm/unittests/Support/DataExtractorTest.cpp --- a/llvm/unittests/Support/DataExtractorTest.cpp +++ b/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);