Skip to content

Commit baa18ee

Browse files
committed
Add a new API seek for the Cursor class in the DataExtractor.cpp
Summary: add a new API seek for the Cursor class in the DataExtractor.cpp Reviewers: James Henderson, Fangrui Song Differential Revision: https://reviews.llvm.org/D109603
1 parent 1b0a71c commit baa18ee

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

llvm/include/llvm/Support/DataExtractor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class DataExtractor {
7070
/// the position of the Cursor before the first error was encountered.
7171
uint64_t tell() const { return Offset; }
7272

73+
/// Set the cursor to the new offset. This does not impact the error state.
74+
void seek(uint64_t NewOffSet) { Offset = NewOffSet; }
75+
7376
/// Return error contained inside this Cursor, if any. Clears the internal
7477
/// Cursor state.
7578
Error takeError() { return std::move(Err); }

llvm/unittests/Support/DataExtractorTest.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,18 @@ TEST(DataExtractorTest, Cursor_tell) {
177177
consumeError(C.takeError());
178178
}
179179

180+
TEST(DataExtractorTest, Cursor_seek) {
181+
DataExtractor::Cursor C(5);
182+
183+
C.seek(3);
184+
EXPECT_EQ(3u, C.tell());
185+
186+
C.seek(8);
187+
EXPECT_EQ(8u, C.tell());
188+
189+
EXPECT_THAT_ERROR(C.takeError(), Succeeded());
190+
}
191+
180192
TEST(DataExtractorTest, Cursor_takeError) {
181193
DataExtractor DE(StringRef("AB"), false, 8);
182194
DataExtractor::Cursor C(0);

0 commit comments

Comments
 (0)