Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement #435 #436

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading