diff options
author | A. Unique TensorFlower <nobody@tensorflow.org> | 2016-04-05 09:19:52 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2016-04-05 10:22:04 -0700 |
commit | 3c676e8b1a3b52e7af36937537e8fefad71bc448 (patch) | |
tree | 5b47ad1a7bd0156fda76e54856e91bea6a49b8d6 /tensorflow/core/lib | |
parent | 2d11588a46d48d0b9630bf2362685dd204fd1ed1 (diff) |
Fix Scanner so that in RestartCapture, the capture_end_ is reset. Otherwise, an
invalid capture is produced where the end is before the start.
Change: 119062729
Diffstat (limited to 'tensorflow/core/lib')
-rw-r--r-- | tensorflow/core/lib/strings/scanner.h | 1 | ||||
-rw-r--r-- | tensorflow/core/lib/strings/scanner_test.cc | 7 |
2 files changed, 8 insertions, 0 deletions
diff --git a/tensorflow/core/lib/strings/scanner.h b/tensorflow/core/lib/strings/scanner.h index ecbb139d60..19cd8a50fe 100644 --- a/tensorflow/core/lib/strings/scanner.h +++ b/tensorflow/core/lib/strings/scanner.h @@ -102,6 +102,7 @@ class Scanner { // returned will start at the position at the time this was called. Scanner& RestartCapture() { capture_start_ = cur_.data(); + capture_end_ = nullptr; return *this; } diff --git a/tensorflow/core/lib/strings/scanner_test.cc b/tensorflow/core/lib/strings/scanner_test.cc index 98028ae516..acd39f1470 100644 --- a/tensorflow/core/lib/strings/scanner_test.cc +++ b/tensorflow/core/lib/strings/scanner_test.cc @@ -181,6 +181,13 @@ TEST_F(ScannerTest, CaptureAndGetResult) { EXPECT_TRUE(scan.GetResult(&remaining, &match)); EXPECT_EQ("second", remaining.ToString()); EXPECT_EQ("first", match.ToString()); + + scan.RestartCapture().One(Scanner::LETTER).One(Scanner::LETTER); + remaining = ""; + match = ""; + EXPECT_TRUE(scan.GetResult(&remaining, &match)); + EXPECT_EQ("cond", remaining.ToString()); + EXPECT_EQ("se", match.ToString()); } // Tests that if StopCapture is not called, then calling GetResult, then |