void namespaces::property_op( property_mode mode, value const &id, value &data) { local_root_scope scope; string name_ = id.to_string(); xmlChar const *name = (xmlChar const*) name_.c_str(); xmlChar *txt = 0; if (mode != property_get && mode != property_delete) { data = data.to_string(); txt = xmlStrdup((xmlChar const *) data.get_string().c_str()); } switch (mode) { case property_add: if (xmlHashAddEntry(table, name, txt) != 0) throw exception("Could not add entry to namespace hash table"); break; case property_delete: if (xmlHashRemoveEntry(table, name, xmlHashDeallocator(xmlFree)) != 0) throw exception("Could not remove entry from namespace hash table"); break; case property_set: if (xmlHashUpdateEntry(table, name, txt, xmlHashDeallocator(xmlFree))!=0) throw exception("Could not update entry in namespace hash table"); break; case property_get: break; } }
string stream::read_line(value sep_) { local_root_scope scope; if (sep_.is_undefined_or_null()) sep_ = string("\n"); string sep = sep_.to_string(); if (sep.length() != 1) throw exception("Line separators with size other than 1 are not supported"); int sepc = sep.data()[0]; if (sepc >= 128) throw exception("Non-ASCII line separators are not supported"); std::string line; for (;;) { int ch = streambuf_->sbumpc(); if (ch == std::char_traits<char>::eof()) break; line += ch; if (ch == sepc) break; } return line; }
value regex_match_node::apply(value const& v) const { auto const& pattern = impl_.get()->pattern_; #if defined(BOOST_REGEX_HAS_ICU) return boost::u32regex_match(v.to_unicode(),pattern); #else return boost::regex_match(v.to_string(),pattern); #endif }
void object::delete_property(value const &id) { if (is_null()) throw exception("Could not delete property (object is null)"); local_root_scope scope; string name = id.to_string(); jsval dummy; if (!JS_DeleteUCProperty2(Impl::current_context(), get(), (jschar*)name.data(), name.length(), &dummy)) throw exception("Could not delete property"); }
value object::set_property(value const &id, value const &v_) { if (is_null()) throw exception("Could not set property (object is null)"); local_root_scope scope; value v = v_; string name = id.to_string(); if (!JS_SetUCProperty(Impl::current_context(), get(), (jschar*)name.data(), name.length(), Impl::get_jsvalp(v))) throw exception("Could not set property"); return v; }
bool object::has_property(value const &id) const { if (is_null()) throw exception("Could not check property (object is null)"); local_root_scope scope; string name = id.to_string(); JSBool foundp; if (!JS_HasUCProperty(Impl::current_context(), get_const(), (jschar*)name.data(), name.length(), &foundp)) throw exception("Could not check property"); return foundp; }
value object::get_property(value const &id) const { if (is_null()) throw exception("Could not get property (object is null)"); value result; local_root_scope scope; string name = id.to_string(); if (!JS_GetUCProperty(Impl::current_context(), get_const(), (jschar*)name.data(), name.length(), Impl::get_jsvalp(result))) throw exception("Could not get property"); return result; }
value regex_replace_node::apply(value const& v) const { auto const& pattern = impl_.get()->pattern_; auto const& format = impl_.get()->format_; #if defined(BOOST_REGEX_HAS_ICU) return boost::u32regex_replace(v.to_unicode(),pattern,format); #else std::string repl = boost::regex_replace(v.to_string(),pattern,format); transcoder tr_("utf8"); return tr_.transcode(repl.c_str()); #endif }
bool object::has_own_property(value const &id) const { if (is_null()) throw exception("Could not check property (object is null)"); JSBool has; string name = id.to_string(); if (!JS_AlreadyHasOwnPropertyById(Impl::current_context(), get_const(), Impl::get_jsid(id), &has)) { throw exception("Unable to check for own property"); } return has; }
bool binary::property_resolve(value const &id, unsigned /*flags*/) { if (!id.is_int()) return false; int uid = id.get_int(); if (uid < 0) return false; if (size_t(uid) >= v_data.size()) return false; value v = element(v_data[uid]); define_property(id.to_string(), v, permanent_shared_property); return true; }
bool object::has_own_property(value const &id) const { if (is_null()) throw exception("Could not check property (object is null)"); JSBool has; #if JS_VERSION >= 180 string name = id.to_string(); if (!JS_AlreadyHasOwnUCProperty(Impl::current_context(), get_const(), (jschar*)name.data(), name.length(), &has)) #else JSObject *obj = get_const(); jsval argv[] = { Impl::get_jsval(id) }; jsval vp; JSBool ret = js_HasOwnPropertyHelper(Impl::current_context(), obj, obj->map->ops->lookupProperty, 1, argv, &vp); has = JSVAL_TO_BOOLEAN(vp); if (!ret) #endif { throw exception("Unable to check for own property"); } return has; }
string_t perform(value const &v) { return v.to_string().to_utf16_string(); }
std::string perform(value const &v) { return v.to_string().to_string(); }
string perform(value const &v) { string s = v.to_string(); root = s; return s; }