pitrou commented on a change in pull request #12030:
URL: https://github.com/apache/arrow/pull/12030#discussion_r777672319



##########
File path: r/src/io.cpp
##########
@@ -178,4 +181,166 @@ void io___BufferOutputStream__Write(
   StopIfNotOk(stream->Write(RAW(bytes), bytes.size()));
 }
 
+// TransformInputStream::TransformFunc wrapper
+
+class RIconvWrapper {
+ public:
+  RIconvWrapper(std::string to, std::string from)
+      : handle_(Riconv_open(to.c_str(), from.c_str())) {
+    if (handle_ == ((void*)-1)) {
+      cpp11::stop("Can't convert encoding from '%s' to '%s'", from.c_str(), 
to.c_str());
+    }
+  }
+
+  size_t iconv(const uint8_t** inbuf, int64_t* inbytesleft, uint8_t** outbuf,
+               int64_t* outbytesleft) {
+    // This iconv signature uses the types that Arrow C++ uses to minimize
+    // deviations from the style guide; however, iconv() uses pointers
+    // to char* and size_t instead of uint8_t and int64_t.
+    size_t inbytesleft_size_t = *inbytesleft;
+    size_t outbytesleft_size_t = *outbytesleft;
+    const char** inbuf_const_char = reinterpret_cast<const char**>(inbuf);
+    char** outbuf_char = reinterpret_cast<char**>(outbuf);
+
+    size_t return_value = Riconv(handle_, inbuf_const_char, 
&inbytesleft_size_t,
+                                 outbuf_char, &outbytesleft_size_t);
+
+    *inbytesleft = inbytesleft_size_t;
+    *outbytesleft = outbytesleft_size_t;
+    return return_value;
+  }
+
+  ~RIconvWrapper() {
+    if (handle_ != ((void*)-1)) {
+      Riconv_close(handle_);
+    }
+  }
+
+ protected:
+  void* handle_;
+};
+
+struct ReencodeUTF8TransformFunctionWrapper {
+  explicit ReencodeUTF8TransformFunctionWrapper(std::string from)
+      : from_(from), iconv_("UTF-8", from), n_pending_(0) {}
+
+  // This may get copied and we need a fresh RIconvWrapper for each copy.
+  ReencodeUTF8TransformFunctionWrapper(const 
ReencodeUTF8TransformFunctionWrapper& ref)
+      : ReencodeUTF8TransformFunctionWrapper(ref.from_) {}
+
+  arrow::Result<std::shared_ptr<arrow::Buffer>> operator()(
+      const std::shared_ptr<arrow::Buffer>& src) {
+    int64_t initial_size = std::min<int64_t>((src->size() + 8 * 1.2), 32);

Review comment:
       You probably want `max` not `min`? Also, `8 * 1.2` is a constant :-)




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to