@@ -137,7 +137,12 @@ inline SEXP get_last_call(){
137
137
138
138
inline SEXP get_exception_classes ( const std::string& ex_class) {
139
139
Rcpp::Shield<SEXP> res ( Rf_allocVector ( STRSXP, 4 ) );
140
+
141
+ #ifndef RCPP_USING_UTF8_ERROR_STRING
140
142
SET_STRING_ELT ( res, 0 , Rf_mkChar ( ex_class.c_str () ) ) ;
143
+ #else
144
+ SET_STRING_ELT ( res, 0 , Rf_mkCharLenCE ( ex_class.c_str (), ex_class.size (), CE_UTF8 ) );
145
+ #endif
141
146
SET_STRING_ELT ( res, 1 , Rf_mkChar ( " C++Error" ) ) ;
142
147
SET_STRING_ELT ( res, 2 , Rf_mkChar ( " error" ) ) ;
143
148
SET_STRING_ELT ( res, 3 , Rf_mkChar ( " condition" ) ) ;
@@ -146,8 +151,13 @@ inline SEXP get_exception_classes( const std::string& ex_class) {
146
151
147
152
inline SEXP make_condition (const std::string& ex_msg, SEXP call, SEXP cppstack, SEXP classes){
148
153
Rcpp::Shield<SEXP> res ( Rf_allocVector ( VECSXP, 3 ) ) ;
149
-
150
- SET_VECTOR_ELT ( res, 0 , Rf_mkString ( ex_msg.c_str () ) ) ;
154
+ #ifndef RCPP_USING_UTF8_ERROR_STRING
155
+ SET_VECTOR_ELT ( res, 0 , Rf_mkString ( ex_msg.c_str () ) ) ;
156
+ #else
157
+ Rcpp::Shield<SEXP> ex_msg_rstring ( Rf_allocVector ( STRSXP, 1 ) ) ;
158
+ SET_STRING_ELT ( ex_msg_rstring, 0 , Rf_mkCharLenCE ( ex_msg.c_str (), ex_msg.size (), CE_UTF8 ) );
159
+ SET_VECTOR_ELT ( res, 0 , ex_msg_rstring ) ;
160
+ #endif
151
161
SET_VECTOR_ELT ( res, 1 , call ) ;
152
162
SET_VECTOR_ELT ( res, 2 , cppstack ) ;
153
163
@@ -174,10 +184,17 @@ inline SEXP exception_to_r_condition( const std::exception& ex){
174
184
175
185
inline SEXP string_to_try_error ( const std::string& str){
176
186
using namespace Rcpp ;
177
-
178
- Rcpp::Shield<SEXP> simpleErrorExpr ( Rf_lang2 (::Rf_install (" simpleError" ), Rf_mkString (str.c_str ())) );
187
+
188
+ #ifndef RCPP_USING_UTF8_ERROR_STRING
189
+ Rcpp::Shield<SEXP> simpleErrorExpr ( Rf_lang2 (::Rf_install (" simpleError" ), Rf_mkString (str.c_str ())) );
190
+ Rcpp::Shield<SEXP> tryError ( Rf_mkString ( str.c_str () ) );
191
+ #else
192
+ Rcpp::Shield<SEXP> tryError ( Rf_allocVector ( STRSXP, 1 ) ) ;
193
+ SET_STRING_ELT ( tryError, 0 , Rf_mkCharLenCE ( str.c_str (), str.size (), CE_UTF8 ) );
194
+ Rcpp::Shield<SEXP> simpleErrorExpr ( Rf_lang2 (::Rf_install (" simpleError" ), tryError ));
195
+ #endif
196
+
179
197
Rcpp::Shield<SEXP> simpleError ( Rf_eval (simpleErrorExpr, R_GlobalEnv) );
180
- Rcpp::Shield<SEXP> tryError ( Rf_mkString ( str.c_str () ) );
181
198
Rf_setAttrib ( tryError, R_ClassSymbol, Rf_mkString (" try-error" ) ) ;
182
199
Rf_setAttrib ( tryError, Rf_install ( " condition" ) , simpleError ) ;
183
200
0 commit comments