File: regex.cpp

package info (click to toggle)
pytorch-text 0.14.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 11,560 kB
  • sloc: python: 14,197; cpp: 2,404; sh: 214; makefile: 20
file content (26 lines) | stat: -rw-r--r-- 698 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <torchtext/csrc/regex.h>

namespace torchtext {

Regex::Regex(const std::string& re_str) : re_str_(re_str) {
  compiled_pattern_ = new RE2(re_str_);
}

std::string Regex::Sub(std::string str, const std::string& repl) const {
  RE2::GlobalReplace(&str, *compiled_pattern_, repl);
  return str;
}

bool Regex::FindAndConsume(re2::StringPiece* input, std::string* text) const {
  return RE2::FindAndConsume(input, *compiled_pattern_, text);
}

std::string _serialize_regex(const c10::intrusive_ptr<Regex>& self) {
  return self->re_str_;
}

c10::intrusive_ptr<Regex> _deserialize_regex(std::string&& state) {
  return c10::make_intrusive<Regex>(std::move(state));
}

} // namespace torchtext