| 31 | explicit StringStripOp(OpKernelConstruction* context) : OpKernel(context) {} |
| 32 | |
| 33 | void Compute(OpKernelContext* ctx) override { |
| 34 | const Tensor* input_tensor; |
| 35 | OP_REQUIRES_OK(ctx, ctx->input("input", &input_tensor)); |
| 36 | Tensor* output_tensor; |
| 37 | OP_REQUIRES_OK( |
| 38 | ctx, ctx->allocate_output(0, input_tensor->shape(), &output_tensor)); |
| 39 | |
| 40 | const auto input = input_tensor->flat<tstring>(); |
| 41 | auto output = output_tensor->flat<tstring>(); |
| 42 | |
| 43 | for (int64 i = 0; i < input.size(); ++i) { |
| 44 | StringPiece entry(input(i)); |
| 45 | str_util::RemoveWhitespaceContext(&entry); |
| 46 | output(i) = string(entry); |
| 47 | } |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | REGISTER_KERNEL_BUILDER(Name("StringStrip").Device(DEVICE_CPU), StringStripOp); |
nothing calls this directly
no test coverage detected