cyb70289 commented on a change in pull request #10586: URL: https://github.com/apache/arrow/pull/10586#discussion_r659659943
########## File path: cpp/src/arrow/compute/kernels/scalar_string.cc ########## @@ -2755,6 +2748,138 @@ Result<ValueDescr> StrptimeResolve(KernelContext* ctx, const std::vector<ValueDe return Status::Invalid("strptime does not provide default StrptimeOptions"); } +// ---------------------------------------------------------------------- +// string padding + +template <bool PadLeft, bool PadRight> +struct AsciiPadTransform : public StringTransformBase { + using State = OptionsWrapper<PadOptions>; + + const PadOptions& options_; + + explicit AsciiPadTransform(const PadOptions& options) : options_(options) {} + + Status PreExec(KernelContext* ctx, const ExecBatch& batch, Datum* out) override { + if (options_.padding.size() != 1) { + return Status::Invalid("Padding must be one byte, got '", options_.padding, "'"); + } + return Status::OK(); + } + + int64_t MaxCodeunits(int64_t ninputs, int64_t input_ncodeunits) override { + // This is likely very overallocated but hard to do better without + // actually looking at each string (because of strings that may be + // longer than the given width) + return input_ncodeunits + ninputs * options_.width; + } + + int64_t Transform(const uint8_t* input, int64_t input_string_ncodeunits, + uint8_t* output) { + if (input_string_ncodeunits >= options_.width) { + std::copy(input, input + input_string_ncodeunits, output); + return input_string_ncodeunits; + } + const int64_t spaces = options_.width - input_string_ncodeunits; + int64_t left = 0; + int64_t right = 0; + if (PadLeft && PadRight) { + // If odd number of spaces, put them on the left Review comment: This comment looks to me means "to put all spaces to the left". -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org