MCPcopy Create free account
hub / github.com/apache/arrow / ConvertStripNul

Method ConvertStripNul

r/src/altrep.cpp:797–825  ·  view source on GitHub ↗

strip the nuls and then convert to R string

Source from the content-addressed store, hash-verified

795
796 // strip the nuls and then convert to R string
797 SEXP ConvertStripNul() {
798 const char* old_string = view_.data();
799
800 size_t stripped_len = 0, nul_count = 0;
801
802 for (size_t i = 0; i < view_.size(); i++) {
803 if (old_string[i] == '\0') {
804 ++nul_count;
805
806 if (nul_count == 1) {
807 // first nul spotted: allocate stripped string storage
808 stripped_string_.assign(view_.begin(), view_.end());
809 stripped_len = i;
810 }
811
812 // don't copy old_string[i] (which is \0) into stripped_string
813 continue;
814 }
815
816 if (nul_count > 0) {
817 stripped_string_[stripped_len++] = old_string[i];
818 }
819 }
820
821 nul_was_stripped_ = true;
822 ARROW_R_DCHECK(stripped_len <= std::numeric_limits<int>::max());
823 return Rf_mkCharLenCE(stripped_string_.data(), static_cast<int>(stripped_len),
824 CE_UTF8);
825 }
826
827 bool nul_was_stripped() const { return nul_was_stripped_; }
828

Callers

nothing calls this directly

Calls 5

assignMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected