Skip to content

Commit 9673bb2

Browse files
committed
implement #435
1 parent aeb1895 commit 9673bb2

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

cpp11test/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ Suggests:
2020
xml2
2121
LazyData: true
2222
Roxygen: list(markdown = TRUE)
23-
RoxygenNote: 7.1.1
23+
RoxygenNote: 7.3.2

inst/include/cpp11/r_vector.hpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -876,15 +876,23 @@ inline r_vector<T>::r_vector(std::initializer_list<named_arg> il)
876876
// SAFETY: We've validated type and length ahead of this.
877877
const underlying_type elt = get_elt(value, 0);
878878

879-
// TODO: The equivalent ctor from `initializer_list<r_string>` has a specialization
880-
// for `<r_string>` to translate `elt` to UTF-8 before assigning. Should we have
881-
// that here too? `named_arg` doesn't do any checking here.
882-
if (data_p_ != nullptr) {
883-
data_p_[i] = elt;
879+
if constexpr (std::is_same<T, cpp11::r_string>::value) {
880+
// Translate to UTF-8 before assigning for string types
881+
SEXP translated_elt = Rf_mkCharCE(Rf_translateCharUTF8(elt), CE_UTF8);
882+
883+
if (data_p_ != nullptr) {
884+
data_p_[i] = translated_elt;
885+
} else {
886+
// Handles STRSXP case. VECSXP case has its own specialization.
887+
// We don't expect any ALTREP cases since we just freshly allocated `data_`.
888+
set_elt(data_, i, translated_elt);
889+
}
884890
} else {
885-
// Handles STRSXP case. VECSXP case has its own specialization.
886-
// We don't expect any ALTREP cases since we just freshly allocated `data_`.
887-
set_elt(data_, i, elt);
891+
if (data_p_ != nullptr) {
892+
data_p_[i] = elt;
893+
} else {
894+
set_elt(data_, i, elt);
895+
}
888896
}
889897

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

0 commit comments

Comments
 (0)