@@ -15,8 +15,8 @@ inline const xmlChar* asXmlChar(std::string const& x) {
15
15
return (const xmlChar*) x.c_str ();
16
16
}
17
17
18
- inline const xmlChar* asXmlChar (SEXP x, int n = 0 ) {
19
- return (const xmlChar*) CHAR ( STRING_ELT (x, n) );
18
+ inline const xmlChar* asXmlChar (cpp11::strings x ) {
19
+ return (const xmlChar*) cpp11::as_cpp< const char *>(x );
20
20
}
21
21
22
22
#define BEGIN_CPP try {
@@ -64,11 +64,11 @@ class Xml2String {
64
64
return std::string ((char *) string_);
65
65
}
66
66
67
- SEXP asRString (SEXP missing = NA_STRING) {
67
+ cpp11::r_string asRString (cpp11::r_string missing = NA_STRING) {
68
68
if (string_ == NULL )
69
69
return missing;
70
70
71
- return Rf_mkCharCE ((char *) string_, CE_UTF8 );
71
+ return cpp11::r_string ((char *) string_);
72
72
};
73
73
};
74
74
@@ -87,10 +87,10 @@ class NsMap {
87
87
}
88
88
89
89
// Initialise from an existing STRSXP
90
- NsMap (SEXP x) {
91
- SEXP names = Rf_getAttrib (x, R_NamesSymbol );
92
- for (R_len_t i = 0 ; i < Rf_xlength (x ); ++i) {
93
- add (std::string ( CHAR ( STRING_ELT ( names, i))), std::string ( CHAR ( STRING_ELT (x, i)) ));
90
+ NsMap (cpp11::strings x) {
91
+ cpp11::strings names = x. names ( );
92
+ for (R_len_t i = 0 ; i < x. size ( ); ++i) {
93
+ add (cpp11::r_string ( names[i]), cpp11::r_string (x[i] ));
94
94
}
95
95
}
96
96
@@ -128,20 +128,20 @@ class NsMap {
128
128
return true ;
129
129
}
130
130
131
- SEXP out () {
132
- SEXP out = PROTECT (Rf_allocVector (STRSXP, prefix2url.size ()));
133
- SEXP names = PROTECT (Rf_allocVector (STRSXP, prefix2url.size ()));
131
+ cpp11::sexp out () {
132
+ int n = prefix2url.size ();
133
+ cpp11::writable::strings out (n);
134
+ cpp11::writable::strings names (n);
134
135
135
136
size_t i = 0 ;
136
137
for (prefix2url_t ::const_iterator it = prefix2url.begin (); it != prefix2url.end (); ++it) {
137
- SET_STRING_ELT ( out, i, Rf_mkChar ( it->second .c_str ()) );
138
- SET_STRING_ELT ( names, i, Rf_mkChar ( it->first .c_str ()) );
138
+ out[i] = it->second .c_str ();
139
+ names[i] = it->first .c_str ();
139
140
++i;
140
141
}
141
142
142
- Rf_setAttrib ( out, R_NamesSymbol, names) ;
143
+ out. names () = names;
143
144
144
- UNPROTECT (2 );
145
145
return out;
146
146
}
147
147
};
0 commit comments