| 19 | namespace py = pybind11; |
| 20 | |
| 21 | struct AddBytesMethods { |
| 22 | template <typename FuncApplication> |
| 23 | void operator()(FuncApplication func) { |
| 24 | using namespace blocksci; |
| 25 | func(method_tag, "startswith", +[](const py::bytes &bytes, const std::string &str) -> bool { |
| 26 | auto bytesString = static_cast<std::string>(bytes); |
| 27 | return bytesString.find(str, 0) == 0; |
| 28 | }, "Returns true if the byte string has the given prefix"); |
| 29 | func(method_tag, "endswith", +[](const py::bytes &bytes, const std::string &str) -> bool { |
| 30 | auto bytesString = static_cast<std::string>(bytes); |
| 31 | return bytesString.size() >= str.size() && |
| 32 | bytesString.compare(bytesString.size() - str.size(), str.size(), str) == 0; |
| 33 | }, "Returns true if the byte string has the given suffix"); |
| 34 | } |
| 35 | }; |
| 36 | |
| 37 | void addBytesProxyMethods(AllProxyClasses<py::bytes> &cls) { |
| 38 | cls.applyToAll(AddProxyMethods{}); |
nothing calls this directly
no outgoing calls
no test coverage detected