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. This does not impact the error state. + 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::Cursor C(5); + + C.seek(3); + EXPECT_EQ(3u, C.tell()); + + C.seek(8); + EXPECT_EQ(8u, C.tell()); + + EXPECT_THAT_ERROR(C.takeError(), Succeeded()); +} + TEST(DataExtractorTest, Cursor_takeError) { DataExtractor DE(StringRef("AB"), false, 8); DataExtractor::Cursor C(0);