aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/lib/strings/scanner.cc
diff options
context:
space:
mode:
Diffstat (limited to 'tensorflow/core/lib/strings/scanner.cc')
-rw-r--r--tensorflow/core/lib/strings/scanner.cc59
1 files changed, 59 insertions, 0 deletions
diff --git a/tensorflow/core/lib/strings/scanner.cc b/tensorflow/core/lib/strings/scanner.cc
new file mode 100644
index 0000000000..b05400c97d
--- /dev/null
+++ b/tensorflow/core/lib/strings/scanner.cc
@@ -0,0 +1,59 @@
+/* Copyright 2016 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+==============================================================================*/
+
+#include "tensorflow/core/lib/strings/scanner.h"
+
+namespace tensorflow {
+namespace strings {
+
+void Scanner::ScanEscapedUntilImpl(char end_ch) {
+ for (;;) {
+ if (cur_.empty()) {
+ Error();
+ return;
+ }
+ const char ch = cur_[0];
+ if (ch == end_ch) {
+ return;
+ }
+
+ cur_.remove_prefix(1);
+ if (ch == '\\') {
+ // Escape character, skip next character.
+ if (cur_.empty()) {
+ Error();
+ return;
+ }
+ cur_.remove_prefix(1);
+ }
+ }
+}
+
+bool Scanner::GetResult(StringPiece* remaining, StringPiece* capture) {
+ if (error_) {
+ return false;
+ }
+ if (remaining != nullptr) {
+ *remaining = cur_;
+ }
+ if (capture != nullptr) {
+ const char* end = capture_end_ == nullptr ? cur_.data() : capture_end_;
+ *capture = StringPiece(capture_start_, end - capture_start_);
+ }
+ return true;
+}
+
+} // namespace strings
+} // namespace tensorflow