58 #include <boost/serialization/nvp.hpp>
59 #include <tr1/unordered_map>
121 return m_string->c_str()[index];
140 return m_string->c_str();
247 friend class boost::serialization::access;
253 typedef std::pair<std::string, cetype_t> key;
257 class Hasher :
public std::unary_function<key, std::size_t> {
259 std::size_t operator()(
const key& k)
const
261 return s_string_hasher(k.first);
264 static std::tr1::hash<std::string> s_string_hasher;
271 std::tr1::unordered_map<key, String*, Hasher, std::equal_to<key>,
277 static std::string* s_na_string;
279 static String* s_blank;
281 map::value_type* m_key_val_pr;
282 const std::string* m_string;
284 mutable Symbol* m_symbol;
289 explicit String(map::value_type* key_val_pr = 0);
293 String(
const String&);
294 String& operator=(
const String&);
300 static void cleanup();
303 static void initialize();
305 template<
class Archive>
306 void load(Archive & ar,
const unsigned int version);
308 template<
class Archive>
309 void save(Archive & ar,
const unsigned int version)
const;
312 template <
class Archive>
313 void serialize(Archive& ar,
const unsigned int version) {
314 boost::serialization::split_member(ar, *
this, version);
326 bool isASCII(
const std::string& str);
337 template<
class Archive>
338 void CXXR::String::load(Archive& ar,
const unsigned int version)
342 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(
RObject);
344 ar >> BOOST_SERIALIZATION_NVP(isna);
349 ar >> boost::serialization::make_nvp(
"string", str);
350 ar >> BOOST_SERIALIZATION_NVP(m_encoding);
355 template<
class Archive>
356 void CXXR::String::save(Archive& ar,
const unsigned int version)
const
358 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(RObject);
359 bool isna = (
this ==
NA());
360 ar << BOOST_SERIALIZATION_NVP(isna);
362 std::string str = stdstring();
363 ar << boost::serialization::make_nvp(
"string", str);
364 ar << BOOST_SERIALIZATION_NVP(m_encoding);
372 extern SEXP R_NaString;
373 extern SEXP R_BlankString;
388 const CXXR::String& str = *CXXR::SEXP_downcast<const CXXR::String*>(x);
390 return enc == CE_LATIN1 || enc == CE_UTF8;
406 const CXXR::String& str = *CXXR::SEXP_downcast<const CXXR::String*>(x);
407 return Rboolean(str.
isASCII());
423 const CXXR::String& str = *CXXR::SEXP_downcast<const CXXR::String*>(x);
424 return Rboolean(str.
encoding() == CE_BYTES);
440 const CXXR::String& str = *CXXR::SEXP_downcast<const CXXR::String*>(x);
441 return Rboolean(str.
encoding() == CE_LATIN1);
457 const CXXR::String& str = *CXXR::SEXP_downcast<const CXXR::String*>(x);
458 return Rboolean(str.
encoding() == CE_UTF8);
473 using namespace CXXR;
474 return SEXP_downcast<String*>(x,
false)->stdstring().c_str();