Skip to content

Commit

Permalink
implement #435
Browse files Browse the repository at this point in the history
  • Loading branch information
pachadotdev committed Jan 1, 2025
1 parent aeb1895 commit 9673bb2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cpp11test/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ Suggests:
xml2
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
RoxygenNote: 7.3.2
24 changes: 16 additions & 8 deletions inst/include/cpp11/r_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,15 +876,23 @@ inline r_vector<T>::r_vector(std::initializer_list<named_arg> il)
// SAFETY: We've validated type and length ahead of this.
const underlying_type elt = get_elt(value, 0);

// TODO: The equivalent ctor from `initializer_list<r_string>` has a specialization
// for `<r_string>` to translate `elt` to UTF-8 before assigning. Should we have
// that here too? `named_arg` doesn't do any checking here.
if (data_p_ != nullptr) {
data_p_[i] = elt;
if constexpr (std::is_same<T, cpp11::r_string>::value) {
// Translate to UTF-8 before assigning for string types
SEXP translated_elt = Rf_mkCharCE(Rf_translateCharUTF8(elt), CE_UTF8);

if (data_p_ != nullptr) {
data_p_[i] = translated_elt;
} else {
// Handles STRSXP case. VECSXP case has its own specialization.
// We don't expect any ALTREP cases since we just freshly allocated `data_`.
set_elt(data_, i, translated_elt);
}
} else {
// Handles STRSXP case. VECSXP case has its own specialization.
// We don't expect any ALTREP cases since we just freshly allocated `data_`.
set_elt(data_, i, elt);
if (data_p_ != nullptr) {
data_p_[i] = elt;
} else {
set_elt(data_, i, elt);
}
}

SEXP name = Rf_mkCharCE(it->name(), CE_UTF8);
Expand Down

0 comments on commit 9673bb2

Please sign in to comment.